# -*- coding: utf-8 -*-
# E

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

import sys
input = sys.stdin.readline

INF = float("INF")

N, M, L = map(int, input().split())

cost = [[INF] * N for _ in range(N)]
for i in range(N):
    cost[i][i] = 0

for _ in range(M):
    v1, v2, w = map(int, input().split())
    v1, v2 = v1-1, v2-1
    cost[v1][v2] = w
    cost[v2][v1] = w

for k in range(N):
    for i in range(N):
        for j in range(N):
            if cost[i][j] > cost[i][k] + cost[k][j]:
                cost[i][j] = cost[i][k] + cost[k][j]

for i in range(N):
    for j in range(N):
        if cost[i][j] == 0:
            continue
        elif cost[i][j] <= L:
            cost[i][j] = 1
        else:
            cost[i][j] = INF

for k in range(N):
    for i in range(N):
        for j in range(N):
            if cost[i][j] > cost[i][k] + cost[k][j]:
                cost[i][j] = cost[i][k] + cost[k][j]

q = int(input())
for _ in range(q):
    s, t = map(int, input().split())
    if cost[s-1][t-1] == INF:
        print(-1)
    else:
        print(cost[s-1][t-1] - 1) import sys sys from collections import defaultdict, deque from heapq import heappush, heappop import math math import bisect bisect import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline INF = float("INF") INF float("INF") float "INF" N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L [INF] * N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF] * N [INF] INF N cost = [[INF] * N for _ in range(N)] cost [[INF] * N for _ in range(N)] for i in range(N):
    cost[i][i] = 0 i range(N) range N cost[i][i] = 0 cost[i][i] [i] cost i i 0 for _ in range(M):
    v1, v2, w = map(int, input().split())
    v1, v2 = v1-1, v2-1
    cost[v1][v2] = w
    cost[v2][v1] = w _ range(M) range M v1, v2, w = map(int, input().split()) v1 map(int, input().split()) map int input().split() ().split () input split v2 w v1, v2 = v1-1, v2-1 v1 v1-1 v1 1 v2 v2-1 v2 1 cost[v1][v2] = w cost[v1][v2] [v1] cost v1 v2 w cost[v2][v1] = w cost[v2][v1] [v2] cost v2 v1 w for k in range(N):
    for i in range(N):
        for j in range(N):
            if cost[i][j] > cost[i][k] + cost[k][j]:
                cost[i][j] = cost[i][k] + cost[k][j] k range(N) range N for i in range(N):
        for j in range(N):
            if cost[i][j] > cost[i][k] + cost[k][j]:
                cost[i][j] = cost[i][k] + cost[k][j] i range(N) range N for j in range(N):
            if cost[i][j] > cost[i][k] + cost[k][j]:
                cost[i][j] = cost[i][k] + cost[k][j] j range(N) range N if cost[i][j] > cost[i][k] + cost[k][j]:
                cost[i][j] = cost[i][k] + cost[k][j] cost[i][j] > cost[i][k] + cost[k][j] cost[i][j] [i] cost i j cost[i][k] + cost[k][j] cost[i][k] [i] cost i k cost[k][j] [k] cost k j cost[i][j] = cost[i][k] + cost[k][j] cost[i][j] [i] cost i j cost[i][k] + cost[k][j] cost[i][k] [i] cost i k cost[k][j] [k] cost k j for i in range(N):
    for j in range(N):
        if cost[i][j] == 0:
            continue
        elif cost[i][j] <= L:
            cost[i][j] = 1
        else:
            cost[i][j] = INF i range(N) range N for j in range(N):
        if cost[i][j] == 0:
            continue
        elif cost[i][j] <= L:
            cost[i][j] = 1
        else:
            cost[i][j] = INF j range(N) range N if cost[i][j] == 0:
            continue
        elif cost[i][j] <= L:
            cost[i][j] = 1
        else:
            cost[i][j] = INF cost[i][j] == 0 cost[i][j] [i] cost i j 0 continue elif cost[i][j] <= L:
            cost[i][j] = 1
         cost[i][j] <= L cost[i][j] [i] cost i j L cost[i][j] = 1 cost[i][j] [i] cost i j 1 cost[i][j] = INF cost[i][j] [i] cost i j INF for k in range(N):
    for i in range(N):
        for j in range(N):
            if cost[i][j] > cost[i][k] + cost[k][j]:
                cost[i][j] = cost[i][k] + cost[k][j] k range(N) range N for i in range(N):
        for j in range(N):
            if cost[i][j] > cost[i][k] + cost[k][j]:
                cost[i][j] = cost[i][k] + cost[k][j] i range(N) range N for j in range(N):
            if cost[i][j] > cost[i][k] + cost[k][j]:
                cost[i][j] = cost[i][k] + cost[k][j] j range(N) range N if cost[i][j] > cost[i][k] + cost[k][j]:
                cost[i][j] = cost[i][k] + cost[k][j] cost[i][j] > cost[i][k] + cost[k][j] cost[i][j] [i] cost i j cost[i][k] + cost[k][j] cost[i][k] [i] cost i k cost[k][j] [k] cost k j cost[i][j] = cost[i][k] + cost[k][j] cost[i][j] [i] cost i j cost[i][k] + cost[k][j] cost[i][k] [i] cost i k cost[k][j] [k] cost k j q = int(input()) q int(input()) int input() input for _ in range(q):
    s, t = map(int, input().split())
    if cost[s-1][t-1] == INF:
        print(-1)
    else:
        print(cost[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 if cost[s-1][t-1] == INF:
        print(-1)
    else:
        print(cost[s-1][t-1] - 1) cost[s-1][t-1] == INF cost[s-1][t-1] [s-1] cost s-1 s 1 t-1 t 1 INF print(-1) print -1 print(cost[s-1][t-1] - 1) print cost[s-1][t-1] - 1 cost[s-1][t-1] [s-1] cost s-1 s 1 t-1 t 1 1 v1, v2 = v1-1, v2-1 v1-1 v1 input = sys.stdin.readline sys.stdin.readline input INF = float("INF") float("INF") INF N, M, L = map(int, input().split()) map(int, input().split()) N v2, w = map(int, input().split()) map(int, input().split()) v2 w = map(int, input().split()) map(int, input().split()) w cost = [[INF] * N for _ in range(N)] [[INF] * N for _ in range(N)] cost M, L = map(int, input().split()) map(int, input().split()) M v2 = v1-1, v2-1 v2-1 v2 v1, v2, w = map(int, input().split()) map(int, input().split()) v1 q = int(input()) int(input()) q s, t = map(int, input().split()) map(int, input().split()) s t = map(int, input().split()) map(int, input().split()) t L = map(int, input().split()) map(int, input().split()) L
# -*- coding: utf-8 -*-
# E

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

import sys
input = sys.stdin.readline

INF = float("INF")

N, M, L = map(int, input().split())

cost = [[INF] * N for _ in range(N)]
for i in range(N):
    cost[i][i] = 0

for _ in range(M):
    v1, v2, w = map(int, input().split())
    v1, v2 = v1-1, v2-1
    cost[v1][v2] = w
    cost[v2][v1] = w

for k in range(N):
    for i in range(N):
        for j in range(N):
            if cost[i][j] > cost[i][k] + cost[k][j]:
                cost[i][j] = cost[i][k] + cost[k][j]

for i in range(N):
    for j in range(N):
        if cost[i][j] == 0:
            continue
        elif cost[i][j] <= L:
            cost[i][j] = 1
        else:
            cost[i][j] = INF

for k in range(N):
    for i in range(N):
        for j in range(N):
            if cost[i][j] > cost[i][k] + cost[k][j]:
                cost[i][j] = cost[i][k] + cost[k][j]

q = int(input())
for _ in range(q):
    s, t = map(int, input().split())
    if cost[s-1][t-1] == INF:
        print(-1)
    else:
        print(cost[s-1][t-1] - 1)
