import sys
import numpy as np
from scipy.sparse import*
F = csgraph.floyd_warshall
CSR = csr_matrix
input = sys.stdin.readline

n,m,l = map(int,input().split())
cost = [[0]*n for i in range(n)]
for i in range(m):
  a,b,c = map(int,input().split())
  cost[a-1][b-1] = c
  cost[b-1][a-1] = c  

Cost = F(CSR(cost))
Cost = F(CSR(np.where((0<Cost)&(Cost<=l),1,0)))

q = int(input())
for i in range(q):
  s,t = map(int,input().split())
  print(-1 if np.isinf(Cost[s-1][t-1]) else int(Cost[s-1][t-1])-1) import sys sys import numpy as np numpy from scipy.sparse import* F = csgraph.floyd_warshall F csgraph.floyd_warshall csgraph floyd_warshall CSR = csr_matrix CSR csr_matrix input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline n,m,l = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l [0]*n for i in range(n) for i in range(n) i range(n) range n for i in range(n) [0]*n [0] 0 n cost = [[0]*n for i in range(n)] cost [[0]*n for i in range(n)] for i in range(m):
  a,b,c = map(int,input().split())
  cost[a-1][b-1] = c
  cost[b-1][a-1] = c   i range(m) range m a,b,c = map(int,input().split()) a map(int,input().split()) map int input().split() ().split () input split b c cost[a-1][b-1] = c cost[a-1][b-1] [a-1] cost a-1 a 1 b-1 b 1 c cost[b-1][a-1] = c cost[b-1][a-1] [b-1] cost b-1 b 1 a-1 a 1 c Cost = F(CSR(cost)) Cost F(CSR(cost)) F CSR(cost) CSR cost Cost = F(CSR(np.where((0<Cost)&(Cost<=l),1,0))) Cost F(CSR(np.where((0<Cost)&(Cost<=l),1,0))) F CSR(np.where((0<Cost)&(Cost<=l),1,0)) CSR np.where((0<Cost)&(Cost<=l),1,0) np.where np where (0<Cost)&(Cost<=l) 0<Cost 0 Cost Cost<=l Cost l 1 0 q = int(input()) q int(input()) int input() input for i in range(q):
  s,t = map(int,input().split())
  print(-1 if np.isinf(Cost[s-1][t-1]) else int(Cost[s-1][t-1])-1) i range(q) range q s,t = map(int,input().split()) s map(int,input().split()) map int input().split() ().split () input split t print(-1 if np.isinf(Cost[s-1][t-1]) else int(Cost[s-1][t-1])-1) print -1 if np.isinf(Cost[s-1][t-1]) else int(Cost[s-1][t-1])-1 np.isinf(Cost[s-1][t-1]) np.isinf np isinf Cost[s-1][t-1] [s-1] Cost s-1 s 1 t-1 t 1 -1 int(Cost[s-1][t-1])-1 int(Cost[s-1][t-1]) int Cost[s-1][t-1] [s-1] Cost s-1 s 1 t-1 t 1 1 b,c = map(int,input().split()) map(int,input().split()) b s,t = map(int,input().split()) map(int,input().split()) s CSR = csr_matrix csr_matrix CSR Cost = F(CSR(cost)) F(CSR(cost)) Cost c = map(int,input().split()) map(int,input().split()) c m,l = map(int,input().split()) map(int,input().split()) m F = csgraph.floyd_warshall csgraph.floyd_warshall F t = map(int,input().split()) map(int,input().split()) t Cost = F(CSR(np.where((0<Cost)&(Cost<=l),1,0))) F(CSR(np.where((0<Cost)&(Cost<=l),1,0))) Cost l = map(int,input().split()) map(int,input().split()) l n,m,l = map(int,input().split()) map(int,input().split()) n a,b,c = map(int,input().split()) map(int,input().split()) a cost = [[0]*n for i in range(n)] [[0]*n for i in range(n)] cost input = sys.stdin.readline sys.stdin.readline input q = int(input()) int(input()) q
import sys
import numpy as np
from scipy.sparse import*
F = csgraph.floyd_warshall
CSR = csr_matrix
input = sys.stdin.readline

n,m,l = map(int,input().split())
cost = [[0]*n for i in range(n)]
for i in range(m):
  a,b,c = map(int,input().split())
  cost[a-1][b-1] = c
  cost[b-1][a-1] = c  

Cost = F(CSR(cost))
Cost = F(CSR(np.where((0<Cost)&(Cost<=l),1,0)))

q = int(input())
for i in range(q):
  s,t = map(int,input().split())
  print(-1 if np.isinf(Cost[s-1][t-1]) else int(Cost[s-1][t-1])-1)