import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
import sys
def input():
	return sys.stdin.readline()[:-1]

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

fw = floyd_warshall(csr_matrix(dist))

num = [[0 for _ in range(n)] for _ in range(n)]
for i in range(n):
	for j in range(n):
		if fw[i][j] <= l:
			num[i][j] = 1

ans = floyd_warshall(csr_matrix(num))

q = int(input())
for _ in range(q):
	s, t = map(int, input().split())
	if ans[s-1][t-1] > n:
		print(-1)
	else:
		print(int(ans[s-1][t-1])-1) import numpy as np numpy from scipy.sparse import csr_matrix from scipy.sparse.csgraph import floyd_warshall import sys sys def input():
	return sys.stdin.readline()[:-1] input return sys.stdin.readline()[:-1] sys.stdin.readline()[:-1] sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline :-1 -1 n, m, l = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m l [0 for _ in range(n)] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [0 for _ in range(n)] dist = [[0 for _ in range(n)] for _ in range(n)] dist [[0 for _ in range(n)] for _ in range(n)] for _ in range(m):
	a, b, c = map(int, input().split())
	dist[a-1][b-1] = c
	dist[b-1][a-1] = c _ 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 dist[a-1][b-1] = c dist[a-1][b-1] [a-1] dist a-1 a 1 b-1 b 1 c dist[b-1][a-1] = c dist[b-1][a-1] [b-1] dist b-1 b 1 a-1 a 1 c fw = floyd_warshall(csr_matrix(dist)) fw floyd_warshall(csr_matrix(dist)) floyd_warshall csr_matrix(dist) csr_matrix dist [0 for _ in range(n)] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [0 for _ in range(n)] num = [[0 for _ in range(n)] for _ in range(n)] num [[0 for _ in range(n)] for _ in range(n)] for i in range(n):
	for j in range(n):
		if fw[i][j] <= l:
			num[i][j] = 1 i range(n) range n for j in range(n):
		if fw[i][j] <= l:
			num[i][j] = 1 j range(n) range n if fw[i][j] <= l:
			num[i][j] = 1 fw[i][j] <= l fw[i][j] [i] fw i j l num[i][j] = 1 num[i][j] [i] num i j 1 ans = floyd_warshall(csr_matrix(num)) ans floyd_warshall(csr_matrix(num)) floyd_warshall csr_matrix(num) csr_matrix num q = int(input()) q int(input()) int input() input for _ in range(q):
	s, t = map(int, input().split())
	if ans[s-1][t-1] > n:
		print(-1)
	else:
		print(int(ans[s-1][t-1])-1) _ range(q) range q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t if ans[s-1][t-1] > n:
		print(-1)
	else:
		print(int(ans[s-1][t-1])-1) ans[s-1][t-1] > n ans[s-1][t-1] [s-1] ans s-1 s 1 t-1 t 1 n print(-1) print -1 print(int(ans[s-1][t-1])-1) print int(ans[s-1][t-1])-1 int(ans[s-1][t-1]) int ans[s-1][t-1] [s-1] ans s-1 s 1 t-1 t 1 1 a, b, c = map(int, input().split()) map(int, input().split()) a def input():
	return sys.stdin.readline()[:-1] def input():
	return sys.stdin.readline()[:-1] input q = int(input()) int(input()) q b, c = map(int, input().split()) map(int, input().split()) b s, t = map(int, input().split()) map(int, input().split()) s l = map(int, input().split()) map(int, input().split()) l t = map(int, input().split()) map(int, input().split()) t m, l = map(int, input().split()) map(int, input().split()) m num = [[0 for _ in range(n)] for _ in range(n)] [[0 for _ in range(n)] for _ in range(n)] num ans = floyd_warshall(csr_matrix(num)) floyd_warshall(csr_matrix(num)) ans n, m, l = map(int, input().split()) map(int, input().split()) n fw = floyd_warshall(csr_matrix(dist)) floyd_warshall(csr_matrix(dist)) fw c = map(int, input().split()) map(int, input().split()) c dist = [[0 for _ in range(n)] for _ in range(n)] [[0 for _ in range(n)] for _ in range(n)] dist
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
import sys
def input():
	return sys.stdin.readline()[:-1]

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

fw = floyd_warshall(csr_matrix(dist))

num = [[0 for _ in range(n)] for _ in range(n)]
for i in range(n):
	for j in range(n):
		if fw[i][j] <= l:
			num[i][j] = 1

ans = floyd_warshall(csr_matrix(num))

q = int(input())
for _ in range(q):
	s, t = map(int, input().split())
	if ans[s-1][t-1] > n:
		print(-1)
	else:
		print(int(ans[s-1][t-1])-1)