
N,M,L = map(int,input().split())
ABC = [list(map(int,input().split())) for _ in range(M)]
Q = int(input())
st = [list(map(int,input().split())) for _ in range(Q)]

INF = 1<<30
dp = [[INF]*N for _ in range(N)]

for a,b,c in ABC:
    dp[a-1][b-1] = c
    dp[b-1][a-1] = c
    
for k in range(N):
    for i in range(N):
        for j in range(N):
            dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j])
        
d = [[INF]*N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if dp[i][j]<=L:
            d[i][j] = 1
        
for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j] = min(d[i][j], d[i][k]+d[k][j])
        
for s,t in st:
    if d[s-1][t-1]!=INF:
        print(d[s-1][t-1]-1)
    else:
        print(-1) N,M,L = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M L list(map(int,input().split())) for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split ABC = [list(map(int,input().split())) for _ in range(M)] ABC [list(map(int,input().split())) for _ in range(M)] Q = int(input()) Q int(input()) int input() input list(map(int,input().split())) for _ in range(Q) for _ in range(Q) _ range(Q) range Q for _ in range(Q) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split st = [list(map(int,input().split())) for _ in range(Q)] st [list(map(int,input().split())) for _ in range(Q)] INF = 1<<30 INF 1<<30 1 30 [INF]*N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF]*N [INF] INF N dp = [[INF]*N for _ in range(N)] dp [[INF]*N for _ in range(N)] for a,b,c in ABC:
    dp[a-1][b-1] = c
    dp[b-1][a-1] = c
     a b c ABC dp[a-1][b-1] = c dp[a-1][b-1] [a-1] dp a-1 a 1 b-1 b 1 c dp[b-1][a-1] = c dp[b-1][a-1] [b-1] dp b-1 b 1 a-1 a 1 c for k in range(N):
    for i in range(N):
        for j in range(N):
            dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j])
         k range(N) range N for i in range(N):
        for j in range(N):
            dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j])
         i range(N) range N for j in range(N):
            dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j])
         j range(N) range N dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j]) dp[i][j] [i] dp i j min(dp[i][j], dp[i][k]+dp[k][j]) min dp[i][j] [i] dp i j dp[i][k]+dp[k][j] dp[i][k] [i] dp i k dp[k][j] [k] dp k j [INF]*N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF]*N [INF] INF N d = [[INF]*N for _ in range(N)] d [[INF]*N for _ in range(N)] for i in range(N):
    for j in range(N):
        if dp[i][j]<=L:
            d[i][j] = 1
         i range(N) range N for j in range(N):
        if dp[i][j]<=L:
            d[i][j] = 1
         j range(N) range N if dp[i][j]<=L:
            d[i][j] = 1
         dp[i][j]<=L dp[i][j] [i] dp i j L d[i][j] = 1 d[i][j] [i] d i j 1 for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j] = min(d[i][j], d[i][k]+d[k][j])
         k range(N) range N for i in range(N):
        for j in range(N):
            d[i][j] = min(d[i][j], d[i][k]+d[k][j])
         i range(N) range N for j in range(N):
            d[i][j] = min(d[i][j], d[i][k]+d[k][j])
         j range(N) range N 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 for s,t in st:
    if d[s-1][t-1]!=INF:
        print(d[s-1][t-1]-1)
    else:
        print(-1) s t st if d[s-1][t-1]!=INF:
        print(d[s-1][t-1]-1)
    else:
        print(-1) d[s-1][t-1]!=INF d[s-1][t-1] [s-1] d s-1 s 1 t-1 t 1 INF print(d[s-1][t-1]-1) print d[s-1][t-1]-1 d[s-1][t-1] [s-1] d s-1 s 1 t-1 t 1 1 print(-1) print -1 N,M,L = map(int,input().split()) map(int,input().split()) N ABC = [list(map(int,input().split())) for _ in range(M)] [list(map(int,input().split())) for _ in range(M)] ABC st = [list(map(int,input().split())) for _ in range(Q)] [list(map(int,input().split())) for _ in range(Q)] st INF = 1<<30 1<<30 INF dp = [[INF]*N for _ in range(N)] [[INF]*N for _ in range(N)] dp M,L = map(int,input().split()) map(int,input().split()) M L = map(int,input().split()) map(int,input().split()) L Q = int(input()) int(input()) Q d = [[INF]*N for _ in range(N)] [[INF]*N for _ in range(N)] d

N,M,L = map(int,input().split())
ABC = [list(map(int,input().split())) for _ in range(M)]
Q = int(input())
st = [list(map(int,input().split())) for _ in range(Q)]

INF = 1<<30
dp = [[INF]*N for _ in range(N)]

for a,b,c in ABC:
    dp[a-1][b-1] = c
    dp[b-1][a-1] = c
    
for k in range(N):
    for i in range(N):
        for j in range(N):
            dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j])
        
d = [[INF]*N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if dp[i][j]<=L:
            d[i][j] = 1
        
for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j] = min(d[i][j], d[i][k]+d[k][j])
        
for s,t in st:
    if d[s-1][t-1]!=INF:
        print(d[s-1][t-1]-1)
    else:
        print(-1)