import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
N, M, L = map(int, input().split())
dist = [[INF] * N for _ in range(N)]
for i in range(M):
    a, b, c = map(int, input().split())
    if c > L:
        continue
    a -= 1
    b -= 1
    dist[a][b] = c
    dist[b][a] = c
Q = int(input())

for k in range(N):
    for i in range(N):
        for j in range(N):
            if dist[i][j] > dist[i][k] + dist[k][j]:
                dist[i][j] = dist[i][k] + dist[k][j]
fuel = [[INF] * N for _ in range(N)]
for i in range(N):
    for j in range(N):
        fuel[i][j] = 1 if dist[i][j] <= L else INF
for k in range(N):
    for i in range(N):
        for j in range(N):
            if fuel[i][j] > fuel[i][k] + fuel[k][j]:
                fuel[i][j] = fuel[i][k] + fuel[k][j]
for i in range(Q):
    s,t = map(int, input().split())
    if fuel[s - 1][t - 1] != INF:
        print(fuel[s - 1][t - 1] - 1)
    else:
        print(-1) import sys sys import itertools itertools import time time import math math from heapq import heappop, heappush from collections import defaultdict from collections import Counter from collections import deque sys.setrecursionlimit(10 ** 7) sys.setrecursionlimit sys setrecursionlimit 10 ** 7 10 7 INF = 10 ** 18 INF 10 ** 18 10 18 MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline readlines = sys.stdin.buffer.readlines readlines sys.stdin.buffer.readlines sys.stdin.buffer sys.stdin sys stdin buffer readlines 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 dist = [[INF] * N for _ in range(N)] dist [[INF] * N for _ in range(N)] for i in range(M):
    a, b, c = map(int, input().split())
    if c > L:
        continue
    a -= 1
    b -= 1
    dist[a][b] = c
    dist[b][a] = c i 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 if c > L:
        continue
     c > L c L continue a -= 1 a 1 b -= 1 b 1 dist[a][b] = c dist[a][b] [a] dist a b c dist[b][a] = c dist[b][a] [b] dist b a c Q = int(input()) Q int(input()) int input() input for k in range(N):
    for i in range(N):
        for j in range(N):
            if dist[i][j] > dist[i][k] + dist[k][j]:
                dist[i][j] = dist[i][k] + dist[k][j] k range(N) range N for i in range(N):
        for j in range(N):
            if dist[i][j] > dist[i][k] + dist[k][j]:
                dist[i][j] = dist[i][k] + dist[k][j] i range(N) range N for j in range(N):
            if dist[i][j] > dist[i][k] + dist[k][j]:
                dist[i][j] = dist[i][k] + dist[k][j] j range(N) range N if dist[i][j] > dist[i][k] + dist[k][j]:
                dist[i][j] = dist[i][k] + dist[k][j] dist[i][j] > dist[i][k] + dist[k][j] dist[i][j] [i] dist i j dist[i][k] + dist[k][j] dist[i][k] [i] dist i k dist[k][j] [k] dist k j dist[i][j] = dist[i][k] + dist[k][j] dist[i][j] [i] dist i j dist[i][k] + dist[k][j] dist[i][k] [i] dist i k dist[k][j] [k] dist k j [INF] * N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF] * N [INF] INF N fuel = [[INF] * N for _ in range(N)] fuel [[INF] * N for _ in range(N)] for i in range(N):
    for j in range(N):
        fuel[i][j] = 1 if dist[i][j] <= L else INF i range(N) range N for j in range(N):
        fuel[i][j] = 1 if dist[i][j] <= L else INF j range(N) range N fuel[i][j] = 1 if dist[i][j] <= L else INF fuel[i][j] [i] fuel i j 1 if dist[i][j] <= L else INF dist[i][j] <= L dist[i][j] [i] dist i j L 1 INF for k in range(N):
    for i in range(N):
        for j in range(N):
            if fuel[i][j] > fuel[i][k] + fuel[k][j]:
                fuel[i][j] = fuel[i][k] + fuel[k][j] k range(N) range N for i in range(N):
        for j in range(N):
            if fuel[i][j] > fuel[i][k] + fuel[k][j]:
                fuel[i][j] = fuel[i][k] + fuel[k][j] i range(N) range N for j in range(N):
            if fuel[i][j] > fuel[i][k] + fuel[k][j]:
                fuel[i][j] = fuel[i][k] + fuel[k][j] j range(N) range N if fuel[i][j] > fuel[i][k] + fuel[k][j]:
                fuel[i][j] = fuel[i][k] + fuel[k][j] fuel[i][j] > fuel[i][k] + fuel[k][j] fuel[i][j] [i] fuel i j fuel[i][k] + fuel[k][j] fuel[i][k] [i] fuel i k fuel[k][j] [k] fuel k j fuel[i][j] = fuel[i][k] + fuel[k][j] fuel[i][j] [i] fuel i j fuel[i][k] + fuel[k][j] fuel[i][k] [i] fuel i k fuel[k][j] [k] fuel k j for i in range(Q):
    s,t = map(int, input().split())
    if fuel[s - 1][t - 1] != INF:
        print(fuel[s - 1][t - 1] - 1)
    else:
        print(-1) i range(Q) range Q s,t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t if fuel[s - 1][t - 1] != INF:
        print(fuel[s - 1][t - 1] - 1)
    else:
        print(-1) fuel[s - 1][t - 1] != INF fuel[s - 1][t - 1] [s - 1] fuel s - 1 s 1 t - 1 t 1 INF print(fuel[s - 1][t - 1] - 1) print fuel[s - 1][t - 1] - 1 fuel[s - 1][t - 1] [s - 1] fuel s - 1 s 1 t - 1 t 1 1 print(-1) print -1 M, L = map(int, input().split()) map(int, input().split()) M N, M, L = map(int, input().split()) map(int, input().split()) N readlines = sys.stdin.buffer.readlines sys.stdin.buffer.readlines readlines dist = [[INF] * N for _ in range(N)] [[INF] * N for _ in range(N)] dist b -= 1 1 b INF = 10 ** 18 10 ** 18 INF c = map(int, input().split()) map(int, input().split()) c MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD read = sys.stdin.buffer.read sys.stdin.buffer.read read fuel = [[INF] * N for _ in range(N)] [[INF] * N for _ in range(N)] fuel a, b, c = map(int, input().split()) map(int, input().split()) a b, c = map(int, input().split()) map(int, input().split()) b L = map(int, input().split()) map(int, input().split()) L a -= 1 1 a Q = int(input()) int(input()) Q t = map(int, input().split()) map(int, input().split()) t s,t = map(int, input().split()) map(int, input().split()) s readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
N, M, L = map(int, input().split())
dist = [[INF] * N for _ in range(N)]
for i in range(M):
    a, b, c = map(int, input().split())
    if c > L:
        continue
    a -= 1
    b -= 1
    dist[a][b] = c
    dist[b][a] = c
Q = int(input())

for k in range(N):
    for i in range(N):
        for j in range(N):
            if dist[i][j] > dist[i][k] + dist[k][j]:
                dist[i][j] = dist[i][k] + dist[k][j]
fuel = [[INF] * N for _ in range(N)]
for i in range(N):
    for j in range(N):
        fuel[i][j] = 1 if dist[i][j] <= L else INF
for k in range(N):
    for i in range(N):
        for j in range(N):
            if fuel[i][j] > fuel[i][k] + fuel[k][j]:
                fuel[i][j] = fuel[i][k] + fuel[k][j]
for i in range(Q):
    s,t = map(int, input().split())
    if fuel[s - 1][t - 1] != INF:
        print(fuel[s - 1][t - 1] - 1)
    else:
        print(-1)