# ABC143-E

import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())


N,M,L = MI()

inf = 10**12
cost = [[inf]*(N+1) for _ in range(N+1)]  # cost[i][j] = 町iから町jへ移動するのにかかる燃料の総和

# WarshallFloyd法

for i in range(M):
    a,b,c = MI()
    cost[a][b] = c
    cost[b][a] = c

for k in range(N+1):
    for i in range(N+1):
        for j in range(N+1):
            cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j])

ans = [[inf]*(N+1) for _ in range(N+1)]  # ans[i][j] = 町iから町jへ移動するために必要な燃料補給の回数+1

# WarshallFloyd法、再び

for i in range(N+1):
    for j in range(N+1):
        if cost[i][j] <= L:
            ans[i][j] = 1

for k in range(N+1):
    for i in range(N+1):
        for j in range(N+1):
            ans[i][j] = min(ans[i][j],ans[i][k]+ans[k][j])

Q = I()
for i in range(Q):
    s,t = MI()
    if ans[s][t] == inf:
        print(-1)
        continue
    print(ans[s][t]-1) import sys sys def I(): return int(sys.stdin.readline().rstrip()) I def MI(): return map(int,sys.stdin.readline().rstrip().split()) MI N,M,L = MI() N MI() MI M L inf = 10**12 inf 10**12 10 12 [inf]*(N+1) for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) [inf]*(N+1) [inf] inf N+1 N 1 cost = [[inf]*(N+1) for _ in range(N+1)] cost [[inf]*(N+1) for _ in range(N+1)] for i in range(M):
    a,b,c = MI()
    cost[a][b] = c
    cost[b][a] = c i range(M) range M a,b,c = MI() a MI() MI b c cost[a][b] = c cost[a][b] [a] cost a b c cost[b][a] = c cost[b][a] [b] cost b a c for k in range(N+1):
    for i in range(N+1):
        for j in range(N+1):
            cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j]) k range(N+1) range N+1 N 1 for i in range(N+1):
        for j in range(N+1):
            cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j]) i range(N+1) range N+1 N 1 for j in range(N+1):
            cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j]) j range(N+1) range N+1 N 1 cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j]) cost[i][j] [i] cost i j min(cost[i][j],cost[i][k]+cost[k][j]) min cost[i][j] [i] cost i j cost[i][k]+cost[k][j] cost[i][k] [i] cost i k cost[k][j] [k] cost k j [inf]*(N+1) for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) [inf]*(N+1) [inf] inf N+1 N 1 ans = [[inf]*(N+1) for _ in range(N+1)] ans [[inf]*(N+1) for _ in range(N+1)] for i in range(N+1):
    for j in range(N+1):
        if cost[i][j] <= L:
            ans[i][j] = 1 i range(N+1) range N+1 N 1 for j in range(N+1):
        if cost[i][j] <= L:
            ans[i][j] = 1 j range(N+1) range N+1 N 1 if cost[i][j] <= L:
            ans[i][j] = 1 cost[i][j] <= L cost[i][j] [i] cost i j L ans[i][j] = 1 ans[i][j] [i] ans i j 1 for k in range(N+1):
    for i in range(N+1):
        for j in range(N+1):
            ans[i][j] = min(ans[i][j],ans[i][k]+ans[k][j]) k range(N+1) range N+1 N 1 for i in range(N+1):
        for j in range(N+1):
            ans[i][j] = min(ans[i][j],ans[i][k]+ans[k][j]) i range(N+1) range N+1 N 1 for j in range(N+1):
            ans[i][j] = min(ans[i][j],ans[i][k]+ans[k][j]) j range(N+1) range N+1 N 1 ans[i][j] = min(ans[i][j],ans[i][k]+ans[k][j]) ans[i][j] [i] ans i j min(ans[i][j],ans[i][k]+ans[k][j]) min ans[i][j] [i] ans i j ans[i][k]+ans[k][j] ans[i][k] [i] ans i k ans[k][j] [k] ans k j Q = I() Q I() I for i in range(Q):
    s,t = MI()
    if ans[s][t] == inf:
        print(-1)
        continue
    print(ans[s][t]-1) i range(Q) range Q s,t = MI() s MI() MI t if ans[s][t] == inf:
        print(-1)
        continue
     ans[s][t] == inf ans[s][t] [s] ans s t inf print(-1) print -1 continue print(ans[s][t]-1) print ans[s][t]-1 ans[s][t] [s] ans s t 1 inf = 10**12 10**12 inf ans = [[inf]*(N+1) for _ in range(N+1)] [[inf]*(N+1) for _ in range(N+1)] ans N,M,L = MI() MI() N a,b,c = MI() MI() a c = MI() MI() c t = MI() MI() t L = MI() MI() L Q = I() I() Q M,L = MI() MI() M def MI(): return map(int,sys.stdin.readline().rstrip().split()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) MI s,t = MI() MI() s def I(): return int(sys.stdin.readline().rstrip()) def I(): return int(sys.stdin.readline().rstrip()) I cost = [[inf]*(N+1) for _ in range(N+1)] [[inf]*(N+1) for _ in range(N+1)] cost b,c = MI() MI() b
# ABC143-E

import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())


N,M,L = MI()

inf = 10**12
cost = [[inf]*(N+1) for _ in range(N+1)]  # cost[i][j] = 町iから町jへ移動するのにかかる燃料の総和

# WarshallFloyd法

for i in range(M):
    a,b,c = MI()
    cost[a][b] = c
    cost[b][a] = c

for k in range(N+1):
    for i in range(N+1):
        for j in range(N+1):
            cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j])

ans = [[inf]*(N+1) for _ in range(N+1)]  # ans[i][j] = 町iから町jへ移動するために必要な燃料補給の回数+1

# WarshallFloyd法、再び

for i in range(N+1):
    for j in range(N+1):
        if cost[i][j] <= L:
            ans[i][j] = 1

for k in range(N+1):
    for i in range(N+1):
        for j in range(N+1):
            ans[i][j] = min(ans[i][j],ans[i][k]+ans[k][j])

Q = I()
for i in range(Q):
    s,t = MI()
    if ans[s][t] == inf:
        print(-1)
        continue
    print(ans[s][t]-1)
