# -*- coding: utf-8 -*-
from scipy.sparse.csgraph import floyd_warshall

"""
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
"""
N, M, L = map(int, input().split())

d = [[0 for i in range(N)] for i in range(N)]

for i in range(M):
    A, B, C = map(int, input().split())
    d[A-1][B-1] = C
    d[B-1][A-1] = C

d = floyd_warshall(d, directed = False)
S = [[0 for i in range(N)] for i in range(N)]


for i in range(N):
    for j in range(N):
        if d[i][j] <= L:
            S[i][j] = 1
            S[j][i] = 1
            
S = floyd_warshall(S, directed = False)

Q = int(input())

for i in range(Q):
    s, t = map(int, input().split())
    if S[s-1][t-1] == float("inf"):
        print(-1)
    else: 
        print(int(S[s-1][t-1]-1)) from scipy.sparse.csgraph import floyd_warshall """
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
""" N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L [0 for i in range(N)] for i in range(N) for i in range(N) i range(N) range N for i in range(N) [0 for i in range(N)] d = [[0 for i in range(N)] for i in range(N)] d [[0 for i in range(N)] for i in range(N)] for i in range(M):
    A, B, C = map(int, input().split())
    d[A-1][B-1] = C
    d[B-1][A-1] = C i 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 d[A-1][B-1] = C d[A-1][B-1] [A-1] d A-1 A 1 B-1 B 1 C d[B-1][A-1] = C d[B-1][A-1] [B-1] d B-1 B 1 A-1 A 1 C d = floyd_warshall(d, directed = False) d floyd_warshall(d, directed = False) floyd_warshall d directed = False directed False [0 for i in range(N)] for i in range(N) for i in range(N) i range(N) range N for i in range(N) [0 for i in range(N)] S = [[0 for i in range(N)] for i in range(N)] S [[0 for i in range(N)] for i in range(N)] for i in range(N):
    for j in range(N):
        if d[i][j] <= L:
            S[i][j] = 1
            S[j][i] = 1
             i range(N) range N for j in range(N):
        if d[i][j] <= L:
            S[i][j] = 1
            S[j][i] = 1
             j range(N) range N if d[i][j] <= L:
            S[i][j] = 1
            S[j][i] = 1
             d[i][j] <= L d[i][j] [i] d i j L S[i][j] = 1 S[i][j] [i] S i j 1 S[j][i] = 1 S[j][i] [j] S j i 1 S = floyd_warshall(S, directed = False) S floyd_warshall(S, directed = False) floyd_warshall S directed = False directed False Q = int(input()) Q int(input()) int input() input for i in range(Q):
    s, t = map(int, input().split())
    if S[s-1][t-1] == float("inf"):
        print(-1)
    else: 
        print(int(S[s-1][t-1]-1)) i range(Q) range Q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t if S[s-1][t-1] == float("inf"):
        print(-1)
    else: 
        print(int(S[s-1][t-1]-1)) S[s-1][t-1] == float("inf") S[s-1][t-1] [s-1] S s-1 s 1 t-1 t 1 float("inf") float "inf" print(-1) print -1 print(int(S[s-1][t-1]-1)) print int(S[s-1][t-1]-1) int S[s-1][t-1]-1 S[s-1][t-1] [s-1] S s-1 s 1 t-1 t 1 1 N, M, L = map(int, input().split()) map(int, input().split()) N S = [[0 for i in range(N)] for i in range(N)] [[0 for i in range(N)] for i in range(N)] S Q = int(input()) int(input()) Q M, L = map(int, input().split()) map(int, input().split()) M d = [[0 for i in range(N)] for i in range(N)] [[0 for i in range(N)] for i in range(N)] d S = floyd_warshall(S, directed = False) floyd_warshall(S, directed = False) S t = map(int, input().split()) map(int, input().split()) t s, t = map(int, input().split()) map(int, input().split()) s C = map(int, input().split()) map(int, input().split()) C B, C = map(int, input().split()) map(int, input().split()) B L = map(int, input().split()) map(int, input().split()) L d = floyd_warshall(d, directed = False) floyd_warshall(d, directed = False) d A, B, C = map(int, input().split()) map(int, input().split()) A
# -*- coding: utf-8 -*-
from scipy.sparse.csgraph import floyd_warshall

"""
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
"""
N, M, L = map(int, input().split())

d = [[0 for i in range(N)] for i in range(N)]

for i in range(M):
    A, B, C = map(int, input().split())
    d[A-1][B-1] = C
    d[B-1][A-1] = C

d = floyd_warshall(d, directed = False)
S = [[0 for i in range(N)] for i in range(N)]


for i in range(N):
    for j in range(N):
        if d[i][j] <= L:
            S[i][j] = 1
            S[j][i] = 1
            
S = floyd_warshall(S, directed = False)

Q = int(input())

for i in range(Q):
    s, t = map(int, input().split())
    if S[s-1][t-1] == float("inf"):
        print(-1)
    else: 
        print(int(S[s-1][t-1]-1))