#!/usr/bin/python3
# -*- coding: utf-8 -*-

# scipy version

import sys
from collections import deque
from array import array

from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

def input():
    return sys.stdin.readline().rstrip('\n')

##### main

N,M,L = list(map(int, input().split()))

C = [[0]*N for _ in range(N)]

for i in range(M):
    a,b,c = list(map(int, input().split()))
    if c>L:
        continue
    C[a-1][b-1] = c

Q = int(input())

ST = [None]*Q

for i in range(Q):
    s, t = list(map(int, input().split()))
    ST[i] = (s-1,t-1)

dist_matrix, predecessors = floyd_warshall(csgraph=C, directed=False, return_predecessors=True)

# D[i][j] <= L となる i,j に辺を張る
for i in range(N):
    for j in range(i+1,N):
        if dist_matrix[i][j] <= L:
            C[i][j] = 1

dist_matrix, predecessors = floyd_warshall(csgraph=C, directed=False, return_predecessors=True)

# answer
for q in range(Q):
    i,j = ST[q]
    step = dist_matrix[i][j]
    if step > 10**9:
        print(-1)
    else:
        print(int(step-1)) import sys sys from collections import deque from array import array from scipy.sparse import csr_matrix from scipy.sparse.csgraph import floyd_warshall def input():
    return sys.stdin.readline().rstrip('\n')

##### main input return sys.stdin.readline().rstrip('\n') sys.stdin.readline().rstrip('\n') sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip '\n' 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 [0]*N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [0]*N [0] 0 N C = [[0]*N for _ in range(N)] C [[0]*N for _ in range(N)] for i in range(M):
    a,b,c = list(map(int, input().split()))
    if c>L:
        continue
    C[a-1][b-1] = c i range(M) range M a,b,c = list(map(int, input().split())) a list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split b c if c>L:
        continue
     c>L c L continue C[a-1][b-1] = c C[a-1][b-1] [a-1] C a-1 a 1 b-1 b 1 c Q = int(input()) Q int(input()) int input() input ST = [None]*Q ST [None]*Q [None] None Q for i in range(Q):
    s, t = list(map(int, input().split()))
    ST[i] = (s-1,t-1) i range(Q) range Q s, t = list(map(int, input().split())) s list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split t ST[i] = (s-1,t-1) ST[i] ST i (s-1,t-1) s-1 s 1 t-1 t 1 dist_matrix, predecessors = floyd_warshall(csgraph=C, directed=False, return_predecessors=True) dist_matrix floyd_warshall(csgraph=C, directed=False, return_predecessors=True) floyd_warshall csgraph=C csgraph C directed=False directed False return_predecessors=True return_predecessors True predecessors for i in range(N):
    for j in range(i+1,N):
        if dist_matrix[i][j] <= L:
            C[i][j] = 1 i range(N) range N for j in range(i+1,N):
        if dist_matrix[i][j] <= L:
            C[i][j] = 1 j range(i+1,N) range i+1 i 1 N if dist_matrix[i][j] <= L:
            C[i][j] = 1 dist_matrix[i][j] <= L dist_matrix[i][j] [i] dist_matrix i j L C[i][j] = 1 C[i][j] [i] C i j 1 dist_matrix, predecessors = floyd_warshall(csgraph=C, directed=False, return_predecessors=True) dist_matrix floyd_warshall(csgraph=C, directed=False, return_predecessors=True) floyd_warshall csgraph=C csgraph C directed=False directed False return_predecessors=True return_predecessors True predecessors for q in range(Q):
    i,j = ST[q]
    step = dist_matrix[i][j]
    if step > 10**9:
        print(-1)
    else:
        print(int(step-1)) q range(Q) range Q i,j = ST[q] i ST[q] ST q j step = dist_matrix[i][j] step dist_matrix[i][j] [i] dist_matrix i j if step > 10**9:
        print(-1)
    else:
        print(int(step-1)) step > 10**9 step 10**9 10 9 print(-1) print -1 print(int(step-1)) print int(step-1) int step-1 step 1 def input():
    return sys.stdin.readline().rstrip('\n')

##### main def input():
    return sys.stdin.readline().rstrip('\n')

##### main input dist_matrix, predecessors = floyd_warshall(csgraph=C, directed=False, return_predecessors=True) floyd_warshall(csgraph=C, directed=False, return_predecessors=True) dist_matrix predecessors = floyd_warshall(csgraph=C, directed=False, return_predecessors=True) floyd_warshall(csgraph=C, directed=False, return_predecessors=True) predecessors step = dist_matrix[i][j] dist_matrix[i][j] step N,M,L = list(map(int, input().split())) list(map(int, input().split())) N t = list(map(int, input().split())) list(map(int, input().split())) t M,L = list(map(int, input().split())) list(map(int, input().split())) M dist_matrix, predecessors = floyd_warshall(csgraph=C, directed=False, return_predecessors=True) floyd_warshall(csgraph=C, directed=False, return_predecessors=True) dist_matrix j = ST[q] ST[q] j C = [[0]*N for _ in range(N)] [[0]*N for _ in range(N)] C ST = [None]*Q [None]*Q ST s, t = list(map(int, input().split())) list(map(int, input().split())) s predecessors = floyd_warshall(csgraph=C, directed=False, return_predecessors=True) floyd_warshall(csgraph=C, directed=False, return_predecessors=True) predecessors L = list(map(int, input().split())) list(map(int, input().split())) L b,c = list(map(int, input().split())) list(map(int, input().split())) b c = list(map(int, input().split())) list(map(int, input().split())) c Q = int(input()) int(input()) Q a,b,c = list(map(int, input().split())) list(map(int, input().split())) a i,j = ST[q] ST[q] i
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# scipy version

import sys
from collections import deque
from array import array

from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

def input():
    return sys.stdin.readline().rstrip('\n')

##### main

N,M,L = list(map(int, input().split()))

C = [[0]*N for _ in range(N)]

for i in range(M):
    a,b,c = list(map(int, input().split()))
    if c>L:
        continue
    C[a-1][b-1] = c

Q = int(input())

ST = [None]*Q

for i in range(Q):
    s, t = list(map(int, input().split()))
    ST[i] = (s-1,t-1)

dist_matrix, predecessors = floyd_warshall(csgraph=C, directed=False, return_predecessors=True)

# D[i][j] <= L となる i,j に辺を張る
for i in range(N):
    for j in range(i+1,N):
        if dist_matrix[i][j] <= L:
            C[i][j] = 1

dist_matrix, predecessors = floyd_warshall(csgraph=C, directed=False, return_predecessors=True)

# answer
for q in range(Q):
    i,j = ST[q]
    step = dist_matrix[i][j]
    if step > 10**9:
        print(-1)
    else:
        print(int(step-1))
