import numpy as np
from scipy.sparse import lil_matrix, csr_matrix
from scipy.sparse.csgraph import shortest_path

n,m,limit=map(int,input().split())
G=np.zeros((n,n),dtype=np.int64)
for i in range(m):
    a,b,cost=map(int,input().split())
    G[a-1,b-1]=cost
    G[b-1,a-1]=cost
G=shortest_path(G,method='FW')
for c in range(n):
    for l in range(n):
        if G[c][l]<=limit:
            G[c][l]=1
        else:
            G[c][l]=0
G=shortest_path(G,method='FW')
q=int(input())
Q=[map(int,input().split())for i in range(q)]
for a,b in Q:
    print(int(G[a-1][b-1])-1 if G[a-1][b-1]<10**18 else -1) import numpy as np numpy from scipy.sparse import lil_matrix, csr_matrix from scipy.sparse.csgraph import shortest_path n,m,limit=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m limit G=np.zeros((n,n),dtype=np.int64) G np.zeros((n,n),dtype=np.int64) np.zeros np zeros (n,n) n n dtype=np.int64 dtype np.int64 np int64 for i in range(m):
    a,b,cost=map(int,input().split())
    G[a-1,b-1]=cost
    G[b-1,a-1]=cost i range(m) range m a,b,cost=map(int,input().split()) a map(int,input().split()) map int input().split() ().split () input split b cost G[a-1,b-1]=cost G[a-1,b-1] G a-1 a 1 cost G[b-1,a-1]=cost G[b-1,a-1] G b-1 b 1 cost G=shortest_path(G,method='FW') G shortest_path(G,method='FW') shortest_path G method='FW' method 'FW' for c in range(n):
    for l in range(n):
        if G[c][l]<=limit:
            G[c][l]=1
        else:
            G[c][l]=0 c range(n) range n for l in range(n):
        if G[c][l]<=limit:
            G[c][l]=1
        else:
            G[c][l]=0 l range(n) range n if G[c][l]<=limit:
            G[c][l]=1
        else:
            G[c][l]=0 G[c][l]<=limit G[c][l] [c] G c l limit G[c][l]=1 G[c][l] [c] G c l 1 G[c][l]=0 G[c][l] [c] G c l 0 G=shortest_path(G,method='FW') G shortest_path(G,method='FW') shortest_path G method='FW' method 'FW' q=int(input()) q int(input()) int input() input map(int,input().split())for i in range(q) for i in range(q) i range(q) range q for i in range(q) map(int,input().split()) map int input().split() ().split () input split Q=[map(int,input().split())for i in range(q)] Q [map(int,input().split())for i in range(q)] for a,b in Q:
    print(int(G[a-1][b-1])-1 if G[a-1][b-1]<10**18 else -1) a b Q print(int(G[a-1][b-1])-1 if G[a-1][b-1]<10**18 else -1) print int(G[a-1][b-1])-1 if G[a-1][b-1]<10**18 else -1 G[a-1][b-1]<10**18 G[a-1][b-1] [a-1] G a-1 a 1 b-1 b 1 10**18 10 18 int(G[a-1][b-1])-1 int(G[a-1][b-1]) int G[a-1][b-1] [a-1] G a-1 a 1 b-1 b 1 1 -1 cost=map(int,input().split()) map(int,input().split()) cost q=int(input()) int(input()) q limit=map(int,input().split()) map(int,input().split()) limit G=np.zeros((n,n),dtype=np.int64) np.zeros((n,n),dtype=np.int64) G G=shortest_path(G,method='FW') shortest_path(G,method='FW') G Q=[map(int,input().split())for i in range(q)] [map(int,input().split())for i in range(q)] Q m,limit=map(int,input().split()) map(int,input().split()) m n,m,limit=map(int,input().split()) map(int,input().split()) n G=shortest_path(G,method='FW') shortest_path(G,method='FW') G a,b,cost=map(int,input().split()) map(int,input().split()) a b,cost=map(int,input().split()) map(int,input().split()) b
import numpy as np
from scipy.sparse import lil_matrix, csr_matrix
from scipy.sparse.csgraph import shortest_path

n,m,limit=map(int,input().split())
G=np.zeros((n,n),dtype=np.int64)
for i in range(m):
    a,b,cost=map(int,input().split())
    G[a-1,b-1]=cost
    G[b-1,a-1]=cost
G=shortest_path(G,method='FW')
for c in range(n):
    for l in range(n):
        if G[c][l]<=limit:
            G[c][l]=1
        else:
            G[c][l]=0
G=shortest_path(G,method='FW')
q=int(input())
Q=[map(int,input().split())for i in range(q)]
for a,b in Q:
    print(int(G[a-1][b-1])-1 if G[a-1][b-1]<10**18 else -1)