import numpy as np
import sys
from scipy.sparse.csgraph import floyd_warshall,csgraph_from_dense
from scipy.sparse import csr_matrix
input = sys.stdin.readline
def inputs():return [int(x) for x in input().split()]
N,M,L = inputs()
ABC =[inputs() for _ in range(M)]
graph = [[10**13]*(N+1) for _ in range(N+1)]
for a,b,c in ABC:
    graph[a][b] = c
G = csgraph_from_dense(graph, null_value=10**13)
dist_mat = floyd_warshall(graph,directed=False)
graph2 = np.array([[10**13]*(N+1) for _ in range(N+1)])
np.fill_diagonal(graph2,0)
graph2[dist_mat<=L]=1
dist_mat2 = floyd_warshall(graph2,directed=False)
dist_mat2[dist_mat2==10**13]=0
Q = int(input())
for i in range(Q):
    s,t = inputs()
    print(int(dist_mat2[s,t])-1)
 import numpy as np numpy import sys sys from scipy.sparse.csgraph import floyd_warshall,csgraph_from_dense from scipy.sparse import csr_matrix input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x def inputs():return [int(x) for x in input().split()] inputs N,M,L = inputs() N inputs() inputs M L inputs() for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) inputs() inputs ABC =[inputs() for _ in range(M)] ABC [inputs() for _ in range(M)] [10**13]*(N+1) for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) [10**13]*(N+1) [10**13] 10**13 10 13 N+1 N 1 graph = [[10**13]*(N+1) for _ in range(N+1)] graph [[10**13]*(N+1) for _ in range(N+1)] for a,b,c in ABC:
    graph[a][b] = c a b c ABC graph[a][b] = c graph[a][b] [a] graph a b c G = csgraph_from_dense(graph, null_value=10**13) G csgraph_from_dense(graph, null_value=10**13) csgraph_from_dense graph null_value=10**13 null_value 10**13 10 13 dist_mat = floyd_warshall(graph,directed=False) dist_mat floyd_warshall(graph,directed=False) floyd_warshall graph directed=False directed False [10**13]*(N+1) for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) [10**13]*(N+1) [10**13] 10**13 10 13 N+1 N 1 graph2 = np.array([[10**13]*(N+1) for _ in range(N+1)]) graph2 np.array([[10**13]*(N+1) for _ in range(N+1)]) np.array np array [[10**13]*(N+1) for _ in range(N+1)] np.fill_diagonal(graph2,0) np.fill_diagonal np fill_diagonal graph2 0 graph2[dist_mat<=L]=1 graph2[dist_mat<=L] graph2 dist_mat<=L dist_mat L 1 dist_mat2 = floyd_warshall(graph2,directed=False) dist_mat2 floyd_warshall(graph2,directed=False) floyd_warshall graph2 directed=False directed False dist_mat2[dist_mat2==10**13]=0 dist_mat2[dist_mat2==10**13] dist_mat2 dist_mat2==10**13 dist_mat2 10**13 10 13 0 Q = int(input()) Q int(input()) int input() input for i in range(Q):
    s,t = inputs()
    print(int(dist_mat2[s,t])-1) i range(Q) range Q s,t = inputs() s inputs() inputs t print(int(dist_mat2[s,t])-1) print int(dist_mat2[s,t])-1 int(dist_mat2[s,t]) int dist_mat2[s,t] dist_mat2 s 1 dist_mat = floyd_warshall(graph,directed=False) floyd_warshall(graph,directed=False) dist_mat ABC =[inputs() for _ in range(M)] [inputs() for _ in range(M)] ABC L = inputs() inputs() L graph2 = np.array([[10**13]*(N+1) for _ in range(N+1)]) np.array([[10**13]*(N+1) for _ in range(N+1)]) graph2 dist_mat2 = floyd_warshall(graph2,directed=False) floyd_warshall(graph2,directed=False) dist_mat2 N,M,L = inputs() inputs() N G = csgraph_from_dense(graph, null_value=10**13) csgraph_from_dense(graph, null_value=10**13) G def inputs():return [int(x) for x in input().split()] def inputs():return [int(x) for x in input().split()] inputs graph = [[10**13]*(N+1) for _ in range(N+1)] [[10**13]*(N+1) for _ in range(N+1)] graph Q = int(input()) int(input()) Q t = inputs() inputs() t s,t = inputs() inputs() s input = sys.stdin.readline sys.stdin.readline input M,L = inputs() inputs() M
import numpy as np
import sys
from scipy.sparse.csgraph import floyd_warshall,csgraph_from_dense
from scipy.sparse import csr_matrix
input = sys.stdin.readline
def inputs():return [int(x) for x in input().split()]
N,M,L = inputs()
ABC =[inputs() for _ in range(M)]
graph = [[10**13]*(N+1) for _ in range(N+1)]
for a,b,c in ABC:
    graph[a][b] = c
G = csgraph_from_dense(graph, null_value=10**13)
dist_mat = floyd_warshall(graph,directed=False)
graph2 = np.array([[10**13]*(N+1) for _ in range(N+1)])
np.fill_diagonal(graph2,0)
graph2[dist_mat<=L]=1
dist_mat2 = floyd_warshall(graph2,directed=False)
dist_mat2[dist_mat2==10**13]=0
Q = int(input())
for i in range(Q):
    s,t = inputs()
    print(int(dist_mat2[s,t])-1)

