import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N,M,L = MI()
	to = [[] for _ in range(N)]
	dist = [[float("inf") for _ in range(N)] for _ in range(N)]

	def warshall_floyd(N):
		for mid in range(N):
			for s in range(N):
				for g in range(s+1,N):
					dist[s][g] = min(dist[s][g], dist[s][mid]+dist[mid][g])
					dist[g][s] = dist[s][g]


	for _ in range(M):
		a,b,c = MI()
		dist[a-1][b-1],dist[b-1][a-1]=c,c
	for i in range(N):
		dist[i][i] = 0

	warshall_floyd(N)

	for i in range(N):
		for j in range(i+1,N):
			if dist[i][j]<=L :
				dist[i][j],dist[j][i]=1,1
			else:
				dist[i][j],dist[j][i]=float("inf"),float("inf")

	warshall_floyd(N)

	Q = II()
	for _ in range(Q):
		s,t = MI()
		ans = dist[s-1][t-1]-1
		if(ans == float("inf")):
			print(-1)
		else:
			print(ans)

main() import sys sys sys.setrecursionlimit(10 ** 6) sys.setrecursionlimit sys setrecursionlimit 10 ** 6 10 6 int1 = lambda x: int(x) - 1 int1 lambda x: int(x) - 1 int(x) - 1 int(x) int x 1 x p2D = lambda x: print(*x, sep="\n") p2D lambda x: print(*x, sep="\n") print(*x, sep="\n") print *x x sep="\n" sep "\n" x def IS(): return sys.stdin.readline()[:-1] IS def II(): return int(sys.stdin.readline()) II def MI(): return map(int, sys.stdin.readline().split()) MI def LI(): return list(map(int, sys.stdin.readline().split())) LI def LI1(): return list(map(int1, sys.stdin.readline().split())) LI1 II() for _ in range(rows_number) for _ in range(rows_number) _ range(rows_number) range rows_number for _ in range(rows_number) II() II def LII(rows_number): return [II() for _ in range(rows_number)] LII rows_number rows_number LI() for _ in range(rows_number) for _ in range(rows_number) _ range(rows_number) range rows_number for _ in range(rows_number) LI() LI def LLI(rows_number): return [LI() for _ in range(rows_number)] LLI rows_number rows_number LI1() for _ in range(rows_number) for _ in range(rows_number) _ range(rows_number) range rows_number for _ in range(rows_number) LI1() LI1 def LLI1(rows_number): return [LI1() for _ in range(rows_number)] LLI1 rows_number rows_number def main():
	N,M,L = MI()
	to = [[] for _ in range(N)]
	dist = [[float("inf") for _ in range(N)] for _ in range(N)]

	def warshall_floyd(N):
		for mid in range(N):
			for s in range(N):
				for g in range(s+1,N):
					dist[s][g] = min(dist[s][g], dist[s][mid]+dist[mid][g])
					dist[g][s] = dist[s][g]


	for _ in range(M):
		a,b,c = MI()
		dist[a-1][b-1],dist[b-1][a-1]=c,c
	for i in range(N):
		dist[i][i] = 0

	warshall_floyd(N)

	for i in range(N):
		for j in range(i+1,N):
			if dist[i][j]<=L :
				dist[i][j],dist[j][i]=1,1
			else:
				dist[i][j],dist[j][i]=float("inf"),float("inf")

	warshall_floyd(N)

	Q = II()
	for _ in range(Q):
		s,t = MI()
		ans = dist[s-1][t-1]-1
		if(ans == float("inf")):
			print(-1)
		else:
			print(ans) main N,M,L = MI() N MI() MI M L [] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [] to = [[] for _ in range(N)] to [[] for _ in range(N)] [float("inf") for _ in range(N)] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [float("inf") for _ in range(N)] dist = [[float("inf") for _ in range(N)] for _ in range(N)] dist [[float("inf") for _ in range(N)] for _ in range(N)] def warshall_floyd(N):
		for mid in range(N):
			for s in range(N):
				for g in range(s+1,N):
					dist[s][g] = min(dist[s][g], dist[s][mid]+dist[mid][g])
					dist[g][s] = dist[s][g]


	 warshall_floyd for mid in range(N):
			for s in range(N):
				for g in range(s+1,N):
					dist[s][g] = min(dist[s][g], dist[s][mid]+dist[mid][g])
					dist[g][s] = dist[s][g]


	 mid range(N) range N for s in range(N):
				for g in range(s+1,N):
					dist[s][g] = min(dist[s][g], dist[s][mid]+dist[mid][g])
					dist[g][s] = dist[s][g]


	 s range(N) range N for g in range(s+1,N):
					dist[s][g] = min(dist[s][g], dist[s][mid]+dist[mid][g])
					dist[g][s] = dist[s][g]


	 g range(s+1,N) range s+1 s 1 N dist[s][g] = min(dist[s][g], dist[s][mid]+dist[mid][g]) dist[s][g] [s] dist s g min(dist[s][g], dist[s][mid]+dist[mid][g]) min dist[s][g] [s] dist s g dist[s][mid]+dist[mid][g] dist[s][mid] [s] dist s mid dist[mid][g] [mid] dist mid g dist[g][s] = dist[s][g] dist[g][s] [g] dist g s dist[s][g] [s] dist s g N N for _ in range(M):
		a,b,c = MI()
		dist[a-1][b-1],dist[b-1][a-1]=c,c
	 _ range(M) range M a,b,c = MI() a MI() MI b c dist[a-1][b-1],dist[b-1][a-1]=c,c dist[a-1][b-1] [a-1] dist a-1 a 1 b-1 b 1 c dist[b-1][a-1] [b-1] dist b-1 b 1 a-1 a 1 c 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 warshall_floyd(N) warshall_floyd N for i in range(N):
		for j in range(i+1,N):
			if dist[i][j]<=L :
				dist[i][j],dist[j][i]=1,1
			else:
				dist[i][j],dist[j][i]=float("inf"),float("inf")

	 i range(N) range N for j in range(i+1,N):
			if dist[i][j]<=L :
				dist[i][j],dist[j][i]=1,1
			else:
				dist[i][j],dist[j][i]=float("inf"),float("inf")

	 j range(i+1,N) range i+1 i 1 N if dist[i][j]<=L :
				dist[i][j],dist[j][i]=1,1
			else:
				dist[i][j],dist[j][i]=float("inf"),float("inf")

	 dist[i][j]<=L dist[i][j] [i] dist i j L dist[i][j],dist[j][i]=1,1 dist[i][j] [i] dist i j 1 dist[j][i] [j] dist j i 1 dist[i][j],dist[j][i]=float("inf"),float("inf") dist[i][j] [i] dist i j float("inf") float "inf" dist[j][i] [j] dist j i float("inf") float "inf" warshall_floyd(N) warshall_floyd N Q = II() Q II() II for _ in range(Q):
		s,t = MI()
		ans = dist[s-1][t-1]-1
		if(ans == float("inf")):
			print(-1)
		else:
			print(ans) _ range(Q) range Q s,t = MI() s MI() MI t ans = dist[s-1][t-1]-1 ans dist[s-1][t-1]-1 dist[s-1][t-1] [s-1] dist s-1 s 1 t-1 t 1 1 if(ans == float("inf")):
			print(-1)
		else:
			print(ans) ans == float("inf") ans float("inf") float "inf" print(-1) print -1 print(ans) print ans main() main def MI(): return map(int, sys.stdin.readline().split()) def MI(): return map(int, sys.stdin.readline().split()) MI def LII(rows_number): return [II() for _ in range(rows_number)] def LII(rows_number): return [II() for _ in range(rows_number)] LII def LI(): return list(map(int, sys.stdin.readline().split())) def LI(): return list(map(int, sys.stdin.readline().split())) LI def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI(rows_number): return [LI() for _ in range(rows_number)] LLI def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] LLI1 p2D = lambda x: print(*x, sep="\n") lambda x: print(*x, sep="\n") p2D def IS(): return sys.stdin.readline()[:-1] def IS(): return sys.stdin.readline()[:-1] IS def II(): return int(sys.stdin.readline()) def II(): return int(sys.stdin.readline()) II def main():
	N,M,L = MI()
	to = [[] for _ in range(N)]
	dist = [[float("inf") for _ in range(N)] for _ in range(N)]

	def warshall_floyd(N):
		for mid in range(N):
			for s in range(N):
				for g in range(s+1,N):
					dist[s][g] = min(dist[s][g], dist[s][mid]+dist[mid][g])
					dist[g][s] = dist[s][g]


	for _ in range(M):
		a,b,c = MI()
		dist[a-1][b-1],dist[b-1][a-1]=c,c
	for i in range(N):
		dist[i][i] = 0

	warshall_floyd(N)

	for i in range(N):
		for j in range(i+1,N):
			if dist[i][j]<=L :
				dist[i][j],dist[j][i]=1,1
			else:
				dist[i][j],dist[j][i]=float("inf"),float("inf")

	warshall_floyd(N)

	Q = II()
	for _ in range(Q):
		s,t = MI()
		ans = dist[s-1][t-1]-1
		if(ans == float("inf")):
			print(-1)
		else:
			print(ans) def main():
	N,M,L = MI()
	to = [[] for _ in range(N)]
	dist = [[float("inf") for _ in range(N)] for _ in range(N)]

	def warshall_floyd(N):
		for mid in range(N):
			for s in range(N):
				for g in range(s+1,N):
					dist[s][g] = min(dist[s][g], dist[s][mid]+dist[mid][g])
					dist[g][s] = dist[s][g]


	for _ in range(M):
		a,b,c = MI()
		dist[a-1][b-1],dist[b-1][a-1]=c,c
	for i in range(N):
		dist[i][i] = 0

	warshall_floyd(N)

	for i in range(N):
		for j in range(i+1,N):
			if dist[i][j]<=L :
				dist[i][j],dist[j][i]=1,1
			else:
				dist[i][j],dist[j][i]=float("inf"),float("inf")

	warshall_floyd(N)

	Q = II()
	for _ in range(Q):
		s,t = MI()
		ans = dist[s-1][t-1]-1
		if(ans == float("inf")):
			print(-1)
		else:
			print(ans) main int1 = lambda x: int(x) - 1 lambda x: int(x) - 1 int1 def LI1(): return list(map(int1, sys.stdin.readline().split())) def LI1(): return list(map(int1, sys.stdin.readline().split())) LI1
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N,M,L = MI()
	to = [[] for _ in range(N)]
	dist = [[float("inf") for _ in range(N)] for _ in range(N)]

	def warshall_floyd(N):
		for mid in range(N):
			for s in range(N):
				for g in range(s+1,N):
					dist[s][g] = min(dist[s][g], dist[s][mid]+dist[mid][g])
					dist[g][s] = dist[s][g]


	for _ in range(M):
		a,b,c = MI()
		dist[a-1][b-1],dist[b-1][a-1]=c,c
	for i in range(N):
		dist[i][i] = 0

	warshall_floyd(N)

	for i in range(N):
		for j in range(i+1,N):
			if dist[i][j]<=L :
				dist[i][j],dist[j][i]=1,1
			else:
				dist[i][j],dist[j][i]=float("inf"),float("inf")

	warshall_floyd(N)

	Q = II()
	for _ in range(Q):
		s,t = MI()
		ans = dist[s-1][t-1]-1
		if(ans == float("inf")):
			print(-1)
		else:
			print(ans)

main()