import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

INF = 10**12
N, M, L = map(int, readline().split())

ABCQST = np.array(read().split(), dtype=np.int64)
ABC = ABCQST[:3*M]
A = ABC[::3]; B = ABC[1::3]; C = ABC[2::3]

Q = ABCQST[3*M]

ST = ABCQST[3*M + 1:]
S = ST[::2]; T = ST[1::2]

graph = csr_matrix((C, (A, B)), (N + 1, N + 1))
d = floyd_warshall(graph, directed=False)

d[d <= L] = 1
d[d > L] = INF

d = floyd_warshall(d, directed=False).astype(int)
d[d == INF] = 0

d -= 1
print('\n'.join(d.astype(str)[S, T])) import sys sys read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline readlines = sys.stdin.buffer.readlines readlines sys.stdin.buffer.readlines sys.stdin.buffer sys.stdin sys stdin buffer readlines import numpy as np numpy from scipy.sparse.csgraph import floyd_warshall from scipy.sparse import csr_matrix INF = 10**12 INF 10**12 10 12 N, M, L = map(int, readline().split()) N map(int, readline().split()) map int readline().split() ().split () readline split M L ABCQST = np.array(read().split(), dtype=np.int64) ABCQST np.array(read().split(), dtype=np.int64) np.array np array read().split() ().split () read split dtype=np.int64 dtype np.int64 np int64 ABC = ABCQST[:3*M] ABC ABCQST[:3*M] ABCQST :3*M 3*M 3 M A = ABC[::3] A ABC[::3] ABC ::3 3 B = ABC[1::3] B ABC[1::3] ABC 1::3 1 3 C = ABC[2::3] C ABC[2::3] ABC 2::3 2 3 Q = ABCQST[3*M] Q ABCQST[3*M] ABCQST 3*M 3 M ST = ABCQST[3*M + 1:] ST ABCQST[3*M + 1:] ABCQST 3*M + 1: 3*M + 1 3*M 3 M 1 S = ST[::2] S ST[::2] ST ::2 2 T = ST[1::2] T ST[1::2] ST 1::2 1 2 graph = csr_matrix((C, (A, B)), (N + 1, N + 1)) graph csr_matrix((C, (A, B)), (N + 1, N + 1)) csr_matrix (C, (A, B)) C (A, B) A B (N + 1, N + 1) N + 1 N 1 N + 1 N 1 d = floyd_warshall(graph, directed=False) d floyd_warshall(graph, directed=False) floyd_warshall graph directed=False directed False d[d <= L] = 1 d[d <= L] d d <= L d L 1 d[d > L] = INF d[d > L] d d > L d L INF d = floyd_warshall(d, directed=False).astype(int) d floyd_warshall(d, directed=False).astype(int) (d, directed=False).astype (d, directed=False) floyd_warshall d directed=False directed False astype int d[d == INF] = 0 d[d == INF] d d == INF d INF 0 d -= 1 d 1 print('\n'.join(d.astype(str)[S, T])) print '\n'.join(d.astype(str)[S, T]) '\n'.join '\n' join d.astype(str)[S, T] d.astype(str) d.astype d astype str S B = ABC[1::3] ABC[1::3] B graph = csr_matrix((C, (A, B)), (N + 1, N + 1)) csr_matrix((C, (A, B)), (N + 1, N + 1)) graph d = floyd_warshall(d, directed=False).astype(int) floyd_warshall(d, directed=False).astype(int) d INF = 10**12 10**12 INF M, L = map(int, readline().split()) map(int, readline().split()) M C = ABC[2::3] ABC[2::3] C ABCQST = np.array(read().split(), dtype=np.int64) np.array(read().split(), dtype=np.int64) ABCQST S = ST[::2] ST[::2] S readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline ABC = ABCQST[:3*M] ABCQST[:3*M] ABC d = floyd_warshall(graph, directed=False) floyd_warshall(graph, directed=False) d ST = ABCQST[3*M + 1:] ABCQST[3*M + 1:] ST N, M, L = map(int, readline().split()) map(int, readline().split()) N L = map(int, readline().split()) map(int, readline().split()) L A = ABC[::3] ABC[::3] A readlines = sys.stdin.buffer.readlines sys.stdin.buffer.readlines readlines Q = ABCQST[3*M] ABCQST[3*M] Q T = ST[1::2] ST[1::2] T d -= 1 1 d read = sys.stdin.buffer.read sys.stdin.buffer.read read
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

INF = 10**12
N, M, L = map(int, readline().split())

ABCQST = np.array(read().split(), dtype=np.int64)
ABC = ABCQST[:3*M]
A = ABC[::3]; B = ABC[1::3]; C = ABC[2::3]

Q = ABCQST[3*M]

ST = ABCQST[3*M + 1:]
S = ST[::2]; T = ST[1::2]

graph = csr_matrix((C, (A, B)), (N + 1, N + 1))
d = floyd_warshall(graph, directed=False)

d[d <= L] = 1
d[d > L] = INF

d = floyd_warshall(d, directed=False).astype(int)
d[d == INF] = 0

d -= 1
print('\n'.join(d.astype(str)[S, T]))
