import sys
input = sys.stdin.readline

N, M, L = map(int, input().split())
INF = 10**18
G = [[INF]*N for i in range(N)]
for i in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    if c <= L:
        G[a][b] = c
        G[b][a] = c
for k in range(N):
    for i in range(N):
        for j in range(N):
            G[i][j] = min(G[i][j], G[i][k]+G[k][j])
G2 = [[INF]*N for i in range(N)]
for i in range(N):
    for j in range(N):
        if G[i][j] <= L:
            G2[i][j] = 1
for k in range(N):
    for i in range(N):
        for j in range(N):
            G2[i][j] = min(G2[i][j], G2[i][k]+G2[k][j])
Q = int(input())
ans = []
for i in range(Q):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    if G2[s][t] == INF:
        ans.append(-1)
    else:
        ans.append(G2[s][t]-1)
print(*ans, sep="\n") import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L INF = 10**18 INF 10**18 10 18 [INF]*N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [INF]*N [INF] INF N G = [[INF]*N for i in range(N)] G [[INF]*N for i in range(N)] for i in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    if c <= L:
        G[a][b] = c
        G[b][a] = c i 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 if c <= L:
        G[a][b] = c
        G[b][a] = c c <= L c L G[a][b] = c G[a][b] [a] G a b c G[b][a] = c G[b][a] [b] G b a c for k in range(N):
    for i in range(N):
        for j in range(N):
            G[i][j] = min(G[i][j], G[i][k]+G[k][j]) k range(N) range N for i in range(N):
        for j in range(N):
            G[i][j] = min(G[i][j], G[i][k]+G[k][j]) i range(N) range N for j in range(N):
            G[i][j] = min(G[i][j], G[i][k]+G[k][j]) j range(N) range N G[i][j] = min(G[i][j], G[i][k]+G[k][j]) G[i][j] [i] G i j min(G[i][j], G[i][k]+G[k][j]) min G[i][j] [i] G i j G[i][k]+G[k][j] G[i][k] [i] G i k G[k][j] [k] G k j [INF]*N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [INF]*N [INF] INF N G2 = [[INF]*N for i in range(N)] G2 [[INF]*N for i in range(N)] for i in range(N):
    for j in range(N):
        if G[i][j] <= L:
            G2[i][j] = 1 i range(N) range N for j in range(N):
        if G[i][j] <= L:
            G2[i][j] = 1 j range(N) range N if G[i][j] <= L:
            G2[i][j] = 1 G[i][j] <= L G[i][j] [i] G i j L G2[i][j] = 1 G2[i][j] [i] G2 i j 1 for k in range(N):
    for i in range(N):
        for j in range(N):
            G2[i][j] = min(G2[i][j], G2[i][k]+G2[k][j]) k range(N) range N for i in range(N):
        for j in range(N):
            G2[i][j] = min(G2[i][j], G2[i][k]+G2[k][j]) i range(N) range N for j in range(N):
            G2[i][j] = min(G2[i][j], G2[i][k]+G2[k][j]) j range(N) range N G2[i][j] = min(G2[i][j], G2[i][k]+G2[k][j]) G2[i][j] [i] G2 i j min(G2[i][j], G2[i][k]+G2[k][j]) min G2[i][j] [i] G2 i j G2[i][k]+G2[k][j] G2[i][k] [i] G2 i k G2[k][j] [k] G2 k j Q = int(input()) Q int(input()) int input() input ans = [] ans [] for i in range(Q):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    if G2[s][t] == INF:
        ans.append(-1)
    else:
        ans.append(G2[s][t]-1) i 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 G2[s][t] == INF:
        ans.append(-1)
    else:
        ans.append(G2[s][t]-1) G2[s][t] == INF G2[s][t] [s] G2 s t INF ans.append(-1) ans.append ans append -1 ans.append(G2[s][t]-1) ans.append ans append G2[s][t]-1 G2[s][t] [s] G2 s t 1 print(*ans, sep="\n") print *ans ans sep="\n" sep "\n" s, t = map(int, input().split()) map(int, input().split()) s t -= 1 1 t L = map(int, input().split()) map(int, input().split()) L c = map(int, input().split()) map(int, input().split()) c s -= 1 1 s input = sys.stdin.readline sys.stdin.readline input b, c = map(int, input().split()) map(int, input().split()) b b -= 1 1 b a, b, c = map(int, input().split()) map(int, input().split()) a t = map(int, input().split()) map(int, input().split()) t G2 = [[INF]*N for i in range(N)] [[INF]*N for i in range(N)] G2 Q = int(input()) int(input()) Q G = [[INF]*N for i in range(N)] [[INF]*N for i in range(N)] G a -= 1 1 a M, L = map(int, input().split()) map(int, input().split()) M ans = [] [] ans N, M, L = map(int, input().split()) map(int, input().split()) N INF = 10**18 10**18 INF
import sys
input = sys.stdin.readline

N, M, L = map(int, input().split())
INF = 10**18
G = [[INF]*N for i in range(N)]
for i in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    if c <= L:
        G[a][b] = c
        G[b][a] = c
for k in range(N):
    for i in range(N):
        for j in range(N):
            G[i][j] = min(G[i][j], G[i][k]+G[k][j])
G2 = [[INF]*N for i in range(N)]
for i in range(N):
    for j in range(N):
        if G[i][j] <= L:
            G2[i][j] = 1
for k in range(N):
    for i in range(N):
        for j in range(N):
            G2[i][j] = min(G2[i][j], G2[i][k]+G2[k][j])
Q = int(input())
ans = []
for i in range(Q):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    if G2[s][t] == INF:
        ans.append(-1)
    else:
        ans.append(G2[s][t]-1)
print(*ans, sep="\n")
