import sys

inp = sys.stdin
# inp = open("testdata.txt", "r")
def input():
	return inp.readline().strip()

	
n, m, l = map(int, input().split())

def warshall_floyd(d):
	for k in range(n):
		for i in range(n):
			for j in range(n):
				d[i][j] = min(d[i][j],d[i][k] + d[k][j])
	return d

adjl = [[float('inf') for j in range(n)] for i in range(n)]
for i in range(n):
	adjl[i][i] = 0

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

adjl = warshall_floyd(adjl)

for i in range(n):
	for j in range(n):
		if i==j: adjl[i][j] = 0
		else: adjl[i][j] = 1 if adjl[i][j] <= l else float("inf")

adjl = warshall_floyd(adjl)

q = int(input())

for _ in range(q):
	a, b = map(int, input().split())
	ans = adjl[a-1][b-1]
	print(-1 if ans==float("inf") else ans-1) import sys sys inp = sys.stdin inp sys.stdin sys stdin def input():
	return inp.readline().strip()

	 input return inp.readline().strip() inp.readline().strip() inp.readline().strip inp.readline() inp.readline inp readline strip n, m, l = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m l def warshall_floyd(d):
	for k in range(n):
		for i in range(n):
			for j in range(n):
				d[i][j] = min(d[i][j],d[i][k] + d[k][j])
	return d warshall_floyd for k in range(n):
		for i in range(n):
			for j in range(n):
				d[i][j] = min(d[i][j],d[i][k] + d[k][j])
	 k range(n) range n for i in range(n):
			for j in range(n):
				d[i][j] = min(d[i][j],d[i][k] + d[k][j])
	 i range(n) range n for j in range(n):
				d[i][j] = min(d[i][j],d[i][k] + d[k][j])
	 j range(n) range n d[i][j] = min(d[i][j],d[i][k] + d[k][j]) d[i][j] [i] d i j min(d[i][j],d[i][k] + d[k][j]) min d[i][j] [i] d i j d[i][k] + d[k][j] d[i][k] [i] d i k d[k][j] [k] d k j return d d d d [float('inf') for j in range(n)] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [float('inf') for j in range(n)] adjl = [[float('inf') for j in range(n)] for i in range(n)] adjl [[float('inf') for j in range(n)] for i in range(n)] for i in range(n):
	adjl[i][i] = 0 i range(n) range n adjl[i][i] = 0 adjl[i][i] [i] adjl i i 0 for _ in range(m):
	a, b, c = map(int, input().split())
	adjl[a-1][b-1] = c
	adjl[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 adjl[a-1][b-1] = c adjl[a-1][b-1] [a-1] adjl a-1 a 1 b-1 b 1 c adjl[b-1][a-1] = c adjl[b-1][a-1] [b-1] adjl b-1 b 1 a-1 a 1 c adjl = warshall_floyd(adjl) adjl warshall_floyd(adjl) warshall_floyd adjl for i in range(n):
	for j in range(n):
		if i==j: adjl[i][j] = 0
		else: adjl[i][j] = 1 if adjl[i][j] <= l else float("inf") i range(n) range n for j in range(n):
		if i==j: adjl[i][j] = 0
		else: adjl[i][j] = 1 if adjl[i][j] <= l else float("inf") j range(n) range n if i==j: adjl[i][j] = 0
		else: adjl[i][j] = 1 if adjl[i][j] <= l else float("inf") i==j i j adjl = warshall_floyd(adjl) adjl warshall_floyd(adjl) warshall_floyd adjl q = int(input()) q int(input()) int input() input for _ in range(q):
	a, b = map(int, input().split())
	ans = adjl[a-1][b-1]
	print(-1 if ans==float("inf") else ans-1) _ range(q) range q a, b = map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b ans = adjl[a-1][b-1] ans adjl[a-1][b-1] [a-1] adjl a-1 a 1 b-1 b 1 print(-1 if ans==float("inf") else ans-1) print -1 if ans==float("inf") else ans-1 ans==float("inf") ans float("inf") float "inf" -1 ans-1 ans 1 m, l = map(int, input().split()) map(int, input().split()) m l = map(int, input().split()) map(int, input().split()) l a, b, c = map(int, input().split()) map(int, input().split()) a b, c = map(int, input().split()) map(int, input().split()) b a, b = map(int, input().split()) map(int, input().split()) a adjl = [[float('inf') for j in range(n)] for i in range(n)] [[float('inf') for j in range(n)] for i in range(n)] adjl adjl = warshall_floyd(adjl) warshall_floyd(adjl) adjl q = int(input()) int(input()) q c = map(int, input().split()) map(int, input().split()) c n, m, l = map(int, input().split()) map(int, input().split()) n inp = sys.stdin sys.stdin inp def input():
	return inp.readline().strip()

	 def input():
	return inp.readline().strip()

	 input adjl = warshall_floyd(adjl) warshall_floyd(adjl) adjl b = map(int, input().split()) map(int, input().split()) b def warshall_floyd(d):
	for k in range(n):
		for i in range(n):
			for j in range(n):
				d[i][j] = min(d[i][j],d[i][k] + d[k][j])
	return d def warshall_floyd(d):
	for k in range(n):
		for i in range(n):
			for j in range(n):
				d[i][j] = min(d[i][j],d[i][k] + d[k][j])
	return d warshall_floyd ans = adjl[a-1][b-1] adjl[a-1][b-1] ans
import sys

inp = sys.stdin
# inp = open("testdata.txt", "r")
def input():
	return inp.readline().strip()

	
n, m, l = map(int, input().split())

def warshall_floyd(d):
	for k in range(n):
		for i in range(n):
			for j in range(n):
				d[i][j] = min(d[i][j],d[i][k] + d[k][j])
	return d

adjl = [[float('inf') for j in range(n)] for i in range(n)]
for i in range(n):
	adjl[i][i] = 0

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

adjl = warshall_floyd(adjl)

for i in range(n):
	for j in range(n):
		if i==j: adjl[i][j] = 0
		else: adjl[i][j] = 1 if adjl[i][j] <= l else float("inf")

adjl = warshall_floyd(adjl)

q = int(input())

for _ in range(q):
	a, b = map(int, input().split())
	ans = adjl[a-1][b-1]
	print(-1 if ans==float("inf") else ans-1)