from scipy.sparse.csgraph import csgraph_from_dense
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
import numpy as np
N,M,L=map(int,input().split())
A=[0]*M
B=[0]*M
C=[0]*M
for i in range(M):
    A[i],B[i],C[i] = map(int,input().split())
    A[i] -=1
    B[i] -=1
Q=int(input())
ST=[list(map(int,input().split())) for _ in range(Q)]


G = csr_matrix((C, (A, B)), shape=(N, N))
d = floyd_warshall(G, directed=False)
G=np.full((N,N), np.inf)
G[d<=L]=1
G = csr_matrix(G)
E = floyd_warshall(G, directed=False)

for s,t in ST:
    if E[s-1][t-1]==float('inf'):
        print(-1)
    else:
        print(int(E[s-1][t-1]-1)) from scipy.sparse.csgraph import csgraph_from_dense from scipy.sparse import csr_matrix from scipy.sparse.csgraph import floyd_warshall import numpy as np numpy N,M,L=map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M L A=[0]*M A [0]*M [0] 0 M B=[0]*M B [0]*M [0] 0 M C=[0]*M C [0]*M [0] 0 M for i in range(M):
    A[i],B[i],C[i] = map(int,input().split())
    A[i] -=1
    B[i] -=1 i range(M) range M A[i],B[i],C[i] = map(int,input().split()) A[i] A i map(int,input().split()) map int input().split() ().split () input split B[i] B i C[i] C i A[i] -=1 A[i] A i 1 B[i] -=1 B[i] B i 1 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)] G = csr_matrix((C, (A, B)), shape=(N, N)) G csr_matrix((C, (A, B)), shape=(N, N)) csr_matrix (C, (A, B)) C (A, B) A B shape=(N, N) shape (N, N) N N d = floyd_warshall(G, directed=False) d floyd_warshall(G, directed=False) floyd_warshall G directed=False directed False G=np.full((N,N), np.inf) G np.full((N,N), np.inf) np.full np full (N,N) N N np.inf np inf G[d<=L]=1 G[d<=L] G d<=L d L 1 G = csr_matrix(G) G csr_matrix(G) csr_matrix G E = floyd_warshall(G, directed=False) E floyd_warshall(G, directed=False) floyd_warshall G directed=False directed False for s,t in ST:
    if E[s-1][t-1]==float('inf'):
        print(-1)
    else:
        print(int(E[s-1][t-1]-1)) s t ST if E[s-1][t-1]==float('inf'):
        print(-1)
    else:
        print(int(E[s-1][t-1]-1)) E[s-1][t-1]==float('inf') E[s-1][t-1] [s-1] E s-1 s 1 t-1 t 1 float('inf') float 'inf' print(-1) print -1 print(int(E[s-1][t-1]-1)) print int(E[s-1][t-1]-1) int E[s-1][t-1]-1 E[s-1][t-1] [s-1] E s-1 s 1 t-1 t 1 1 B=[0]*M [0]*M B E = floyd_warshall(G, directed=False) floyd_warshall(G, directed=False) E L=map(int,input().split()) map(int,input().split()) L N,M,L=map(int,input().split()) map(int,input().split()) N Q=int(input()) int(input()) Q G = csr_matrix(G) csr_matrix(G) G A=[0]*M [0]*M A M,L=map(int,input().split()) map(int,input().split()) M d = floyd_warshall(G, directed=False) floyd_warshall(G, directed=False) d C=[0]*M [0]*M C G=np.full((N,N), np.inf) np.full((N,N), np.inf) G ST=[list(map(int,input().split())) for _ in range(Q)] [list(map(int,input().split())) for _ in range(Q)] ST G = csr_matrix((C, (A, B)), shape=(N, N)) csr_matrix((C, (A, B)), shape=(N, N)) G
from scipy.sparse.csgraph import csgraph_from_dense
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
import numpy as np
N,M,L=map(int,input().split())
A=[0]*M
B=[0]*M
C=[0]*M
for i in range(M):
    A[i],B[i],C[i] = map(int,input().split())
    A[i] -=1
    B[i] -=1
Q=int(input())
ST=[list(map(int,input().split())) for _ in range(Q)]


G = csr_matrix((C, (A, B)), shape=(N, N))
d = floyd_warshall(G, directed=False)
G=np.full((N,N), np.inf)
G[d<=L]=1
G = csr_matrix(G)
E = floyd_warshall(G, directed=False)

for s,t in ST:
    if E[s-1][t-1]==float('inf'):
        print(-1)
    else:
        print(int(E[s-1][t-1]-1))