n,m,l=map(int,input().split())
abcs=[list(map(int,input().split())) for _ in range(m)]
for i in range(m):
	abcs[i][0]-=1
	abcs[i][1]-=1
inf =1234567890123456
dist = [[inf for i in range(n)] for j in range(n)]
for i in range(n):
	dist[i][i] = 0

for i in range(m):
	a=abcs[i][0]
	b=abcs[i][1]
	c=abcs[i][2]
	dist[a][b] = dist[b][a] = c

for k in range(n):
	for i in range(n):
		for j in range(n):
			dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j])

ans = [[inf for i in range(n)] for j in range(n)]
for i in range(n):
	ans[i][i]=0
for i in range(n):
	for j in range(i+1,n):
		if dist[i][j]<=l:
			ans[i][j]=ans[j][i]=1
for k in range(n):
	for i in range(n):
		for j in range(n):
			ans[i][j] = min(ans[i][j],ans[i][k]+ans[k][j])


for _ in range(int(input())):
	f,t=map(int,input().split())
	f-=1
	t-=1
	print(ans[f][t]-1 if ans[f][t]!=inf else -1) n,m,l=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l list(map(int,input().split())) for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split abcs=[list(map(int,input().split())) for _ in range(m)] abcs [list(map(int,input().split())) for _ in range(m)] for i in range(m):
	abcs[i][0]-=1
	abcs[i][1]-=1 i range(m) range m abcs[i][0]-=1 abcs[i][0] [i] abcs i 0 1 abcs[i][1]-=1 abcs[i][1] [i] abcs i 1 1 inf =1234567890123456 inf 1234567890123456 [inf 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) [inf for i in range(n)] dist = [[inf for i in range(n)] for j in range(n)] dist [[inf for i in range(n)] for j in range(n)] for i in range(n):
	dist[i][i] = 0 i range(n) range n dist[i][i] = 0 dist[i][i] [i] dist i i 0 for i in range(m):
	a=abcs[i][0]
	b=abcs[i][1]
	c=abcs[i][2]
	dist[a][b] = dist[b][a] = c i range(m) range m a=abcs[i][0] a abcs[i][0] [i] abcs i 0 b=abcs[i][1] b abcs[i][1] [i] abcs i 1 c=abcs[i][2] c abcs[i][2] [i] abcs i 2 dist[a][b] = dist[b][a] = c dist[a][b] [a] dist a b c = dist[b][a] = c dist[b][a] [b] dist b a c for k in range(n):
	for i in range(n):
		for j in range(n):
			dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]) k range(n) range n for i in range(n):
		for j in range(n):
			dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]) i range(n) range n for j in range(n):
			dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]) j range(n) range n dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]) dist[i][j] [i] dist i j min(dist[i][j],dist[i][k]+dist[k][j]) min dist[i][j] [i] dist i j dist[i][k]+dist[k][j] dist[i][k] [i] dist i k dist[k][j] [k] dist k j [inf 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) [inf for i in range(n)] ans = [[inf for i in range(n)] for j in range(n)] ans [[inf for i in range(n)] for j in range(n)] for i in range(n):
	ans[i][i]=0 i range(n) range n ans[i][i]=0 ans[i][i] [i] ans i i 0 for i in range(n):
	for j in range(i+1,n):
		if dist[i][j]<=l:
			ans[i][j]=ans[j][i]=1 i range(n) range n for j in range(i+1,n):
		if dist[i][j]<=l:
			ans[i][j]=ans[j][i]=1 j range(i+1,n) range i+1 i 1 n if dist[i][j]<=l:
			ans[i][j]=ans[j][i]=1 dist[i][j]<=l dist[i][j] [i] dist i j l ans[i][j]=ans[j][i]=1 ans[i][j] [i] ans i j 1 =ans[j][i]=1 ans[j][i] [j] ans j i 1 for k in range(n):
	for i in range(n):
		for j in range(n):
			ans[i][j] = min(ans[i][j],ans[i][k]+ans[k][j]) k range(n) range n for i in range(n):
		for j in range(n):
			ans[i][j] = min(ans[i][j],ans[i][k]+ans[k][j]) i range(n) range n for j in range(n):
			ans[i][j] = min(ans[i][j],ans[i][k]+ans[k][j]) j range(n) range n ans[i][j] = min(ans[i][j],ans[i][k]+ans[k][j]) ans[i][j] [i] ans i j min(ans[i][j],ans[i][k]+ans[k][j]) min ans[i][j] [i] ans i j ans[i][k]+ans[k][j] ans[i][k] [i] ans i k ans[k][j] [k] ans k j for _ in range(int(input())):
	f,t=map(int,input().split())
	f-=1
	t-=1
	print(ans[f][t]-1 if ans[f][t]!=inf else -1) _ range(int(input())) range int(input()) int input() input f,t=map(int,input().split()) f map(int,input().split()) map int input().split() ().split () input split t f-=1 f 1 t-=1 t 1 print(ans[f][t]-1 if ans[f][t]!=inf else -1) print ans[f][t]-1 if ans[f][t]!=inf else -1 ans[f][t]!=inf ans[f][t] [f] ans f t inf ans[f][t]-1 ans[f][t] [f] ans f t 1 -1 m,l=map(int,input().split()) map(int,input().split()) m t=map(int,input().split()) map(int,input().split()) t f,t=map(int,input().split()) map(int,input().split()) f n,m,l=map(int,input().split()) map(int,input().split()) n abcs=[list(map(int,input().split())) for _ in range(m)] [list(map(int,input().split())) for _ in range(m)] abcs b=abcs[i][1] abcs[i][1] b c=abcs[i][2] abcs[i][2] c f-=1 1 f ans = [[inf for i in range(n)] for j in range(n)] [[inf for i in range(n)] for j in range(n)] ans t-=1 1 t a=abcs[i][0] abcs[i][0] a dist = [[inf for i in range(n)] for j in range(n)] [[inf for i in range(n)] for j in range(n)] dist l=map(int,input().split()) map(int,input().split()) l inf =1234567890123456 1234567890123456 inf
n,m,l=map(int,input().split())
abcs=[list(map(int,input().split())) for _ in range(m)]
for i in range(m):
	abcs[i][0]-=1
	abcs[i][1]-=1
inf =1234567890123456
dist = [[inf for i in range(n)] for j in range(n)]
for i in range(n):
	dist[i][i] = 0

for i in range(m):
	a=abcs[i][0]
	b=abcs[i][1]
	c=abcs[i][2]
	dist[a][b] = dist[b][a] = c

for k in range(n):
	for i in range(n):
		for j in range(n):
			dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j])

ans = [[inf for i in range(n)] for j in range(n)]
for i in range(n):
	ans[i][i]=0
for i in range(n):
	for j in range(i+1,n):
		if dist[i][j]<=l:
			ans[i][j]=ans[j][i]=1
for k in range(n):
	for i in range(n):
		for j in range(n):
			ans[i][j] = min(ans[i][j],ans[i][k]+ans[k][j])


for _ in range(int(input())):
	f,t=map(int,input().split())
	f-=1
	t-=1
	print(ans[f][t]-1 if ans[f][t]!=inf else -1)