#!/usr/bin/env python

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**6)
inf = float("inf")

import numpy as np
import scipy.sparse.csgraph as csg

def main():
    N,M,L = map(int,input().split())
    ABC = [tuple(map(int,input().split())) for _ in range(M)]
    Q = int(input())
    ST = [tuple(map(int,input().split())) for _ in range(Q)]

    # 町の最短距離を求める
    A = np.array([[inf]*N]*N)
    for a,b,c in ABC:
        A[a-1][b-1] = c
        A[b-1][a-1] = c
    A = csg.floyd_warshall(A)
    
    # 求めた町の距離が L以下 に 1の辺をはる (給油なしでたどり着ける)
    B = np.array([[inf]*N]*N)
    for i in range(N):
        for j in range(N):
            if A[i][j] <= L:
                B[i][j] = 1
    # 最短距離を求める
    B = csg.floyd_warshall(B)
    
    for s,t in ST:
        if B[s-1][t-1] == inf:
            print(-1)
        else:
            print(int(B[s-1][t-1] - 1))

if __name__ == "__main__":
    main() import sys sys input = sys.stdin.buffer.readline input sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline sys.setrecursionlimit(10**6) sys.setrecursionlimit sys setrecursionlimit 10**6 10 6 inf = float("inf") inf float("inf") float "inf" import numpy as np numpy import scipy.sparse.csgraph as csg scipy.sparse.csgraph def main():
    N,M,L = map(int,input().split())
    ABC = [tuple(map(int,input().split())) for _ in range(M)]
    Q = int(input())
    ST = [tuple(map(int,input().split())) for _ in range(Q)]

    # 町の最短距離を求める
    A = np.array([[inf]*N]*N)
    for a,b,c in ABC:
        A[a-1][b-1] = c
        A[b-1][a-1] = c
    A = csg.floyd_warshall(A)
    
    # 求めた町の距離が L以下 に 1の辺をはる (給油なしでたどり着ける)
    B = np.array([[inf]*N]*N)
    for i in range(N):
        for j in range(N):
            if A[i][j] <= L:
                B[i][j] = 1
    # 最短距離を求める
    B = csg.floyd_warshall(B)
    
    for s,t in ST:
        if B[s-1][t-1] == inf:
            print(-1)
        else:
            print(int(B[s-1][t-1] - 1)) main N,M,L = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M L tuple(map(int,input().split())) for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) tuple(map(int,input().split())) tuple map(int,input().split()) map int input().split() ().split () input split ABC = [tuple(map(int,input().split())) for _ in range(M)] ABC [tuple(map(int,input().split())) for _ in range(M)] Q = int(input()) Q int(input()) int input() input tuple(map(int,input().split())) for _ in range(Q) for _ in range(Q) _ range(Q) range Q for _ in range(Q) tuple(map(int,input().split())) tuple map(int,input().split()) map int input().split() ().split () input split ST = [tuple(map(int,input().split())) for _ in range(Q)] ST [tuple(map(int,input().split())) for _ in range(Q)] A = np.array([[inf]*N]*N) A np.array([[inf]*N]*N) np.array np array [[inf]*N]*N [[inf]*N] [inf]*N [inf] inf N N for a,b,c in ABC:
        A[a-1][b-1] = c
        A[b-1][a-1] = c
     a b c ABC A[a-1][b-1] = c A[a-1][b-1] [a-1] A a-1 a 1 b-1 b 1 c A[b-1][a-1] = c A[b-1][a-1] [b-1] A b-1 b 1 a-1 a 1 c A = csg.floyd_warshall(A) A csg.floyd_warshall(A) csg.floyd_warshall csg floyd_warshall A B = np.array([[inf]*N]*N) B np.array([[inf]*N]*N) np.array np array [[inf]*N]*N [[inf]*N] [inf]*N [inf] inf N N for i in range(N):
        for j in range(N):
            if A[i][j] <= L:
                B[i][j] = 1
    # 最短距離を求める
     i range(N) range N for j in range(N):
            if A[i][j] <= L:
                B[i][j] = 1
    # 最短距離を求める
     j range(N) range N if A[i][j] <= L:
                B[i][j] = 1
    # 最短距離を求める
     A[i][j] <= L A[i][j] [i] A i j L B[i][j] = 1 B[i][j] [i] B i j 1 B = csg.floyd_warshall(B) B csg.floyd_warshall(B) csg.floyd_warshall csg floyd_warshall B for s,t in ST:
        if B[s-1][t-1] == inf:
            print(-1)
        else:
            print(int(B[s-1][t-1] - 1)) s t ST if B[s-1][t-1] == inf:
            print(-1)
        else:
            print(int(B[s-1][t-1] - 1)) B[s-1][t-1] == inf B[s-1][t-1] [s-1] B s-1 s 1 t-1 t 1 inf print(-1) print -1 print(int(B[s-1][t-1] - 1)) print int(B[s-1][t-1] - 1) int B[s-1][t-1] - 1 B[s-1][t-1] [s-1] B s-1 s 1 t-1 t 1 1 if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main input = sys.stdin.buffer.readline sys.stdin.buffer.readline input def main():
    N,M,L = map(int,input().split())
    ABC = [tuple(map(int,input().split())) for _ in range(M)]
    Q = int(input())
    ST = [tuple(map(int,input().split())) for _ in range(Q)]

    # 町の最短距離を求める
    A = np.array([[inf]*N]*N)
    for a,b,c in ABC:
        A[a-1][b-1] = c
        A[b-1][a-1] = c
    A = csg.floyd_warshall(A)
    
    # 求めた町の距離が L以下 に 1の辺をはる (給油なしでたどり着ける)
    B = np.array([[inf]*N]*N)
    for i in range(N):
        for j in range(N):
            if A[i][j] <= L:
                B[i][j] = 1
    # 最短距離を求める
    B = csg.floyd_warshall(B)
    
    for s,t in ST:
        if B[s-1][t-1] == inf:
            print(-1)
        else:
            print(int(B[s-1][t-1] - 1)) def main():
    N,M,L = map(int,input().split())
    ABC = [tuple(map(int,input().split())) for _ in range(M)]
    Q = int(input())
    ST = [tuple(map(int,input().split())) for _ in range(Q)]

    # 町の最短距離を求める
    A = np.array([[inf]*N]*N)
    for a,b,c in ABC:
        A[a-1][b-1] = c
        A[b-1][a-1] = c
    A = csg.floyd_warshall(A)
    
    # 求めた町の距離が L以下 に 1の辺をはる (給油なしでたどり着ける)
    B = np.array([[inf]*N]*N)
    for i in range(N):
        for j in range(N):
            if A[i][j] <= L:
                B[i][j] = 1
    # 最短距離を求める
    B = csg.floyd_warshall(B)
    
    for s,t in ST:
        if B[s-1][t-1] == inf:
            print(-1)
        else:
            print(int(B[s-1][t-1] - 1)) main inf = float("inf") float("inf") inf
#!/usr/bin/env python

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**6)
inf = float("inf")

import numpy as np
import scipy.sparse.csgraph as csg

def main():
    N,M,L = map(int,input().split())
    ABC = [tuple(map(int,input().split())) for _ in range(M)]
    Q = int(input())
    ST = [tuple(map(int,input().split())) for _ in range(Q)]

    # 町の最短距離を求める
    A = np.array([[inf]*N]*N)
    for a,b,c in ABC:
        A[a-1][b-1] = c
        A[b-1][a-1] = c
    A = csg.floyd_warshall(A)
    
    # 求めた町の距離が L以下 に 1の辺をはる (給油なしでたどり着ける)
    B = np.array([[inf]*N]*N)
    for i in range(N):
        for j in range(N):
            if A[i][j] <= L:
                B[i][j] = 1
    # 最短距離を求める
    B = csg.floyd_warshall(B)
    
    for s,t in ST:
        if B[s-1][t-1] == inf:
            print(-1)
        else:
            print(int(B[s-1][t-1] - 1))

if __name__ == "__main__":
    main()