### BUGGY CODE ###

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    inf = 10**17
    #mod = 10**9 + 7

    n,m,l = map(int, input().split())
    edge = [[] for i in range(n)]
    #edge[i] : iから出る道の[重み,行先]の配列
    for _ in range(m):
        x,y,z = map(int,input().split())
        edge[x-1].append((z,y-1))
        edge[y-1].append((z,x-1))

    def bfs(start):
        d = [inf]*n
        d[start] = 0
        f = [-1]*n
        f[start] = l
        dq = deque([[start, l, 0]])
        while dq:
            v, nl, dist = dq.popleft()
            for c, nv in edge[v]:
                if l - c < 0:
                    continue
                if nl - c >= 0:
                    if dist < d[nv] or (dist==d[nv]and f[nv] < nl - c):
                        f[nv] = nl - c
                        d[nv] = dist
                        dq.append((nv, nl - c, dist))
                else:
                    if dist + 1 < d[nv] or (dist+1==d[nv] and f[nv] < l-c):
                        f[nv] = l - c
                        d[nv] = dist + 1
                        dq.append((nv, l - c, dist + 1))
        return d

    res = []
    for i in range(n):
        res.append(bfs(i))

    q = int(input())
    ans = []
    for _ in range(q):
        s,t = map(int, input().split())
        if res[s-1][t-1] == inf:
            ans.append(-1)
        else:
            ans.append(res[s-1][t-1])
    
    for i in ans:
        print(i)

if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import deque
import sys
import random
input = sys.stdin.readline


n, m, l = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]
graph = [[] for i in range(n)]

for i in range(m):
    a, b, cost = info[i]
    if cost > l:
        continue
    a -= 1
    b -= 1
    graph[a].append((b, cost))
    graph[b].append((a, cost))

for i in range(n):
    graph[i] = random.sample(graph[i], len(graph[i]))
    
def dfs(start):
    INF = float("inf")
    visited_t = [INF]*n # 回数, 残り燃料
    visited_l = [0]*n
    visited_t[start] = 0
    q = deque([start])
    while q:
        pos = q.popleft()
        for next_pos, cost in graph[pos]:
            tmp = cost + visited_l[pos]
            times = visited_t[pos]
            next_times = visited_t[next_pos]
            if tmp <= l:
                if next_times > times:
                    q.append(next_pos)
                    visited_t[next_pos] = times
                    visited_l[next_pos] = tmp
                elif next_times == times:
                    if visited_l[next_pos] > tmp:
                        q.append(next_pos)
                        visited_t[next_pos] = times
                        visited_l[next_pos] = tmp
                else:
                    continue
            else:
                tmp = cost
                if next_times > times + 1:
                    q.append(next_pos)
                    visited_t[next_pos] = times + 1
                    visited_l[next_pos] = tmp
                elif next_times == times + 1:
                    if visited_l[next_pos] > tmp:
                        q.append(next_pos)
                        visited_t[next_pos] = times + 1
                        visited_l[next_pos] = tmp
                else:
                    continue
    return visited_t

ans = [None]*n
for i in range(n):
    ans[i] = dfs(i)

INF = float("inf")
q = int(input())
query = [list(map(int, input().split())) for i in range(q)]
for i in range(q):
    a, b = query[i]
    a -= 1
    b -= 1
    tmp = ans[a][b]
    if tmp == INF:
        print(-1)
    else:
        print(tmp)