import sys
import numpy as np
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall, csgraph_to_dense
from scipy.sparse import issparse
sys.setrecursionlimit(10**7)

n, m, l = [int(i) for i in sys.stdin.readline().split()]
graph = [[0 for i in range(n)] for j in range(n)]
for i in range(m):
    a, b, c = [int(i) for i in sys.stdin.readline().split()]
    a -= 1
    b -= 1
    graph[a][b] = c
    graph[b][a] = c

res = floyd_warshall(csgraph_from_dense(graph))
if issparse(res):
    res = csgraph_to_dense(res)
res = np.where(res <= l, 1, 0)
new_res = floyd_warshall(res)
new_res[new_res == np.inf] = 0
q = int(input())
for j in range(q):
    s, t = [int(i) for i in sys.stdin.readline().split()]
    s -= 1
    t -= 1
    dis = new_res[s, t]
    print(int(dis) - 1) import sys sys import numpy as np numpy from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall, csgraph_to_dense from scipy.sparse import issparse sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 int(i) for i in sys.stdin.readline().split() for i in sys.stdin.readline().split() i sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for i in sys.stdin.readline().split() int(i) int i n, m, l = [int(i) for i in sys.stdin.readline().split()] n [int(i) for i in sys.stdin.readline().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)] graph = [[0 for i in range(n)] for j in range(n)] graph [[0 for i in range(n)] for j in range(n)] for i in range(m):
    a, b, c = [int(i) for i in sys.stdin.readline().split()]
    a -= 1
    b -= 1
    graph[a][b] = c
    graph[b][a] = c i range(m) range m int(i) for i in sys.stdin.readline().split() for i in sys.stdin.readline().split() i sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for i in sys.stdin.readline().split() int(i) int i a, b, c = [int(i) for i in sys.stdin.readline().split()] a [int(i) for i in sys.stdin.readline().split()] b c a -= 1 a 1 b -= 1 b 1 graph[a][b] = c graph[a][b] [a] graph a b c graph[b][a] = c graph[b][a] [b] graph b a c res = floyd_warshall(csgraph_from_dense(graph)) res floyd_warshall(csgraph_from_dense(graph)) floyd_warshall csgraph_from_dense(graph) csgraph_from_dense graph if issparse(res):
    res = csgraph_to_dense(res) issparse(res) issparse res res = csgraph_to_dense(res) res csgraph_to_dense(res) csgraph_to_dense res res = np.where(res <= l, 1, 0) res np.where(res <= l, 1, 0) np.where np where res <= l res l 1 0 new_res = floyd_warshall(res) new_res floyd_warshall(res) floyd_warshall res new_res[new_res == np.inf] = 0 new_res[new_res == np.inf] new_res new_res == np.inf new_res np.inf np inf 0 q = int(input()) q int(input()) int input() input for j in range(q):
    s, t = [int(i) for i in sys.stdin.readline().split()]
    s -= 1
    t -= 1
    dis = new_res[s, t]
    print(int(dis) - 1) j range(q) range q int(i) for i in sys.stdin.readline().split() for i in sys.stdin.readline().split() i sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for i in sys.stdin.readline().split() int(i) int i s, t = [int(i) for i in sys.stdin.readline().split()] s [int(i) for i in sys.stdin.readline().split()] t s -= 1 s 1 t -= 1 t 1 dis = new_res[s, t] dis new_res[s, t] new_res s print(int(dis) - 1) print int(dis) - 1 int(dis) int dis 1 s -= 1 1 s s, t = [int(i) for i in sys.stdin.readline().split()] [int(i) for i in sys.stdin.readline().split()] s a, b, c = [int(i) for i in sys.stdin.readline().split()] [int(i) for i in sys.stdin.readline().split()] a res = floyd_warshall(csgraph_from_dense(graph)) floyd_warshall(csgraph_from_dense(graph)) res m, l = [int(i) for i in sys.stdin.readline().split()] [int(i) for i in sys.stdin.readline().split()] m graph = [[0 for i in range(n)] for j in range(n)] [[0 for i in range(n)] for j in range(n)] graph b -= 1 1 b n, m, l = [int(i) for i in sys.stdin.readline().split()] [int(i) for i in sys.stdin.readline().split()] n b, c = [int(i) for i in sys.stdin.readline().split()] [int(i) for i in sys.stdin.readline().split()] b dis = new_res[s, t] new_res[s, t] dis c = [int(i) for i in sys.stdin.readline().split()] [int(i) for i in sys.stdin.readline().split()] c l = [int(i) for i in sys.stdin.readline().split()] [int(i) for i in sys.stdin.readline().split()] l res = csgraph_to_dense(res) csgraph_to_dense(res) res new_res = floyd_warshall(res) floyd_warshall(res) new_res a -= 1 1 a res = np.where(res <= l, 1, 0) np.where(res <= l, 1, 0) res q = int(input()) int(input()) q t = [int(i) for i in sys.stdin.readline().split()] [int(i) for i in sys.stdin.readline().split()] t t -= 1 1 t
import sys
import numpy as np
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall, csgraph_to_dense
from scipy.sparse import issparse
sys.setrecursionlimit(10**7)

n, m, l = [int(i) for i in sys.stdin.readline().split()]
graph = [[0 for i in range(n)] for j in range(n)]
for i in range(m):
    a, b, c = [int(i) for i in sys.stdin.readline().split()]
    a -= 1
    b -= 1
    graph[a][b] = c
    graph[b][a] = c

res = floyd_warshall(csgraph_from_dense(graph))
if issparse(res):
    res = csgraph_to_dense(res)
res = np.where(res <= l, 1, 0)
new_res = floyd_warshall(res)
new_res[new_res == np.inf] = 0
q = int(input())
for j in range(q):
    s, t = [int(i) for i in sys.stdin.readline().split()]
    s -= 1
    t -= 1
    dis = new_res[s, t]
    print(int(dis) - 1)