import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

n, m, l = map(int, readline().split())
graph = [[0] * n for _ in range(n)]
inf = float('inf')
for i in range(m):
    a, b, c = map(int, readline().split())
    graph[a - 1][b - 1] = c
    graph[b - 1][a - 1] = c
cost = floyd_warshall(csr_matrix(graph))
cnt = [[0] * n for _ in range(n)]
for i, cost_i in enumerate(cost):
    for j, v in enumerate(cost_i):
        if l >= v:
            cnt[i][j] = 1
cnt = floyd_warshall(csr_matrix(cnt))
q = int(readline())
for _ in range(q):
    s, t = map(int, readline().split())
    if cnt[s - 1][t - 1] == inf:
        print(-1)
    else:
        print(int(cnt[s - 1][t - 1] - 1)) import sys sys read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline readlines = sys.stdin.buffer.readlines readlines sys.stdin.buffer.readlines sys.stdin.buffer sys.stdin sys stdin buffer readlines sys.setrecursionlimit(10 ** 7) sys.setrecursionlimit sys setrecursionlimit 10 ** 7 10 7 from scipy.sparse import csr_matrix from scipy.sparse.csgraph import floyd_warshall n, m, l = map(int, readline().split()) n map(int, readline().split()) map int readline().split() ().split () readline 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 graph = [[0] * n for _ in range(n)] graph [[0] * n for _ in range(n)] inf = float('inf') inf float('inf') float 'inf' for i in range(m):
    a, b, c = map(int, readline().split())
    graph[a - 1][b - 1] = c
    graph[b - 1][a - 1] = c i range(m) range m a, b, c = map(int, readline().split()) a map(int, readline().split()) map int readline().split() ().split () readline 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 cost = floyd_warshall(csr_matrix(graph)) cost floyd_warshall(csr_matrix(graph)) floyd_warshall csr_matrix(graph) csr_matrix graph [0] * n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [0] * n [0] 0 n cnt = [[0] * n for _ in range(n)] cnt [[0] * n for _ in range(n)] for i, cost_i in enumerate(cost):
    for j, v in enumerate(cost_i):
        if l >= v:
            cnt[i][j] = 1 i cost_i enumerate(cost) enumerate cost for j, v in enumerate(cost_i):
        if l >= v:
            cnt[i][j] = 1 j v enumerate(cost_i) enumerate cost_i if l >= v:
            cnt[i][j] = 1 l >= v l v cnt[i][j] = 1 cnt[i][j] [i] cnt i j 1 cnt = floyd_warshall(csr_matrix(cnt)) cnt floyd_warshall(csr_matrix(cnt)) floyd_warshall csr_matrix(cnt) csr_matrix cnt q = int(readline()) q int(readline()) int readline() readline for _ in range(q):
    s, t = map(int, readline().split())
    if cnt[s - 1][t - 1] == inf:
        print(-1)
    else:
        print(int(cnt[s - 1][t - 1] - 1)) _ range(q) range q s, t = map(int, readline().split()) s map(int, readline().split()) map int readline().split() ().split () readline split t if cnt[s - 1][t - 1] == inf:
        print(-1)
    else:
        print(int(cnt[s - 1][t - 1] - 1)) cnt[s - 1][t - 1] == inf cnt[s - 1][t - 1] [s - 1] cnt s - 1 s 1 t - 1 t 1 inf print(-1) print -1 print(int(cnt[s - 1][t - 1] - 1)) print int(cnt[s - 1][t - 1] - 1) int cnt[s - 1][t - 1] - 1 cnt[s - 1][t - 1] [s - 1] cnt s - 1 s 1 t - 1 t 1 1 a, b, c = map(int, readline().split()) map(int, readline().split()) a inf = float('inf') float('inf') inf cost = floyd_warshall(csr_matrix(graph)) floyd_warshall(csr_matrix(graph)) cost readlines = sys.stdin.buffer.readlines sys.stdin.buffer.readlines readlines t = map(int, readline().split()) map(int, readline().split()) t read = sys.stdin.buffer.read sys.stdin.buffer.read read m, l = map(int, readline().split()) map(int, readline().split()) m cnt = [[0] * n for _ in range(n)] [[0] * n for _ in range(n)] cnt c = map(int, readline().split()) map(int, readline().split()) c readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline cnt = floyd_warshall(csr_matrix(cnt)) floyd_warshall(csr_matrix(cnt)) cnt graph = [[0] * n for _ in range(n)] [[0] * n for _ in range(n)] graph b, c = map(int, readline().split()) map(int, readline().split()) b q = int(readline()) int(readline()) q l = map(int, readline().split()) map(int, readline().split()) l n, m, l = map(int, readline().split()) map(int, readline().split()) n s, t = map(int, readline().split()) map(int, readline().split()) s
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

n, m, l = map(int, readline().split())
graph = [[0] * n for _ in range(n)]
inf = float('inf')
for i in range(m):
    a, b, c = map(int, readline().split())
    graph[a - 1][b - 1] = c
    graph[b - 1][a - 1] = c
cost = floyd_warshall(csr_matrix(graph))
cnt = [[0] * n for _ in range(n)]
for i, cost_i in enumerate(cost):
    for j, v in enumerate(cost_i):
        if l >= v:
            cnt[i][j] = 1
cnt = floyd_warshall(csr_matrix(cnt))
q = int(readline())
for _ in range(q):
    s, t = map(int, readline().split())
    if cnt[s - 1][t - 1] == inf:
        print(-1)
    else:
        print(int(cnt[s - 1][t - 1] - 1))
