import sys
input = sys.stdin.readline
N,M,L = map(int,input().split())
ABC = [tuple(map(int,input().split())) for i in range(M)]
Q = int(input())
ST = [tuple(map(int,input().split())) for i in range(Q)]

INF = float('inf')
ds = [[INF]*N for i in range(N)]
for a,b,c in ABC:
    a,b = a-1,b-1
    ds[a][b] = ds[b][a] = c
for i in range(N):
    ds[i][i] = 0

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

ls = [[INF]*N for i in range(N)]
for i in range(N-1):
    for j in range(i+1,N):
        if ds[i][j] <= L:
            ls[i][j] = ls[j][i] = 1
for i in range(N):
    ls[i][i] = 0

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

ans = []
for s,t in ST:
    ans.append(-1 if ls[s-1][t-1]==INF else ls[s-1][t-1] - 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 tuple(map(int,input().split())) for i in range(M) for i in range(M) i range(M) range M for i in range(M) tuple(map(int,input().split())) tuple map(int,input().split()) map int input().split() ().split () input split ABC = [tuple(map(int,input().split())) for i in range(M)] ABC [tuple(map(int,input().split())) for i in range(M)] Q = int(input()) Q int(input()) int input() input tuple(map(int,input().split())) for i in range(Q) for i in range(Q) i range(Q) range Q for i in range(Q) tuple(map(int,input().split())) tuple map(int,input().split()) map int input().split() ().split () input split ST = [tuple(map(int,input().split())) for i in range(Q)] ST [tuple(map(int,input().split())) for i in range(Q)] INF = float('inf') INF float('inf') float 'inf' [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 ds = [[INF]*N for i in range(N)] ds [[INF]*N for i in range(N)] for a,b,c in ABC:
    a,b = a-1,b-1
    ds[a][b] = ds[b][a] = c a b c ABC a,b = a-1,b-1 a a-1 a 1 b b-1 b 1 ds[a][b] = ds[b][a] = c ds[a][b] [a] ds a b c = ds[b][a] = c ds[b][a] [b] ds b a c for i in range(N):
    ds[i][i] = 0 i range(N) range N ds[i][i] = 0 ds[i][i] [i] ds i i 0 for k in range(N):
    for i in range(N):
        for j in range(N):
            ds[i][j] = min(ds[i][j], ds[i][k]+ds[k][j]) k range(N) range N for i in range(N):
        for j in range(N):
            ds[i][j] = min(ds[i][j], ds[i][k]+ds[k][j]) i range(N) range N for j in range(N):
            ds[i][j] = min(ds[i][j], ds[i][k]+ds[k][j]) j range(N) range N ds[i][j] = min(ds[i][j], ds[i][k]+ds[k][j]) ds[i][j] [i] ds i j min(ds[i][j], ds[i][k]+ds[k][j]) min ds[i][j] [i] ds i j ds[i][k]+ds[k][j] ds[i][k] [i] ds i k ds[k][j] [k] ds 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 ls = [[INF]*N for i in range(N)] ls [[INF]*N for i in range(N)] for i in range(N-1):
    for j in range(i+1,N):
        if ds[i][j] <= L:
            ls[i][j] = ls[j][i] = 1 i range(N-1) range N-1 N 1 for j in range(i+1,N):
        if ds[i][j] <= L:
            ls[i][j] = ls[j][i] = 1 j range(i+1,N) range i+1 i 1 N if ds[i][j] <= L:
            ls[i][j] = ls[j][i] = 1 ds[i][j] <= L ds[i][j] [i] ds i j L ls[i][j] = ls[j][i] = 1 ls[i][j] [i] ls i j 1 = ls[j][i] = 1 ls[j][i] [j] ls j i 1 for i in range(N):
    ls[i][i] = 0 i range(N) range N ls[i][i] = 0 ls[i][i] [i] ls i i 0 for k in range(N):
    for i in range(N):
        for j in range(N):
            ls[i][j] = min(ls[i][j], ls[i][k]+ls[k][j]) k range(N) range N for i in range(N):
        for j in range(N):
            ls[i][j] = min(ls[i][j], ls[i][k]+ls[k][j]) i range(N) range N for j in range(N):
            ls[i][j] = min(ls[i][j], ls[i][k]+ls[k][j]) j range(N) range N ls[i][j] = min(ls[i][j], ls[i][k]+ls[k][j]) ls[i][j] [i] ls i j min(ls[i][j], ls[i][k]+ls[k][j]) min ls[i][j] [i] ls i j ls[i][k]+ls[k][j] ls[i][k] [i] ls i k ls[k][j] [k] ls k j ans = [] ans [] for s,t in ST:
    ans.append(-1 if ls[s-1][t-1]==INF else ls[s-1][t-1] - 1) s t ST ans.append(-1 if ls[s-1][t-1]==INF else ls[s-1][t-1] - 1) ans.append ans append -1 if ls[s-1][t-1]==INF else ls[s-1][t-1] - 1 ls[s-1][t-1]==INF ls[s-1][t-1] [s-1] ls s-1 s 1 t-1 t 1 INF -1 ls[s-1][t-1] - 1 ls[s-1][t-1] [s-1] ls s-1 s 1 t-1 t 1 1 print(*ans, sep='\n') print *ans ans sep='\n' sep '\n' ds = [[INF]*N for i in range(N)] [[INF]*N for i in range(N)] ds INF = float('inf') float('inf') INF input = sys.stdin.readline sys.stdin.readline input a,b = a-1,b-1 a-1 a ST = [tuple(map(int,input().split())) for i in range(Q)] [tuple(map(int,input().split())) for i in range(Q)] ST Q = int(input()) int(input()) Q N,M,L = map(int,input().split()) map(int,input().split()) N b = a-1,b-1 b-1 b ls = [[INF]*N for i in range(N)] [[INF]*N for i in range(N)] ls L = map(int,input().split()) map(int,input().split()) L M,L = map(int,input().split()) map(int,input().split()) M ABC = [tuple(map(int,input().split())) for i in range(M)] [tuple(map(int,input().split())) for i in range(M)] ABC ans = [] [] ans
import sys
input = sys.stdin.readline
N,M,L = map(int,input().split())
ABC = [tuple(map(int,input().split())) for i in range(M)]
Q = int(input())
ST = [tuple(map(int,input().split())) for i in range(Q)]

INF = float('inf')
ds = [[INF]*N for i in range(N)]
for a,b,c in ABC:
    a,b = a-1,b-1
    ds[a][b] = ds[b][a] = c
for i in range(N):
    ds[i][i] = 0

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

ls = [[INF]*N for i in range(N)]
for i in range(N-1):
    for j in range(i+1,N):
        if ds[i][j] <= L:
            ls[i][j] = ls[j][i] = 1
for i in range(N):
    ls[i][i] = 0

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

ans = []
for s,t in ST:
    ans.append(-1 if ls[s-1][t-1]==INF else ls[s-1][t-1] - 1)
print(*ans, sep='\n')