### BUGGY CODE ###

from collections import deque


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))

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

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

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

### 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)