import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

N,M,L=map(int,input().split())
d=[[0 for i in range(0,N)] for i in range(0,N)]
for i in range(0,M):
    a,b,c=map(int,input().split())
    d[a-1][b-1]=c
    d[b-1][a-1]=c

csr1=csr_matrix(d)

a=floyd_warshall(csr1)

d=[[0 for i in range(0,N)] for j in range(0,N)]
for i in range(0,N):
    for j in range(0,N):
        if L>=a[i][j]:
            d[i][j]=1


csr2=csr_matrix(d)

data=floyd_warshall(csr2)
ans=[]
Q=int(input())
for i in range(0,Q):
    s,t=map(int,input().split())
    if data[s-1][t-1]!=float('inf'):
        ans.append(int(data[s-1][t-1])-1)
    else:
        ans.append(-1)

for i in range(Q):
    print(ans[i]) import numpy as np numpy from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson from scipy.sparse import csr_matrix 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(0,N)] for i in range(0,N) for i in range(0,N) i range(0,N) range 0 N for i in range(0,N) [0 for i in range(0,N)] d=[[0 for i in range(0,N)] for i in range(0,N)] d [[0 for i in range(0,N)] for i in range(0,N)] for i in range(0,M):
    a,b,c=map(int,input().split())
    d[a-1][b-1]=c
    d[b-1][a-1]=c i range(0,M) range 0 M a,b,c=map(int,input().split()) a map(int,input().split()) map int input().split() ().split () input split b c d[a-1][b-1]=c d[a-1][b-1] [a-1] d a-1 a 1 b-1 b 1 c d[b-1][a-1]=c d[b-1][a-1] [b-1] d b-1 b 1 a-1 a 1 c csr1=csr_matrix(d) csr1 csr_matrix(d) csr_matrix d a=floyd_warshall(csr1) a floyd_warshall(csr1) floyd_warshall csr1 [0 for i in range(0,N)] for j in range(0,N) for j in range(0,N) j range(0,N) range 0 N for j in range(0,N) [0 for i in range(0,N)] d=[[0 for i in range(0,N)] for j in range(0,N)] d [[0 for i in range(0,N)] for j in range(0,N)] for i in range(0,N):
    for j in range(0,N):
        if L>=a[i][j]:
            d[i][j]=1 i range(0,N) range 0 N for j in range(0,N):
        if L>=a[i][j]:
            d[i][j]=1 j range(0,N) range 0 N if L>=a[i][j]:
            d[i][j]=1 L>=a[i][j] L a[i][j] [i] a i j d[i][j]=1 d[i][j] [i] d i j 1 csr2=csr_matrix(d) csr2 csr_matrix(d) csr_matrix d data=floyd_warshall(csr2) data floyd_warshall(csr2) floyd_warshall csr2 ans=[] ans [] Q=int(input()) Q int(input()) int input() input for i in range(0,Q):
    s,t=map(int,input().split())
    if data[s-1][t-1]!=float('inf'):
        ans.append(int(data[s-1][t-1])-1)
    else:
        ans.append(-1) i range(0,Q) range 0 Q s,t=map(int,input().split()) s map(int,input().split()) map int input().split() ().split () input split t if data[s-1][t-1]!=float('inf'):
        ans.append(int(data[s-1][t-1])-1)
    else:
        ans.append(-1) data[s-1][t-1]!=float('inf') data[s-1][t-1] [s-1] data s-1 s 1 t-1 t 1 float('inf') float 'inf' ans.append(int(data[s-1][t-1])-1) ans.append ans append int(data[s-1][t-1])-1 int(data[s-1][t-1]) int data[s-1][t-1] [s-1] data s-1 s 1 t-1 t 1 1 ans.append(-1) ans.append ans append -1 for i in range(Q):
    print(ans[i]) i range(Q) range Q print(ans[i]) print ans[i] ans i d=[[0 for i in range(0,N)] for j in range(0,N)] [[0 for i in range(0,N)] for j in range(0,N)] d L=map(int,input().split()) map(int,input().split()) L N,M,L=map(int,input().split()) map(int,input().split()) N ans=[] [] ans Q=int(input()) int(input()) Q a,b,c=map(int,input().split()) map(int,input().split()) a t=map(int,input().split()) map(int,input().split()) t c=map(int,input().split()) map(int,input().split()) c a=floyd_warshall(csr1) floyd_warshall(csr1) a csr2=csr_matrix(d) csr_matrix(d) csr2 d=[[0 for i in range(0,N)] for i in range(0,N)] [[0 for i in range(0,N)] for i in range(0,N)] d csr1=csr_matrix(d) csr_matrix(d) csr1 b,c=map(int,input().split()) map(int,input().split()) b data=floyd_warshall(csr2) floyd_warshall(csr2) data M,L=map(int,input().split()) map(int,input().split()) M s,t=map(int,input().split()) map(int,input().split()) s
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

N,M,L=map(int,input().split())
d=[[0 for i in range(0,N)] for i in range(0,N)]
for i in range(0,M):
    a,b,c=map(int,input().split())
    d[a-1][b-1]=c
    d[b-1][a-1]=c

csr1=csr_matrix(d)

a=floyd_warshall(csr1)

d=[[0 for i in range(0,N)] for j in range(0,N)]
for i in range(0,N):
    for j in range(0,N):
        if L>=a[i][j]:
            d[i][j]=1


csr2=csr_matrix(d)

data=floyd_warshall(csr2)
ans=[]
Q=int(input())
for i in range(0,Q):
    s,t=map(int,input().split())
    if data[s-1][t-1]!=float('inf'):
        ans.append(int(data[s-1][t-1])-1)
    else:
        ans.append(-1)

for i in range(Q):
    print(ans[i])