import sys
input = sys.stdin.readline

N, M, L = (int(i) for i in input().split())

import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

graph = [[0]*N for i in range(N)]
for i in range(M):
    a, b, c = (int(i) for i in input().split())
    graph[a-1][b-1] = c
    graph[b-1][a-1] = c

graph = csr_matrix(graph)
d = floyd_warshall(csgraph=graph, directed=False)

new_graph = [[0]*N for i in range(N)]
for i in range(N):
    for j in range(N):
        if d[i][j] <= L:
            new_graph[i][j] = 1
            new_graph[j][i] = 1

graph = csr_matrix(new_graph)
d = floyd_warshall(csgraph=graph, directed=False)
Q = int(input())
for i in range(Q):
    s, t = (int(i) for i in input().split())
    if d[s-1][t-1] == float("inf"):
        print("-1")
    else:
        print(int(d[s-1][t-1]-1)) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i N, M, L = (int(i) for i in input().split()) N (int(i) for i in input().split()) M L import numpy as np numpy from scipy.sparse.csgraph import floyd_warshall from scipy.sparse import csr_matrix [0]*N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [0]*N [0] 0 N graph = [[0]*N for i in range(N)] graph [[0]*N for i in range(N)] for i in range(M):
    a, b, c = (int(i) for i in input().split())
    graph[a-1][b-1] = c
    graph[b-1][a-1] = c i range(M) range M int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i a, b, c = (int(i) for i in input().split()) a (int(i) for i in input().split()) b c graph[a-1][b-1] = c graph[a-1][b-1] [a-1] graph a-1 a 1 b-1 b 1 c graph[b-1][a-1] = c graph[b-1][a-1] [b-1] graph b-1 b 1 a-1 a 1 c graph = csr_matrix(graph) graph csr_matrix(graph) csr_matrix graph d = floyd_warshall(csgraph=graph, directed=False) d floyd_warshall(csgraph=graph, directed=False) floyd_warshall csgraph=graph csgraph graph directed=False directed False [0]*N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [0]*N [0] 0 N new_graph = [[0]*N for i in range(N)] new_graph [[0]*N for i in range(N)] for i in range(N):
    for j in range(N):
        if d[i][j] <= L:
            new_graph[i][j] = 1
            new_graph[j][i] = 1 i range(N) range N for j in range(N):
        if d[i][j] <= L:
            new_graph[i][j] = 1
            new_graph[j][i] = 1 j range(N) range N if d[i][j] <= L:
            new_graph[i][j] = 1
            new_graph[j][i] = 1 d[i][j] <= L d[i][j] [i] d i j L new_graph[i][j] = 1 new_graph[i][j] [i] new_graph i j 1 new_graph[j][i] = 1 new_graph[j][i] [j] new_graph j i 1 graph = csr_matrix(new_graph) graph csr_matrix(new_graph) csr_matrix new_graph d = floyd_warshall(csgraph=graph, directed=False) d floyd_warshall(csgraph=graph, directed=False) floyd_warshall csgraph=graph csgraph graph directed=False directed False Q = int(input()) Q int(input()) int input() input for i in range(Q):
    s, t = (int(i) for i in input().split())
    if d[s-1][t-1] == float("inf"):
        print("-1")
    else:
        print(int(d[s-1][t-1]-1)) i range(Q) range Q int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i s, t = (int(i) for i in input().split()) s (int(i) for i in input().split()) t if d[s-1][t-1] == float("inf"):
        print("-1")
    else:
        print(int(d[s-1][t-1]-1)) d[s-1][t-1] == float("inf") d[s-1][t-1] [s-1] d s-1 s 1 t-1 t 1 float("inf") float "inf" print("-1") print "-1" print(int(d[s-1][t-1]-1)) print int(d[s-1][t-1]-1) int d[s-1][t-1]-1 d[s-1][t-1] [s-1] d s-1 s 1 t-1 t 1 1 c = (int(i) for i in input().split()) (int(i) for i in input().split()) c graph = [[0]*N for i in range(N)] [[0]*N for i in range(N)] graph graph = csr_matrix(new_graph) csr_matrix(new_graph) graph s, t = (int(i) for i in input().split()) (int(i) for i in input().split()) s graph = csr_matrix(graph) csr_matrix(graph) graph M, L = (int(i) for i in input().split()) (int(i) for i in input().split()) M a, b, c = (int(i) for i in input().split()) (int(i) for i in input().split()) a input = sys.stdin.readline sys.stdin.readline input d = floyd_warshall(csgraph=graph, directed=False) floyd_warshall(csgraph=graph, directed=False) d t = (int(i) for i in input().split()) (int(i) for i in input().split()) t b, c = (int(i) for i in input().split()) (int(i) for i in input().split()) b N, M, L = (int(i) for i in input().split()) (int(i) for i in input().split()) N L = (int(i) for i in input().split()) (int(i) for i in input().split()) L new_graph = [[0]*N for i in range(N)] [[0]*N for i in range(N)] new_graph d = floyd_warshall(csgraph=graph, directed=False) floyd_warshall(csgraph=graph, directed=False) d Q = int(input()) int(input()) Q
import sys
input = sys.stdin.readline

N, M, L = (int(i) for i in input().split())

import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

graph = [[0]*N for i in range(N)]
for i in range(M):
    a, b, c = (int(i) for i in input().split())
    graph[a-1][b-1] = c
    graph[b-1][a-1] = c

graph = csr_matrix(graph)
d = floyd_warshall(csgraph=graph, directed=False)

new_graph = [[0]*N for i in range(N)]
for i in range(N):
    for j in range(N):
        if d[i][j] <= L:
            new_graph[i][j] = 1
            new_graph[j][i] = 1

graph = csr_matrix(new_graph)
d = floyd_warshall(csgraph=graph, directed=False)
Q = int(input())
for i in range(Q):
    s, t = (int(i) for i in input().split())
    if d[s-1][t-1] == float("inf"):
        print("-1")
    else:
        print(int(d[s-1][t-1]-1))