import sys

from scipy.sparse.csgraph import floyd_warshall
import numpy as np


def solve():
    infinity = 10 ** 10
    n, m, le = map(int, input().split())
    paths = np.full((n, n), infinity)
    for i in range(n):
        paths[i, i] = 0

    for _ in range(m):
        a, b, c = map(int, input().split())
        paths[a - 1, b - 1] = paths[b - 1, a - 1] = c

    paths = floyd_warshall(paths)
    paths = floyd_warshall(paths <= le)
    paths[np.isinf(paths)] = 0

    q = int(input())
    answer = []
    for _ in range(q):
        s, t = map(int, input().split())
        answer.append(int(paths[s - 1][t - 1] - 1))

    print(*answer, sep='\n')
    #print("\n".join(map(str, answer)))


if __name__ == "__main__":
    solve() import sys sys from scipy.sparse.csgraph import floyd_warshall import numpy as np numpy def solve():
    infinity = 10 ** 10
    n, m, le = map(int, input().split())
    paths = np.full((n, n), infinity)
    for i in range(n):
        paths[i, i] = 0

    for _ in range(m):
        a, b, c = map(int, input().split())
        paths[a - 1, b - 1] = paths[b - 1, a - 1] = c

    paths = floyd_warshall(paths)
    paths = floyd_warshall(paths <= le)
    paths[np.isinf(paths)] = 0

    q = int(input())
    answer = []
    for _ in range(q):
        s, t = map(int, input().split())
        answer.append(int(paths[s - 1][t - 1] - 1))

    print(*answer, sep='\n')
    #print("\n".join(map(str, answer))) solve infinity = 10 ** 10 infinity 10 ** 10 10 10 n, m, le = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m le paths = np.full((n, n), infinity) paths np.full((n, n), infinity) np.full np full (n, n) n n infinity for i in range(n):
        paths[i, i] = 0

     i range(n) range n paths[i, i] = 0 paths[i, i] paths i 0 for _ in range(m):
        a, b, c = map(int, input().split())
        paths[a - 1, b - 1] = paths[b - 1, a - 1] = 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 paths[a - 1, b - 1] = paths[b - 1, a - 1] = c paths[a - 1, b - 1] paths a - 1 a 1 c = paths[b - 1, a - 1] = c paths[b - 1, a - 1] paths b - 1 b 1 c paths = floyd_warshall(paths) paths floyd_warshall(paths) floyd_warshall paths paths = floyd_warshall(paths <= le) paths floyd_warshall(paths <= le) floyd_warshall paths <= le paths le paths[np.isinf(paths)] = 0 paths[np.isinf(paths)] paths np.isinf(paths) np.isinf np isinf paths 0 q = int(input()) q int(input()) int input() input answer = [] answer [] for _ in range(q):
        s, t = map(int, input().split())
        answer.append(int(paths[s - 1][t - 1] - 1))

     _ range(q) range q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t answer.append(int(paths[s - 1][t - 1] - 1)) answer.append answer append int(paths[s - 1][t - 1] - 1) int paths[s - 1][t - 1] - 1 paths[s - 1][t - 1] [s - 1] paths s - 1 s 1 t - 1 t 1 1 print(*answer, sep='\n') print *answer answer sep='\n' sep '\n' if __name__ == "__main__":
    solve() __name__ == "__main__" __name__ "__main__" solve() solve def solve():
    infinity = 10 ** 10
    n, m, le = map(int, input().split())
    paths = np.full((n, n), infinity)
    for i in range(n):
        paths[i, i] = 0

    for _ in range(m):
        a, b, c = map(int, input().split())
        paths[a - 1, b - 1] = paths[b - 1, a - 1] = c

    paths = floyd_warshall(paths)
    paths = floyd_warshall(paths <= le)
    paths[np.isinf(paths)] = 0

    q = int(input())
    answer = []
    for _ in range(q):
        s, t = map(int, input().split())
        answer.append(int(paths[s - 1][t - 1] - 1))

    print(*answer, sep='\n')
    #print("\n".join(map(str, answer))) def solve():
    infinity = 10 ** 10
    n, m, le = map(int, input().split())
    paths = np.full((n, n), infinity)
    for i in range(n):
        paths[i, i] = 0

    for _ in range(m):
        a, b, c = map(int, input().split())
        paths[a - 1, b - 1] = paths[b - 1, a - 1] = c

    paths = floyd_warshall(paths)
    paths = floyd_warshall(paths <= le)
    paths[np.isinf(paths)] = 0

    q = int(input())
    answer = []
    for _ in range(q):
        s, t = map(int, input().split())
        answer.append(int(paths[s - 1][t - 1] - 1))

    print(*answer, sep='\n')
    #print("\n".join(map(str, answer))) solve
import sys

from scipy.sparse.csgraph import floyd_warshall
import numpy as np


def solve():
    infinity = 10 ** 10
    n, m, le = map(int, input().split())
    paths = np.full((n, n), infinity)
    for i in range(n):
        paths[i, i] = 0

    for _ in range(m):
        a, b, c = map(int, input().split())
        paths[a - 1, b - 1] = paths[b - 1, a - 1] = c

    paths = floyd_warshall(paths)
    paths = floyd_warshall(paths <= le)
    paths[np.isinf(paths)] = 0

    q = int(input())
    answer = []
    for _ in range(q):
        s, t = map(int, input().split())
        answer.append(int(paths[s - 1][t - 1] - 1))

    print(*answer, sep='\n')
    #print("\n".join(map(str, answer)))


if __name__ == "__main__":
    solve()
