# coding: utf-8
from scipy.sparse.csgraph import floyd_warshall

N,M,L=map(int, input().split())
RG=[[0 for i in range(N)] for j in range(N)]

for i in range(M):
    f,t,c = map(int, input().split())
    if c <= L:
        RG[f-1][t-1] = c
        RG[t-1][f-1] = c

Rd = floyd_warshall(RG, directed=False)

FG=[[0 for i in range(N)] for j in range(N)]
for i in range(N):
    for j in range(i+1, N):
        if Rd[i][j] <= L:
            FG[i][j] = 1
            FG[j][i] = 1

Fd = floyd_warshall(FG, directed=False)

Q=int(input())
for i in range(Q):
    s, t = map(int, input().split())
    v = Fd[s-1][t-1]
    if s == t:
        print (str(0))
    if v == float('inf'):
        print (str(-1))
    else:
        print (str(int(v-1)))
 from scipy.sparse.csgraph import floyd_warshall N,M,L=map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L [0 for i in range(N)] for j in range(N) for j in range(N) j range(N) range N for j in range(N) [0 for i in range(N)] RG=[[0 for i in range(N)] for j in range(N)] RG [[0 for i in range(N)] for j in range(N)] for i in range(M):
    f,t,c = map(int, input().split())
    if c <= L:
        RG[f-1][t-1] = c
        RG[t-1][f-1] = c i range(M) range M f,t,c = map(int, input().split()) f map(int, input().split()) map int input().split() ().split () input split t c if c <= L:
        RG[f-1][t-1] = c
        RG[t-1][f-1] = c c <= L c L RG[f-1][t-1] = c RG[f-1][t-1] [f-1] RG f-1 f 1 t-1 t 1 c RG[t-1][f-1] = c RG[t-1][f-1] [t-1] RG t-1 t 1 f-1 f 1 c Rd = floyd_warshall(RG, directed=False) Rd floyd_warshall(RG, directed=False) floyd_warshall RG directed=False directed False [0 for i in range(N)] for j in range(N) for j in range(N) j range(N) range N for j in range(N) [0 for i in range(N)] FG=[[0 for i in range(N)] for j in range(N)] FG [[0 for i in range(N)] for j in range(N)] for i in range(N):
    for j in range(i+1, N):
        if Rd[i][j] <= L:
            FG[i][j] = 1
            FG[j][i] = 1 i range(N) range N for j in range(i+1, N):
        if Rd[i][j] <= L:
            FG[i][j] = 1
            FG[j][i] = 1 j range(i+1, N) range i+1 i 1 N if Rd[i][j] <= L:
            FG[i][j] = 1
            FG[j][i] = 1 Rd[i][j] <= L Rd[i][j] [i] Rd i j L FG[i][j] = 1 FG[i][j] [i] FG i j 1 FG[j][i] = 1 FG[j][i] [j] FG j i 1 Fd = floyd_warshall(FG, directed=False) Fd floyd_warshall(FG, directed=False) floyd_warshall FG directed=False directed False Q=int(input()) Q int(input()) int input() input for i in range(Q):
    s, t = map(int, input().split())
    v = Fd[s-1][t-1]
    if s == t:
        print (str(0))
    if v == float('inf'):
        print (str(-1))
    else:
        print (str(int(v-1))) i range(Q) range Q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t v = Fd[s-1][t-1] v Fd[s-1][t-1] [s-1] Fd s-1 s 1 t-1 t 1 if s == t:
        print (str(0))
     s == t s t print (str(0)) print str(0) str 0 if v == float('inf'):
        print (str(-1))
    else:
        print (str(int(v-1))) v == float('inf') v float('inf') float 'inf' print (str(-1)) print str(-1) str -1 print (str(int(v-1))) print str(int(v-1)) str int(v-1) int v-1 v 1 M,L=map(int, input().split()) map(int, input().split()) M L=map(int, input().split()) map(int, input().split()) L t,c = map(int, input().split()) map(int, input().split()) t v = Fd[s-1][t-1] Fd[s-1][t-1] v c = map(int, input().split()) map(int, input().split()) c f,t,c = map(int, input().split()) map(int, input().split()) f RG=[[0 for i in range(N)] for j in range(N)] [[0 for i in range(N)] for j in range(N)] RG Q=int(input()) int(input()) Q Rd = floyd_warshall(RG, directed=False) floyd_warshall(RG, directed=False) Rd FG=[[0 for i in range(N)] for j in range(N)] [[0 for i in range(N)] for j in range(N)] FG s, t = map(int, input().split()) map(int, input().split()) s t = map(int, input().split()) map(int, input().split()) t N,M,L=map(int, input().split()) map(int, input().split()) N Fd = floyd_warshall(FG, directed=False) floyd_warshall(FG, directed=False) Fd
# coding: utf-8
from scipy.sparse.csgraph import floyd_warshall

N,M,L=map(int, input().split())
RG=[[0 for i in range(N)] for j in range(N)]

for i in range(M):
    f,t,c = map(int, input().split())
    if c <= L:
        RG[f-1][t-1] = c
        RG[t-1][f-1] = c

Rd = floyd_warshall(RG, directed=False)

FG=[[0 for i in range(N)] for j in range(N)]
for i in range(N):
    for j in range(i+1, N):
        if Rd[i][j] <= L:
            FG[i][j] = 1
            FG[j][i] = 1

Fd = floyd_warshall(FG, directed=False)

Q=int(input())
for i in range(Q):
    s, t = map(int, input().split())
    v = Fd[s-1][t-1]
    if s == t:
        print (str(0))
    if v == float('inf'):
        print (str(-1))
    else:
        print (str(int(v-1)))

