import sys
input = sys.stdin.readline

n,m,l = map(int,input().split())
A = [list(map(int,input().split())) for i in range(m)]
q = int(input())
S = [list(map(int,input().split())) for i in range(q)]

from scipy.sparse.csgraph import floyd_warshall

for i in range(m):  # ノード番号が1始まりで与えられている場合
    for j in range(2):
        A[i][j] -= 1

for i in range(q):  # ノード番号が1始まりで与えられている場合
    for j in range(2):
        S[i][j] -= 1

M = [[float("inf")] * n for i in range(n)]

for i in range(n):
    M[i][i] = 0

for i in range(m):
    M[A[i][0]][A[i][1]] = A[i][2]
    M[A[i][1]][A[i][0]] = A[i][2]

# for k in range(n):
#     for i in range(n):
#         for j in range(n):
#             M[i][j] = min(M[i][j], M[i][k] + M[k][j])

M = floyd_warshall(M)

for i in range(n):
    for j in range(n):
        M[i][j] = 1 if M[i][j] <= l else float("inf")

for i in range(n):
    M[i][i] = 0

# for k in range(n):
#     for i in range(n):
#         for j in range(n):
#             M[i][j] = min(M[i][j], M[i][k] + M[k][j])

M = floyd_warshall(M)

for i in range(q):
    ans = M[S[i][0]][S[i][1]]-1
    if ans == float("inf"):
        ans = -1
    print(int(ans)) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline n,m,l = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l list(map(int,input().split())) for i in range(m) for i in range(m) i range(m) range m for i in range(m) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split A = [list(map(int,input().split())) for i in range(m)] A [list(map(int,input().split())) for i in range(m)] q = int(input()) q int(input()) int input() input list(map(int,input().split())) for i in range(q) for i in range(q) i range(q) range q for i in range(q) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split S = [list(map(int,input().split())) for i in range(q)] S [list(map(int,input().split())) for i in range(q)] from scipy.sparse.csgraph import floyd_warshall for i in range(m):  # ノード番号が1始まりで与えられている場合
    for j in range(2):
        A[i][j] -= 1 i range(m) range m for j in range(2):
        A[i][j] -= 1 j range(2) range 2 A[i][j] -= 1 A[i][j] [i] A i j 1 for i in range(q):  # ノード番号が1始まりで与えられている場合
    for j in range(2):
        S[i][j] -= 1 i range(q) range q for j in range(2):
        S[i][j] -= 1 j range(2) range 2 S[i][j] -= 1 S[i][j] [i] S i j 1 [float("inf")] * n for i in range(n) for i in range(n) i range(n) range n for i in range(n) [float("inf")] * n [float("inf")] float("inf") float "inf" n M = [[float("inf")] * n for i in range(n)] M [[float("inf")] * n for i in range(n)] for i in range(n):
    M[i][i] = 0 i range(n) range n M[i][i] = 0 M[i][i] [i] M i i 0 for i in range(m):
    M[A[i][0]][A[i][1]] = A[i][2]
    M[A[i][1]][A[i][0]] = A[i][2]

# for k in range(n):
#     for i in range(n):
#         for j in range(n):
#             M[i][j] = min(M[i][j], M[i][k] + M[k][j]) i range(m) range m M[A[i][0]][A[i][1]] = A[i][2] M[A[i][0]][A[i][1]] [A[i][0]] M A[i][0] [i] A i 0 A[i][1] [i] A i 1 A[i][2] [i] A i 2 M[A[i][1]][A[i][0]] = A[i][2] M[A[i][1]][A[i][0]] [A[i][1]] M A[i][1] [i] A i 1 A[i][0] [i] A i 0 A[i][2] [i] A i 2 M = floyd_warshall(M) M floyd_warshall(M) floyd_warshall M for i in range(n):
    for j in range(n):
        M[i][j] = 1 if M[i][j] <= l else float("inf") i range(n) range n for j in range(n):
        M[i][j] = 1 if M[i][j] <= l else float("inf") j range(n) range n M[i][j] = 1 if M[i][j] <= l else float("inf") M[i][j] [i] M i j 1 if M[i][j] <= l else float("inf") M[i][j] <= l M[i][j] [i] M i j l 1 float("inf") float "inf" for i in range(n):
    M[i][i] = 0

# for k in range(n):
#     for i in range(n):
#         for j in range(n):
#             M[i][j] = min(M[i][j], M[i][k] + M[k][j]) i range(n) range n M[i][i] = 0 M[i][i] [i] M i i 0 M = floyd_warshall(M) M floyd_warshall(M) floyd_warshall M for i in range(q):
    ans = M[S[i][0]][S[i][1]]-1
    if ans == float("inf"):
        ans = -1
    print(int(ans)) i range(q) range q ans = M[S[i][0]][S[i][1]]-1 ans M[S[i][0]][S[i][1]]-1 M[S[i][0]][S[i][1]] [S[i][0]] M S[i][0] [i] S i 0 S[i][1] [i] S i 1 1 if ans == float("inf"):
        ans = -1
     ans == float("inf") ans float("inf") float "inf" ans = -1 ans -1 print(int(ans)) print int(ans) int ans S = [list(map(int,input().split())) for i in range(q)] [list(map(int,input().split())) for i in range(q)] S M = floyd_warshall(M) floyd_warshall(M) M q = int(input()) int(input()) q ans = -1 -1 ans A = [list(map(int,input().split())) for i in range(m)] [list(map(int,input().split())) for i in range(m)] A M = [[float("inf")] * n for i in range(n)] [[float("inf")] * n for i in range(n)] M M = floyd_warshall(M) floyd_warshall(M) M m,l = map(int,input().split()) map(int,input().split()) m n,m,l = map(int,input().split()) map(int,input().split()) n input = sys.stdin.readline sys.stdin.readline input ans = M[S[i][0]][S[i][1]]-1 M[S[i][0]][S[i][1]]-1 ans l = map(int,input().split()) map(int,input().split()) l
import sys
input = sys.stdin.readline

n,m,l = map(int,input().split())
A = [list(map(int,input().split())) for i in range(m)]
q = int(input())
S = [list(map(int,input().split())) for i in range(q)]

from scipy.sparse.csgraph import floyd_warshall

for i in range(m):  # ノード番号が1始まりで与えられている場合
    for j in range(2):
        A[i][j] -= 1

for i in range(q):  # ノード番号が1始まりで与えられている場合
    for j in range(2):
        S[i][j] -= 1

M = [[float("inf")] * n for i in range(n)]

for i in range(n):
    M[i][i] = 0

for i in range(m):
    M[A[i][0]][A[i][1]] = A[i][2]
    M[A[i][1]][A[i][0]] = A[i][2]

# for k in range(n):
#     for i in range(n):
#         for j in range(n):
#             M[i][j] = min(M[i][j], M[i][k] + M[k][j])

M = floyd_warshall(M)

for i in range(n):
    for j in range(n):
        M[i][j] = 1 if M[i][j] <= l else float("inf")

for i in range(n):
    M[i][i] = 0

# for k in range(n):
#     for i in range(n):
#         for j in range(n):
#             M[i][j] = min(M[i][j], M[i][k] + M[k][j])

M = floyd_warshall(M)

for i in range(q):
    ans = M[S[i][0]][S[i][1]]-1
    if ans == float("inf"):
        ans = -1
    print(int(ans))