import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, M, L = mapint()
dist = [[10**18]*N for _ in range(N)]
for _ in range(M):
    a, b, c = mapint()
    dist[a-1][b-1] = c
    dist[b-1][a-1] = c

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

oil = [[10**18]*N for _ in range(N)]
for i in range(N-1):
    for j in range(i+1, N):
        if dist[i][j]<=L:
            oil[i][j] = 1
            oil[j][i] = 1

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

Q = int(input())
for _ in range(Q):
    s, t = mapint()
    if oil[s-1][t-1]>=10**17:
        print(-1)
    else:
        print(oil[s-1][t-1]-1) import sys sys def input(): return sys.stdin.readline().strip() input def mapint(): return map(int, input().split()) mapint sys.setrecursionlimit(10**9) sys.setrecursionlimit sys setrecursionlimit 10**9 10 9 N, M, L = mapint() N mapint() mapint M L [10**18]*N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [10**18]*N [10**18] 10**18 10 18 N dist = [[10**18]*N for _ in range(N)] dist [[10**18]*N for _ in range(N)] for _ in range(M):
    a, b, c = mapint()
    dist[a-1][b-1] = c
    dist[b-1][a-1] = c _ range(M) range M a, b, c = mapint() a mapint() mapint b c dist[a-1][b-1] = c dist[a-1][b-1] [a-1] dist a-1 a 1 b-1 b 1 c dist[b-1][a-1] = c dist[b-1][a-1] [b-1] dist b-1 b 1 a-1 a 1 c for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j]=min(dist[i][j], dist[i][k]+dist[k][j]) k range(N) range N for i in range(N):
        for j in range(N):
            dist[i][j]=min(dist[i][j], dist[i][k]+dist[k][j]) i range(N) range N for j in range(N):
            dist[i][j]=min(dist[i][j], dist[i][k]+dist[k][j]) j range(N) range N dist[i][j]=min(dist[i][j], dist[i][k]+dist[k][j]) dist[i][j] [i] dist i j min(dist[i][j], dist[i][k]+dist[k][j]) min dist[i][j] [i] dist i j dist[i][k]+dist[k][j] dist[i][k] [i] dist i k dist[k][j] [k] dist k j [10**18]*N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [10**18]*N [10**18] 10**18 10 18 N oil = [[10**18]*N for _ in range(N)] oil [[10**18]*N for _ in range(N)] for i in range(N-1):
    for j in range(i+1, N):
        if dist[i][j]<=L:
            oil[i][j] = 1
            oil[j][i] = 1 i range(N-1) range N-1 N 1 for j in range(i+1, N):
        if dist[i][j]<=L:
            oil[i][j] = 1
            oil[j][i] = 1 j range(i+1, N) range i+1 i 1 N if dist[i][j]<=L:
            oil[i][j] = 1
            oil[j][i] = 1 dist[i][j]<=L dist[i][j] [i] dist i j L oil[i][j] = 1 oil[i][j] [i] oil i j 1 oil[j][i] = 1 oil[j][i] [j] oil j i 1 for k in range(N):
    for i in range(N):
        for j in range(N):
            oil[i][j]=min(oil[i][j], oil[i][k]+oil[k][j]) k range(N) range N for i in range(N):
        for j in range(N):
            oil[i][j]=min(oil[i][j], oil[i][k]+oil[k][j]) i range(N) range N for j in range(N):
            oil[i][j]=min(oil[i][j], oil[i][k]+oil[k][j]) j range(N) range N oil[i][j]=min(oil[i][j], oil[i][k]+oil[k][j]) oil[i][j] [i] oil i j min(oil[i][j], oil[i][k]+oil[k][j]) min oil[i][j] [i] oil i j oil[i][k]+oil[k][j] oil[i][k] [i] oil i k oil[k][j] [k] oil k j Q = int(input()) Q int(input()) int input() input for _ in range(Q):
    s, t = mapint()
    if oil[s-1][t-1]>=10**17:
        print(-1)
    else:
        print(oil[s-1][t-1]-1) _ range(Q) range Q s, t = mapint() s mapint() mapint t if oil[s-1][t-1]>=10**17:
        print(-1)
    else:
        print(oil[s-1][t-1]-1) oil[s-1][t-1]>=10**17 oil[s-1][t-1] [s-1] oil s-1 s 1 t-1 t 1 10**17 10 17 print(-1) print -1 print(oil[s-1][t-1]-1) print oil[s-1][t-1]-1 oil[s-1][t-1] [s-1] oil s-1 s 1 t-1 t 1 1 b, c = mapint() mapint() b def mapint(): return map(int, input().split()) def mapint(): return map(int, input().split()) mapint s, t = mapint() mapint() s a, b, c = mapint() mapint() a c = mapint() mapint() c oil = [[10**18]*N for _ in range(N)] [[10**18]*N for _ in range(N)] oil N, M, L = mapint() mapint() N M, L = mapint() mapint() M L = mapint() mapint() L t = mapint() mapint() t Q = int(input()) int(input()) Q def input(): return sys.stdin.readline().strip() def input(): return sys.stdin.readline().strip() input dist = [[10**18]*N for _ in range(N)] [[10**18]*N for _ in range(N)] dist
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, M, L = mapint()
dist = [[10**18]*N for _ in range(N)]
for _ in range(M):
    a, b, c = mapint()
    dist[a-1][b-1] = c
    dist[b-1][a-1] = c

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

oil = [[10**18]*N for _ in range(N)]
for i in range(N-1):
    for j in range(i+1, N):
        if dist[i][j]<=L:
            oil[i][j] = 1
            oil[j][i] = 1

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

Q = int(input())
for _ in range(Q):
    s, t = mapint()
    if oil[s-1][t-1]>=10**17:
        print(-1)
    else:
        print(oil[s-1][t-1]-1)