import sys
import math

input = sys.stdin.readline


def warshall_floyd(d):
    for k in range(len(d)):
        for i in range(len(d)):
            for j in range(len(d)):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])


N, M, L = map(int, input().split())
d = [[math.inf] * N for _ in range(N)]
for i in range(N):
    d[i][i] = 0
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    d[a][b] = c
    d[b][a] = c
warshall_floyd(d)
for i in range(N):
    for j in range(N):
        d[i][j] = 1 if d[i][j] <= L else math.inf
for i in range(N):
    d[i][i] = 0
warshall_floyd(d)


Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    if s == t:
        print(0)
    elif d[s][t] == math.inf:
        print(-1)
    else:
        print(d[s][t]-1) import sys sys import math math input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def warshall_floyd(d):
    for k in range(len(d)):
        for i in range(len(d)):
            for j in range(len(d)):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]) warshall_floyd for k in range(len(d)):
        for i in range(len(d)):
            for j in range(len(d)):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]) k range(len(d)) range len(d) len d for i in range(len(d)):
            for j in range(len(d)):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]) i range(len(d)) range len(d) len d for j in range(len(d)):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]) j range(len(d)) range len(d) len d d[i][j] = min(d[i][j], d[i][k] + d[k][j]) d[i][j] [i] d i j min(d[i][j], d[i][k] + d[k][j]) min d[i][j] [i] d i j d[i][k] + d[k][j] d[i][k] [i] d i k d[k][j] [k] d k j d d N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L [math.inf] * N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [math.inf] * N [math.inf] math.inf math inf N d = [[math.inf] * N for _ in range(N)] d [[math.inf] * N for _ in range(N)] for i in range(N):
    d[i][i] = 0 i range(N) range N d[i][i] = 0 d[i][i] [i] d i i 0 for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    d[a][b] = c
    d[b][a] = c _ range(M) range M a, b, c = map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b c a -= 1 a 1 b -= 1 b 1 d[a][b] = c d[a][b] [a] d a b c d[b][a] = c d[b][a] [b] d b a c warshall_floyd(d) warshall_floyd d for i in range(N):
    for j in range(N):
        d[i][j] = 1 if d[i][j] <= L else math.inf i range(N) range N for j in range(N):
        d[i][j] = 1 if d[i][j] <= L else math.inf j range(N) range N d[i][j] = 1 if d[i][j] <= L else math.inf d[i][j] [i] d i j 1 if d[i][j] <= L else math.inf d[i][j] <= L d[i][j] [i] d i j L 1 math.inf math inf for i in range(N):
    d[i][i] = 0 i range(N) range N d[i][i] = 0 d[i][i] [i] d i i 0 warshall_floyd(d) warshall_floyd d Q = int(input()) Q int(input()) int input() input for _ in range(Q):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    if s == t:
        print(0)
    elif d[s][t] == math.inf:
        print(-1)
    else:
        print(d[s][t]-1) _ range(Q) range Q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t s -= 1 s 1 t -= 1 t 1 if s == t:
        print(0)
    elif d[s][t] == math.inf:
        print(-1)
    else:
        print(d[s][t]-1) s == t s t print(0) print 0 elif d[s][t] == math.inf:
        print(-1)
     d[s][t] == math.inf d[s][t] [s] d s t math.inf math inf print(-1) print -1 print(d[s][t]-1) print d[s][t]-1 d[s][t] [s] d s t 1 M, L = map(int, input().split()) map(int, input().split()) M input = sys.stdin.readline sys.stdin.readline input N, M, L = map(int, input().split()) map(int, input().split()) N def warshall_floyd(d):
    for k in range(len(d)):
        for i in range(len(d)):
            for j in range(len(d)):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]) def warshall_floyd(d):
    for k in range(len(d)):
        for i in range(len(d)):
            for j in range(len(d)):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]) warshall_floyd c = map(int, input().split()) map(int, input().split()) c s -= 1 1 s d = [[math.inf] * N for _ in range(N)] [[math.inf] * N for _ in range(N)] d t = map(int, input().split()) map(int, input().split()) t t -= 1 1 t L = map(int, input().split()) map(int, input().split()) L s, t = map(int, input().split()) map(int, input().split()) s a -= 1 1 a Q = int(input()) int(input()) Q b -= 1 1 b a, b, c = map(int, input().split()) map(int, input().split()) a b, c = map(int, input().split()) map(int, input().split()) b
import sys
import math

input = sys.stdin.readline


def warshall_floyd(d):
    for k in range(len(d)):
        for i in range(len(d)):
            for j in range(len(d)):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])


N, M, L = map(int, input().split())
d = [[math.inf] * N for _ in range(N)]
for i in range(N):
    d[i][i] = 0
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    d[a][b] = c
    d[b][a] = c
warshall_floyd(d)
for i in range(N):
    for j in range(N):
        d[i][j] = 1 if d[i][j] <= L else math.inf
for i in range(N):
    d[i][i] = 0
warshall_floyd(d)


Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    if s == t:
        print(0)
    elif d[s][t] == math.inf:
        print(-1)
    else:
        print(d[s][t]-1)
