import sys
sys.setrecursionlimit(10**9)
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))
N, M, L = inpl()
road = [[] for _ in range(N)]
ABC = []
for i in range(M):
    A, B, C = inpl()
    if C <= L:
        road[A-1].append((B-1,C))
        road[B-1].append((A-1,C))
        ABC.append((A-1,B-1,C))

INF = 10**12
cur1 = [[INF]*N for _ in range(N)]
for a, b, c in ABC:
    cur1[a][b] = cur1[b][a] = c
for k in range(N):
    prev1 = cur1
    cur1 = [[INF]*N for _ in range(N)] 
    for j in range(N):
        for i in range(N):
            cur1[j][i] = min(prev1[j][i], prev1[k][i]+prev1[j][k])

cur2 = [[INF]*N for j in range(N)]
for j in range(N):
    for i in range(N):
        if cur1[j][i] <= L:
            cur2[j][i] = 1
for k in range(N):
    prev2 = cur2
    cur2 = [[INF]*N for _ in range(N)]
    for j in range(N):
        for i in range(N):
            cur2[j][i] = min(prev2[j][i], prev2[k][i]+prev2[j][k])

Q = int(input())
ST = [inpl() for _ in range(Q)]
for s,t in ST:
    if cur2[s-1][t-1] >= INF:
        print(-1)
    else:
        print(cur2[s-1][t-1]-1) import sys sys sys.setrecursionlimit(10**9) sys.setrecursionlimit sys setrecursionlimit 10**9 10 9 input = lambda: sys.stdin.readline().rstrip() input lambda: sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip inpl = lambda: list(map(int,input().split())) inpl lambda: list(map(int,input().split())) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split N, M, L = inpl() N inpl() inpl M L [] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [] road = [[] for _ in range(N)] road [[] for _ in range(N)] ABC = [] ABC [] for i in range(M):
    A, B, C = inpl()
    if C <= L:
        road[A-1].append((B-1,C))
        road[B-1].append((A-1,C))
        ABC.append((A-1,B-1,C)) i range(M) range M A, B, C = inpl() A inpl() inpl B C if C <= L:
        road[A-1].append((B-1,C))
        road[B-1].append((A-1,C))
        ABC.append((A-1,B-1,C)) C <= L C L road[A-1].append((B-1,C)) [A-1].append [A-1] road A-1 A 1 append (B-1,C) B-1 B 1 C road[B-1].append((A-1,C)) [B-1].append [B-1] road B-1 B 1 append (A-1,C) A-1 A 1 C ABC.append((A-1,B-1,C)) ABC.append ABC append (A-1,B-1,C) A-1 A 1 B-1 B 1 C INF = 10**12 INF 10**12 10 12 [INF]*N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF]*N [INF] INF N cur1 = [[INF]*N for _ in range(N)] cur1 [[INF]*N for _ in range(N)] for a, b, c in ABC:
    cur1[a][b] = cur1[b][a] = c a b c ABC cur1[a][b] = cur1[b][a] = c cur1[a][b] [a] cur1 a b c = cur1[b][a] = c cur1[b][a] [b] cur1 b a c for k in range(N):
    prev1 = cur1
    cur1 = [[INF]*N for _ in range(N)] 
    for j in range(N):
        for i in range(N):
            cur1[j][i] = min(prev1[j][i], prev1[k][i]+prev1[j][k]) k range(N) range N prev1 = cur1 prev1 cur1 [INF]*N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF]*N [INF] INF N cur1 = [[INF]*N for _ in range(N)] cur1 [[INF]*N for _ in range(N)] for j in range(N):
        for i in range(N):
            cur1[j][i] = min(prev1[j][i], prev1[k][i]+prev1[j][k]) j range(N) range N for i in range(N):
            cur1[j][i] = min(prev1[j][i], prev1[k][i]+prev1[j][k]) i range(N) range N cur1[j][i] = min(prev1[j][i], prev1[k][i]+prev1[j][k]) cur1[j][i] [j] cur1 j i min(prev1[j][i], prev1[k][i]+prev1[j][k]) min prev1[j][i] [j] prev1 j i prev1[k][i]+prev1[j][k] prev1[k][i] [k] prev1 k i prev1[j][k] [j] prev1 j k [INF]*N for j in range(N) for j in range(N) j range(N) range N for j in range(N) [INF]*N [INF] INF N cur2 = [[INF]*N for j in range(N)] cur2 [[INF]*N for j in range(N)] for j in range(N):
    for i in range(N):
        if cur1[j][i] <= L:
            cur2[j][i] = 1 j range(N) range N for i in range(N):
        if cur1[j][i] <= L:
            cur2[j][i] = 1 i range(N) range N if cur1[j][i] <= L:
            cur2[j][i] = 1 cur1[j][i] <= L cur1[j][i] [j] cur1 j i L cur2[j][i] = 1 cur2[j][i] [j] cur2 j i 1 for k in range(N):
    prev2 = cur2
    cur2 = [[INF]*N for _ in range(N)]
    for j in range(N):
        for i in range(N):
            cur2[j][i] = min(prev2[j][i], prev2[k][i]+prev2[j][k]) k range(N) range N prev2 = cur2 prev2 cur2 [INF]*N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF]*N [INF] INF N cur2 = [[INF]*N for _ in range(N)] cur2 [[INF]*N for _ in range(N)] for j in range(N):
        for i in range(N):
            cur2[j][i] = min(prev2[j][i], prev2[k][i]+prev2[j][k]) j range(N) range N for i in range(N):
            cur2[j][i] = min(prev2[j][i], prev2[k][i]+prev2[j][k]) i range(N) range N cur2[j][i] = min(prev2[j][i], prev2[k][i]+prev2[j][k]) cur2[j][i] [j] cur2 j i min(prev2[j][i], prev2[k][i]+prev2[j][k]) min prev2[j][i] [j] prev2 j i prev2[k][i]+prev2[j][k] prev2[k][i] [k] prev2 k i prev2[j][k] [j] prev2 j k Q = int(input()) Q int(input()) int input() input inpl() for _ in range(Q) for _ in range(Q) _ range(Q) range Q for _ in range(Q) inpl() inpl ST = [inpl() for _ in range(Q)] ST [inpl() for _ in range(Q)] for s,t in ST:
    if cur2[s-1][t-1] >= INF:
        print(-1)
    else:
        print(cur2[s-1][t-1]-1) s t ST if cur2[s-1][t-1] >= INF:
        print(-1)
    else:
        print(cur2[s-1][t-1]-1) cur2[s-1][t-1] >= INF cur2[s-1][t-1] [s-1] cur2 s-1 s 1 t-1 t 1 INF print(-1) print -1 print(cur2[s-1][t-1]-1) print cur2[s-1][t-1]-1 cur2[s-1][t-1] [s-1] cur2 s-1 s 1 t-1 t 1 1 B, C = inpl() inpl() B C = inpl() inpl() C INF = 10**12 10**12 INF cur2 = [[INF]*N for j in range(N)] [[INF]*N for j in range(N)] cur2 ST = [inpl() for _ in range(Q)] [inpl() for _ in range(Q)] ST inpl = lambda: list(map(int,input().split())) lambda: list(map(int,input().split())) inpl A, B, C = inpl() inpl() A M, L = inpl() inpl() M prev1 = cur1 cur1 prev1 Q = int(input()) int(input()) Q L = inpl() inpl() L ABC = [] [] ABC input = lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() input prev2 = cur2 cur2 prev2 cur1 = [[INF]*N for _ in range(N)] [[INF]*N for _ in range(N)] cur1 cur1 = [[INF]*N for _ in range(N)] [[INF]*N for _ in range(N)] cur1 N, M, L = inpl() inpl() N road = [[] for _ in range(N)] [[] for _ in range(N)] road cur2 = [[INF]*N for _ in range(N)] [[INF]*N for _ in range(N)] cur2
