# -*- coding: utf-8 -*-
"""
E - Travel by Car
https://atcoder.jp/contests/abc143/tasks/abc143_e

"""
import sys


from scipy.sparse.csgraph import floyd_warshall

def main(args):
    N, M, L = map(int, input().split())
    g1 = [[float('inf')] * (N+1) for _ in range(N+1)]
    for i in range(N+1):
        g1[i][i] = 0
    for _ in range(M):
        A, B, C = map(int, input().split())
        g1[A][B] = g1[B][A] = C
    d1 = floyd_warshall(g1)
    g2 = [[float('inf')] * (N+1) for _ in range(N+1)]
    for i in range(N+1):
        for j in range(N+1):
            if i == j:
                g2[i][j] = 0
            elif d1[i][j] <= L:
                g2[i][j] = g2[j][i] = 1
    d2 = floyd_warshall(g2)
    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        print(-1 if d2[s][t] == float('inf') else int(d2[s][t]) - 1)


if __name__ == '__main__':
    main(sys.argv[1:]) """
E - Travel by Car
https://atcoder.jp/contests/abc143/tasks/abc143_e

""" import sys sys from scipy.sparse.csgraph import floyd_warshall def main(args):
    N, M, L = map(int, input().split())
    g1 = [[float('inf')] * (N+1) for _ in range(N+1)]
    for i in range(N+1):
        g1[i][i] = 0
    for _ in range(M):
        A, B, C = map(int, input().split())
        g1[A][B] = g1[B][A] = C
    d1 = floyd_warshall(g1)
    g2 = [[float('inf')] * (N+1) for _ in range(N+1)]
    for i in range(N+1):
        for j in range(N+1):
            if i == j:
                g2[i][j] = 0
            elif d1[i][j] <= L:
                g2[i][j] = g2[j][i] = 1
    d2 = floyd_warshall(g2)
    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        print(-1 if d2[s][t] == float('inf') else int(d2[s][t]) - 1) main N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L [float('inf')] * (N+1) for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) [float('inf')] * (N+1) [float('inf')] float('inf') float 'inf' N+1 N 1 g1 = [[float('inf')] * (N+1) for _ in range(N+1)] g1 [[float('inf')] * (N+1) for _ in range(N+1)] for i in range(N+1):
        g1[i][i] = 0
     i range(N+1) range N+1 N 1 g1[i][i] = 0 g1[i][i] [i] g1 i i 0 for _ in range(M):
        A, B, C = map(int, input().split())
        g1[A][B] = g1[B][A] = C
     _ 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 g1[A][B] = g1[B][A] = C g1[A][B] [A] g1 A B C = g1[B][A] = C g1[B][A] [B] g1 B A C d1 = floyd_warshall(g1) d1 floyd_warshall(g1) floyd_warshall g1 [float('inf')] * (N+1) for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) [float('inf')] * (N+1) [float('inf')] float('inf') float 'inf' N+1 N 1 g2 = [[float('inf')] * (N+1) for _ in range(N+1)] g2 [[float('inf')] * (N+1) for _ in range(N+1)] for i in range(N+1):
        for j in range(N+1):
            if i == j:
                g2[i][j] = 0
            elif d1[i][j] <= L:
                g2[i][j] = g2[j][i] = 1
     i range(N+1) range N+1 N 1 for j in range(N+1):
            if i == j:
                g2[i][j] = 0
            elif d1[i][j] <= L:
                g2[i][j] = g2[j][i] = 1
     j range(N+1) range N+1 N 1 if i == j:
                g2[i][j] = 0
            elif d1[i][j] <= L:
                g2[i][j] = g2[j][i] = 1
     i == j i j g2[i][j] = 0 g2[i][j] [i] g2 i j 0 elif d1[i][j] <= L:
                g2[i][j] = g2[j][i] = 1
     d1[i][j] <= L d1[i][j] [i] d1 i j L g2[i][j] = g2[j][i] = 1 g2[i][j] [i] g2 i j 1 = g2[j][i] = 1 g2[j][i] [j] g2 j i 1 d2 = floyd_warshall(g2) d2 floyd_warshall(g2) floyd_warshall g2 Q = int(input()) Q int(input()) int input() input for _ in range(Q):
        s, t = map(int, input().split())
        print(-1 if d2[s][t] == float('inf') else int(d2[s][t]) - 1) _ range(Q) range Q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t print(-1 if d2[s][t] == float('inf') else int(d2[s][t]) - 1) print -1 if d2[s][t] == float('inf') else int(d2[s][t]) - 1 d2[s][t] == float('inf') d2[s][t] [s] d2 s t float('inf') float 'inf' -1 int(d2[s][t]) - 1 int(d2[s][t]) int d2[s][t] [s] d2 s t 1 args args if __name__ == '__main__':
    main(sys.argv[1:]) __name__ == '__main__' __name__ '__main__' main(sys.argv[1:]) main sys.argv[1:] sys.argv sys argv 1: 1 def main(args):
    N, M, L = map(int, input().split())
    g1 = [[float('inf')] * (N+1) for _ in range(N+1)]
    for i in range(N+1):
        g1[i][i] = 0
    for _ in range(M):
        A, B, C = map(int, input().split())
        g1[A][B] = g1[B][A] = C
    d1 = floyd_warshall(g1)
    g2 = [[float('inf')] * (N+1) for _ in range(N+1)]
    for i in range(N+1):
        for j in range(N+1):
            if i == j:
                g2[i][j] = 0
            elif d1[i][j] <= L:
                g2[i][j] = g2[j][i] = 1
    d2 = floyd_warshall(g2)
    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        print(-1 if d2[s][t] == float('inf') else int(d2[s][t]) - 1) def main(args):
    N, M, L = map(int, input().split())
    g1 = [[float('inf')] * (N+1) for _ in range(N+1)]
    for i in range(N+1):
        g1[i][i] = 0
    for _ in range(M):
        A, B, C = map(int, input().split())
        g1[A][B] = g1[B][A] = C
    d1 = floyd_warshall(g1)
    g2 = [[float('inf')] * (N+1) for _ in range(N+1)]
    for i in range(N+1):
        for j in range(N+1):
            if i == j:
                g2[i][j] = 0
            elif d1[i][j] <= L:
                g2[i][j] = g2[j][i] = 1
    d2 = floyd_warshall(g2)
    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        print(-1 if d2[s][t] == float('inf') else int(d2[s][t]) - 1) main
# -*- coding: utf-8 -*-
"""
E - Travel by Car
https://atcoder.jp/contests/abc143/tasks/abc143_e

"""
import sys


from scipy.sparse.csgraph import floyd_warshall

def main(args):
    N, M, L = map(int, input().split())
    g1 = [[float('inf')] * (N+1) for _ in range(N+1)]
    for i in range(N+1):
        g1[i][i] = 0
    for _ in range(M):
        A, B, C = map(int, input().split())
        g1[A][B] = g1[B][A] = C
    d1 = floyd_warshall(g1)
    g2 = [[float('inf')] * (N+1) for _ in range(N+1)]
    for i in range(N+1):
        for j in range(N+1):
            if i == j:
                g2[i][j] = 0
            elif d1[i][j] <= L:
                g2[i][j] = g2[j][i] = 1
    d2 = floyd_warshall(g2)
    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        print(-1 if d2[s][t] == float('inf') else int(d2[s][t]) - 1)


if __name__ == '__main__':
    main(sys.argv[1:])
