import sys

input = sys.stdin.readline
N, M, L = list(map(int,input().split()))
P = [list(map(int,input().split())) for i in range(M)]
Q = int(input())
st = [list(map(int,input().split())) for i in range(Q)]

INF = 100100100100100

dp = [[INF]*N for i in range(N)]
for s,e,d in P:
	if d<=L:
		dp[s-1][e-1] = d
		dp[e-1][s-1] = d
for i in range(N):
	dp[i][i] = 0

for k in range(N):
	for y in range(N):
		for x in range(N):
			dp[y][x] = min(dp[y][x], dp[y][k]+dp[k][x])

dp2 = [[INF]*N for i in range(N)]
for y in range(N):
	for x in range(N):
		if dp[y][x]<=L:
			dp2[y][x] = 1

for k in range(N):
	for y in range(N):
		for x in range(N):
			dp2[y][x] = min(dp2[y][x], dp2[y][k]+dp2[k][x])

for s, t in st:
	count = dp2[s-1][t-1]
	if count==INF:
		print(-1)
	else:
		print(count-1) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline N, M, L = list(map(int,input().split())) N list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split M L list(map(int,input().split())) for i in range(M) for i in range(M) i range(M) range M for i in range(M) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split P = [list(map(int,input().split())) for i in range(M)] P [list(map(int,input().split())) for i in range(M)] Q = int(input()) Q int(input()) int input() input list(map(int,input().split())) for i in range(Q) for i in range(Q) i range(Q) range Q for i in range(Q) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split st = [list(map(int,input().split())) for i in range(Q)] st [list(map(int,input().split())) for i in range(Q)] INF = 100100100100100 INF 100100100100100 [INF]*N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [INF]*N [INF] INF N dp = [[INF]*N for i in range(N)] dp [[INF]*N for i in range(N)] for s,e,d in P:
	if d<=L:
		dp[s-1][e-1] = d
		dp[e-1][s-1] = d s e d P if d<=L:
		dp[s-1][e-1] = d
		dp[e-1][s-1] = d d<=L d L dp[s-1][e-1] = d dp[s-1][e-1] [s-1] dp s-1 s 1 e-1 e 1 d dp[e-1][s-1] = d dp[e-1][s-1] [e-1] dp e-1 e 1 s-1 s 1 d for i in range(N):
	dp[i][i] = 0 i range(N) range N dp[i][i] = 0 dp[i][i] [i] dp i i 0 for k in range(N):
	for y in range(N):
		for x in range(N):
			dp[y][x] = min(dp[y][x], dp[y][k]+dp[k][x]) k range(N) range N for y in range(N):
		for x in range(N):
			dp[y][x] = min(dp[y][x], dp[y][k]+dp[k][x]) y range(N) range N for x in range(N):
			dp[y][x] = min(dp[y][x], dp[y][k]+dp[k][x]) x range(N) range N dp[y][x] = min(dp[y][x], dp[y][k]+dp[k][x]) dp[y][x] [y] dp y x min(dp[y][x], dp[y][k]+dp[k][x]) min dp[y][x] [y] dp y x dp[y][k]+dp[k][x] dp[y][k] [y] dp y k dp[k][x] [k] dp k x [INF]*N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [INF]*N [INF] INF N dp2 = [[INF]*N for i in range(N)] dp2 [[INF]*N for i in range(N)] for y in range(N):
	for x in range(N):
		if dp[y][x]<=L:
			dp2[y][x] = 1 y range(N) range N for x in range(N):
		if dp[y][x]<=L:
			dp2[y][x] = 1 x range(N) range N if dp[y][x]<=L:
			dp2[y][x] = 1 dp[y][x]<=L dp[y][x] [y] dp y x L dp2[y][x] = 1 dp2[y][x] [y] dp2 y x 1 for k in range(N):
	for y in range(N):
		for x in range(N):
			dp2[y][x] = min(dp2[y][x], dp2[y][k]+dp2[k][x]) k range(N) range N for y in range(N):
		for x in range(N):
			dp2[y][x] = min(dp2[y][x], dp2[y][k]+dp2[k][x]) y range(N) range N for x in range(N):
			dp2[y][x] = min(dp2[y][x], dp2[y][k]+dp2[k][x]) x range(N) range N dp2[y][x] = min(dp2[y][x], dp2[y][k]+dp2[k][x]) dp2[y][x] [y] dp2 y x min(dp2[y][x], dp2[y][k]+dp2[k][x]) min dp2[y][x] [y] dp2 y x dp2[y][k]+dp2[k][x] dp2[y][k] [y] dp2 y k dp2[k][x] [k] dp2 k x for s, t in st:
	count = dp2[s-1][t-1]
	if count==INF:
		print(-1)
	else:
		print(count-1) s t st count = dp2[s-1][t-1] count dp2[s-1][t-1] [s-1] dp2 s-1 s 1 t-1 t 1 if count==INF:
		print(-1)
	else:
		print(count-1) count==INF count INF print(-1) print -1 print(count-1) print count-1 count 1 L = list(map(int,input().split())) list(map(int,input().split())) L dp = [[INF]*N for i in range(N)] [[INF]*N for i in range(N)] dp input = sys.stdin.readline sys.stdin.readline input count = dp2[s-1][t-1] dp2[s-1][t-1] count N, M, L = list(map(int,input().split())) list(map(int,input().split())) N Q = int(input()) int(input()) Q st = [list(map(int,input().split())) for i in range(Q)] [list(map(int,input().split())) for i in range(Q)] st INF = 100100100100100 100100100100100 INF M, L = list(map(int,input().split())) list(map(int,input().split())) M P = [list(map(int,input().split())) for i in range(M)] [list(map(int,input().split())) for i in range(M)] P dp2 = [[INF]*N for i in range(N)] [[INF]*N for i in range(N)] dp2
import sys

input = sys.stdin.readline
N, M, L = list(map(int,input().split()))
P = [list(map(int,input().split())) for i in range(M)]
Q = int(input())
st = [list(map(int,input().split())) for i in range(Q)]

INF = 100100100100100

dp = [[INF]*N for i in range(N)]
for s,e,d in P:
	if d<=L:
		dp[s-1][e-1] = d
		dp[e-1][s-1] = d
for i in range(N):
	dp[i][i] = 0

for k in range(N):
	for y in range(N):
		for x in range(N):
			dp[y][x] = min(dp[y][x], dp[y][k]+dp[k][x])

dp2 = [[INF]*N for i in range(N)]
for y in range(N):
	for x in range(N):
		if dp[y][x]<=L:
			dp2[y][x] = 1

for k in range(N):
	for y in range(N):
		for x in range(N):
			dp2[y][x] = min(dp2[y][x], dp2[y][k]+dp2[k][x])

for s, t in st:
	count = dp2[s-1][t-1]
	if count==INF:
		print(-1)
	else:
		print(count-1)