import sys
sys.setrecursionlimit(10**9)
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))
N, M, L = inpl()
road = [[] for _ in range(N)]
ABC = []
for i in range(M):
    A, B, C = inpl()
    if C <= L:
        road[A-1].append((B-1,C))
        road[B-1].append((A-1,C))
        ABC.append((A-1,B-1,C))

INF = 10**12
cur1 = [[INF]*N for _ in range(N)]
for a, b, c in ABC:
    cur1[a][b] = cur1[b][a] = c
for k in range(N):
    prev1 = cur1
    cur1 = [[INF]*N for _ in range(N)] 
    for j in range(N):
        for i in range(N):
            cur1[j][i] = min(prev1[j][i], prev1[k][i]+prev1[j][k])

cur2 = [[INF]*N for j in range(N)]
for j in range(N):
    for i in range(N):
        if cur1[j][i] <= L:
            cur2[j][i] = 1
for k in range(N):
    prev2 = cur2
    cur2 = [[INF]*N for _ in range(N)]
    for j in range(N):
        for i in range(N):
            cur2[j][i] = min(prev2[j][i], prev2[k][i]+prev2[j][k])

Q = int(input())
ST = [inpl() for _ in range(Q)]
for s,t in ST:
    if cur2[s-1][t-1] >= INF:
        print(-1)
    else:
        print(cur2[s-1][t-1]-1)