### BUGGY CODE ###

from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools

import queue
from collections import deque



def main():
    node_num, edge_num, max_tank = map(int, input().split())
    data = [list(map(int, input().split())) for i in range(edge_num)]
    q_num = int(input())
    query = [list(map(int, input().split())) for i in range(q_num)]

    graph_data = defaultdict(set)
    dist_data = defaultdict(int)

    # ans_list = [[-1 for i in range(node_num + 1)] for j in range(node_num + 1)]
    for i in range(edge_num):
        a, b, c = data[i]
        graph_data[a].add(b)
        graph_data[b].add(a)
        dist_data[(a, b)] = c
        dist_data[(b, a)] = c

        # if c <= max_tank:
        #     ans_list[a][b] = (0, max_tank - c)
        #     ans_list[b][a] = (0, max_tank - c)

    # print(graph_data)
    # print(dist_data)

    ans_list = [[-1 for i in range(node_num + 1)] for j in range(node_num + 1)]
    for i in range(1, node_num + 1):
        # print('start', i)
        ans_list[i][i] = 0
        aaa = []

        for next_ele in graph_data[i]:
            dist = dist_data[(i, next_ele)]
            if dist <= max_tank:
                heapq.heappush(aaa, (0, - (max_tank - dist), next_ele))

        # print(aaa)

        while len(aaa):
            count, nokori, now_ele = heapq.heappop(aaa)
            if ans_list[i][now_ele] != -1:
                continue

            nokori = -1 * nokori
            ans_list[i][now_ele] = count

            for next_ele in graph_data[now_ele]:
                if ans_list[i][next_ele] != -1:
                    continue
                dist = dist_data[(now_ele, next_ele)]
                if dist > max_tank:
                    continue
                if nokori < dist:
                    heapq.heappush(aaa, (count + 1, - (max_tank - dist), next_ele))
                else:
                    heapq.heappush(aaa, (count, - (nokori - dist), next_ele))

            # print(aaa)



    # for i in range(1, node_num + 1):
    #     print(ans_list[i])

    for i in range(q_num):
        s, t = query[i]
        ans = ans_list[s][t]
        print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools

import queue
from collections import deque



def main():
    node_num, edge_num, max_tank = map(int, input().split())
    data = [list(map(int, input().split())) for i in range(edge_num)]
    q_num = int(input())
    query = [list(map(int, input().split())) for i in range(q_num)]

    graph_data = defaultdict(set)
    dist_data = defaultdict(int)

    distance = [[10 ** 12 for i in range(node_num + 1)] for j in range(node_num + 1)]
    for i in range(1, node_num + 1):
        distance[i][i] = 0

    for i in range(edge_num):
        a, b, c = data[i]
        graph_data[a].add(b)
        graph_data[b].add(a)
        dist_data[(a, b)] = c
        dist_data[(b, a)] = c
        distance[a][b] = c
        distance[b][a] = c


    for k in range(1, node_num + 1):
        for i in range(1, node_num + 1):
            for j in range(1, node_num + 1):
                distance[i][j] = min(distance[i][k] + distance[k][j], distance[i][j])


    distance2 = [[10 ** 5 for i in range(node_num + 1)] for j in range(node_num + 1)]
    for i in range(1, node_num + 1):
        distance2[i][i] = 0

    for i in range(1, node_num + 1):
        for j in range(1, node_num + 1):
            if distance[i][j] <= max_tank:
                distance2[i][j] = 1


    for k in range(1, node_num + 1):
        for i in range(1, node_num + 1):
            for j in range(1, node_num + 1):
                distance2[i][j] = min(distance2[i][k] + distance2[k][j], distance2[i][j])

    for i in range(q_num):
        s, t = query[i]
        ans = distance2[s][t]
        if ans == 10 ** 5:
            print(-1)
        else:
            print(ans - 1)



if __name__ == '__main__':
    main()