# -*- coding: utf-8 -*-

import sys
from scipy.sparse.csgraph import floyd_warshall

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, M, L = MAP()
G = list2d(N, N, INF)
for i in range(M):
    a, b, c = MAP()
    a -= 1
    b -= 1
    G[a][b] = c
    G[b][a] = c

res = floyd_warshall(G)

G2 = list2d(N, N, INF)
for i in range(N):
    for j in range(i, N):
        # 最短距離がL以下の2点なら燃料1回で行ける
        if res[i][j] <= L:
            G2[i][j] = 1
            G2[j][i] = 1

# 燃料使用回数をコストとした最短経路
res2 = floyd_warshall(G2)

for i in range(INT()):
    a, b = MAP()
    a -= 1
    b -= 1
    ans = res2[a][b]
    if ans != INF:
        print(ans-1)
    else:
        print(-1) import sys sys from scipy.sparse.csgraph import floyd_warshall def input(): return sys.stdin.readline().strip() input [c] * b for i in range(a) for i in range(a) i range(a) range a for i in range(a) [c] * b [c] c b def list2d(a, b, c): return [[c] * b for i in range(a)] list2d a a b b c c [[d] * c for j in range(b)] for i in range(a) for i in range(a) i range(a) range a for i in range(a) [[d] * c for j in range(b)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] list3d a a b b c c d d [[[e] * d for j in range(c)] for j in range(b)] for i in range(a) for i in range(a) i range(a) range a for i in range(a) [[[e] * d for j in range(c)] for j in range(b)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] list4d a a b b c c d d e e def ceil(x, y=1): return int(-(-x // y)) ceil x x y=1 y 1 def INT(): return int(input()) INT def MAP(): return map(int, input().split()) MAP INT() for i in range(N) for i in range(N) i range(N) range N for i in range(N) INT() INT def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] LIST N=None N None def Yes(): print('Yes') Yes def No(): print('No') No def YES(): print('YES') YES def NO(): print('NO') NO sys.setrecursionlimit(10 ** 9) sys.setrecursionlimit sys setrecursionlimit 10 ** 9 10 9 INF = 10 ** 18 INF 10 ** 18 10 18 MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 N, M, L = MAP() N MAP() MAP M L G = list2d(N, N, INF) G list2d(N, N, INF) list2d N N INF for i in range(M):
    a, b, c = MAP()
    a -= 1
    b -= 1
    G[a][b] = c
    G[b][a] = c i range(M) range M a, b, c = MAP() a MAP() MAP b c a -= 1 a 1 b -= 1 b 1 G[a][b] = c G[a][b] [a] G a b c G[b][a] = c G[b][a] [b] G b a c res = floyd_warshall(G) res floyd_warshall(G) floyd_warshall G G2 = list2d(N, N, INF) G2 list2d(N, N, INF) list2d N N INF for i in range(N):
    for j in range(i, N):
        # 最短距離がL以下の2点なら燃料1回で行ける
        if res[i][j] <= L:
            G2[i][j] = 1
            G2[j][i] = 1

# 燃料使用回数をコストとした最短経路 i range(N) range N for j in range(i, N):
        # 最短距離がL以下の2点なら燃料1回で行ける
        if res[i][j] <= L:
            G2[i][j] = 1
            G2[j][i] = 1

# 燃料使用回数をコストとした最短経路 j range(i, N) range i N if res[i][j] <= L:
            G2[i][j] = 1
            G2[j][i] = 1

# 燃料使用回数をコストとした最短経路 res[i][j] <= L res[i][j] [i] res i j L G2[i][j] = 1 G2[i][j] [i] G2 i j 1 G2[j][i] = 1 G2[j][i] [j] G2 j i 1 res2 = floyd_warshall(G2) res2 floyd_warshall(G2) floyd_warshall G2 for i in range(INT()):
    a, b = MAP()
    a -= 1
    b -= 1
    ans = res2[a][b]
    if ans != INF:
        print(ans-1)
    else:
        print(-1) i range(INT()) range INT() INT a, b = MAP() a MAP() MAP b a -= 1 a 1 b -= 1 b 1 ans = res2[a][b] ans res2[a][b] [a] res2 a b if ans != INF:
        print(ans-1)
    else:
        print(-1) ans != INF ans INF print(ans-1) print ans-1 ans 1 print(-1) print -1 def ceil(x, y=1): return int(-(-x // y)) def ceil(x, y=1): return int(-(-x // y)) ceil a -= 1 1 a b -= 1 1 b a, b = MAP() MAP() a def input(): return sys.stdin.readline().strip() def input(): return sys.stdin.readline().strip() input c = MAP() MAP() c ans = res2[a][b] res2[a][b] ans def YES(): print('YES') def YES(): print('YES') YES def NO(): print('NO') def NO(): print('NO') NO def INT(): return int(input()) def INT(): return int(input()) INT def MAP(): return map(int, input().split()) def MAP(): return map(int, input().split()) MAP N, M, L = MAP() MAP() N G2 = list2d(N, N, INF) list2d(N, N, INF) G2 res = floyd_warshall(G) floyd_warshall(G) res res2 = floyd_warshall(G2) floyd_warshall(G2) res2 def Yes(): print('Yes') def Yes(): print('Yes') Yes b = MAP() MAP() b def No(): print('No') def No(): print('No') No b -= 1 1 b INF = 10 ** 18 10 ** 18 INF def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] LIST L = MAP() MAP() L a, b, c = MAP() MAP() a def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] list3d def list2d(a, b, c): return [[c] * b for i in range(a)] def list2d(a, b, c): return [[c] * b for i in range(a)] list2d M, L = MAP() MAP() M def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] list4d MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD G = list2d(N, N, INF) list2d(N, N, INF) G a -= 1 1 a b, c = MAP() MAP() b
# -*- coding: utf-8 -*-

import sys
from scipy.sparse.csgraph import floyd_warshall

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, M, L = MAP()
G = list2d(N, N, INF)
for i in range(M):
    a, b, c = MAP()
    a -= 1
    b -= 1
    G[a][b] = c
    G[b][a] = c

res = floyd_warshall(G)

G2 = list2d(N, N, INF)
for i in range(N):
    for j in range(i, N):
        # 最短距離がL以下の2点なら燃料1回で行ける
        if res[i][j] <= L:
            G2[i][j] = 1
            G2[j][i] = 1

# 燃料使用回数をコストとした最短経路
res2 = floyd_warshall(G2)

for i in range(INT()):
    a, b = MAP()
    a -= 1
    b -= 1
    ans = res2[a][b]
    if ans != INF:
        print(ans-1)
    else:
        print(-1)
