import sys
sys.setrecursionlimit(10000000)
input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
import functools
import itertools
import math
INF = float('inf')
MOD = 10**9+7

def dijkstra(s, edges):
    dist = [INF] * len(edges)
    dist[s], h = 0, []
    heappush(h, (0, s))
    while (len(h)):
        dv, v = heappop(h)
        if dv > dist[v]:
            continue
        for u, cost in edges[v]:
            if dv + cost < dist[u]:
                dist[u] = dv + cost
                heappush(h, (dist[u], u))
    return dist

N, M, L = map(int, input().split())
es = [[INF] * N for i in range(N)]
for i in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    es[a][b] = es[b][a] = c
for i in range(N):
    es[i][i] = 0
for k in range(N):
    for i in range(N):
        for j in range(N):
            tmp = es[i][k] + es[k][j]
            if tmp < es[i][j]:
                es[i][j] = tmp
es2 = [[] for i in range(N)]
for i in range(N-1):
    for j in range(i+1, N):
        if es[i][j] <= L:
            es2[i].append((j, 1))
            es2[j].append((i, 1))
dist = [dijkstra(i, es2) for i in range(N)]
Q = int(input())
for i in range(Q):
    s, t = map(lambda x: int(x)-1, input().split())
    ans = dist[s][t]
    if ans == INF:
        ans = 0
    print(ans-1) import sys sys sys.setrecursionlimit(10000000) sys.setrecursionlimit sys setrecursionlimit 10000000 input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline from bisect import * from collections import * from heapq import * import functools functools import itertools itertools import math math INF = float('inf') INF float('inf') float 'inf' MOD = 10**9+7 MOD 10**9+7 10**9 10 9 7 def dijkstra(s, edges):
    dist = [INF] * len(edges)
    dist[s], h = 0, []
    heappush(h, (0, s))
    while (len(h)):
        dv, v = heappop(h)
        if dv > dist[v]:
            continue
        for u, cost in edges[v]:
            if dv + cost < dist[u]:
                dist[u] = dv + cost
                heappush(h, (dist[u], u))
    return dist dijkstra dist = [INF] * len(edges) dist [INF] * len(edges) [INF] INF len(edges) len edges dist[s], h = 0, [] dist[s] dist s 0 h [] heappush(h, (0, s)) heappush h (0, s) 0 s while (len(h)):
        dv, v = heappop(h)
        if dv > dist[v]:
            continue
        for u, cost in edges[v]:
            if dv + cost < dist[u]:
                dist[u] = dv + cost
                heappush(h, (dist[u], u))
     len(h) len h dv, v = heappop(h) dv heappop(h) heappop h v if dv > dist[v]:
            continue
         dv > dist[v] dv dist[v] dist v continue for u, cost in edges[v]:
            if dv + cost < dist[u]:
                dist[u] = dv + cost
                heappush(h, (dist[u], u))
     u cost edges[v] edges v if dv + cost < dist[u]:
                dist[u] = dv + cost
                heappush(h, (dist[u], u))
     dv + cost < dist[u] dv + cost dv cost dist[u] dist u dist[u] = dv + cost dist[u] dist u dv + cost dv cost heappush(h, (dist[u], u)) heappush h (dist[u], u) dist[u] dist u u return dist dist s s edges edges N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L [INF] * N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [INF] * N [INF] INF N es = [[INF] * N for i in range(N)] es [[INF] * N for i in range(N)] for i in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    es[a][b] = es[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 a -= 1 a 1 b -= 1 b 1 es[a][b] = es[b][a] = c es[a][b] [a] es a b c = es[b][a] = c es[b][a] [b] es b a c for i in range(N):
    es[i][i] = 0 i range(N) range N es[i][i] = 0 es[i][i] [i] es i i 0 for k in range(N):
    for i in range(N):
        for j in range(N):
            tmp = es[i][k] + es[k][j]
            if tmp < es[i][j]:
                es[i][j] = tmp k range(N) range N for i in range(N):
        for j in range(N):
            tmp = es[i][k] + es[k][j]
            if tmp < es[i][j]:
                es[i][j] = tmp i range(N) range N for j in range(N):
            tmp = es[i][k] + es[k][j]
            if tmp < es[i][j]:
                es[i][j] = tmp j range(N) range N tmp = es[i][k] + es[k][j] tmp es[i][k] + es[k][j] es[i][k] [i] es i k es[k][j] [k] es k j if tmp < es[i][j]:
                es[i][j] = tmp tmp < es[i][j] tmp es[i][j] [i] es i j es[i][j] = tmp es[i][j] [i] es i j tmp [] for i in range(N) for i in range(N) i range(N) range N for i in range(N) [] es2 = [[] for i in range(N)] es2 [[] for i in range(N)] for i in range(N-1):
    for j in range(i+1, N):
        if es[i][j] <= L:
            es2[i].append((j, 1))
            es2[j].append((i, 1)) i range(N-1) range N-1 N 1 for j in range(i+1, N):
        if es[i][j] <= L:
            es2[i].append((j, 1))
            es2[j].append((i, 1)) j range(i+1, N) range i+1 i 1 N if es[i][j] <= L:
            es2[i].append((j, 1))
            es2[j].append((i, 1)) es[i][j] <= L es[i][j] [i] es i j L es2[i].append((j, 1)) [i].append [i] es2 i append (j, 1) j 1 es2[j].append((i, 1)) [j].append [j] es2 j append (i, 1) i 1 dijkstra(i, es2) for i in range(N) for i in range(N) i range(N) range N for i in range(N) dijkstra(i, es2) dijkstra i es2 dist = [dijkstra(i, es2) for i in range(N)] dist [dijkstra(i, es2) for i in range(N)] Q = int(input()) Q int(input()) int input() input for i in range(Q):
    s, t = map(lambda x: int(x)-1, input().split())
    ans = dist[s][t]
    if ans == INF:
        ans = 0
    print(ans-1) i range(Q) range Q s, t = map(lambda x: int(x)-1, input().split()) s map(lambda x: int(x)-1, input().split()) map lambda x: int(x)-1 int(x)-1 int(x) int x 1 x input().split() ().split () input split t ans = dist[s][t] ans dist[s][t] [s] dist s t if ans == INF:
        ans = 0
     ans == INF ans INF ans = 0 ans 0 print(ans-1) print ans-1 ans 1 N, M, L = map(int, input().split()) map(int, input().split()) N M, L = map(int, input().split()) map(int, input().split()) M s, t = map(lambda x: int(x)-1, input().split()) map(lambda x: int(x)-1, input().split()) s dist = [dijkstra(i, es2) for i in range(N)] [dijkstra(i, es2) for i in range(N)] dist b, c = map(int, input().split()) map(int, input().split()) b INF = float('inf') float('inf') INF ans = 0 0 ans es = [[INF] * N for i in range(N)] [[INF] * N for i in range(N)] es def dijkstra(s, edges):
    dist = [INF] * len(edges)
    dist[s], h = 0, []
    heappush(h, (0, s))
    while (len(h)):
        dv, v = heappop(h)
        if dv > dist[v]:
            continue
        for u, cost in edges[v]:
            if dv + cost < dist[u]:
                dist[u] = dv + cost
                heappush(h, (dist[u], u))
    return dist def dijkstra(s, edges):
    dist = [INF] * len(edges)
    dist[s], h = 0, []
    heappush(h, (0, s))
    while (len(h)):
        dv, v = heappop(h)
        if dv > dist[v]:
            continue
        for u, cost in edges[v]:
            if dv + cost < dist[u]:
                dist[u] = dv + cost
                heappush(h, (dist[u], u))
    return dist dijkstra a -= 1 1 a es2 = [[] for i in range(N)] [[] for i in range(N)] es2 b -= 1 1 b c = map(int, input().split()) map(int, input().split()) c L = map(int, input().split()) map(int, input().split()) L Q = int(input()) int(input()) Q MOD = 10**9+7 10**9+7 MOD ans = dist[s][t] dist[s][t] ans input = sys.stdin.readline sys.stdin.readline input t = map(lambda x: int(x)-1, input().split()) map(lambda x: int(x)-1, input().split()) t tmp = es[i][k] + es[k][j] es[i][k] + es[k][j] tmp a, b, c = map(int, input().split()) map(int, input().split()) a
import sys
sys.setrecursionlimit(10000000)
input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
import functools
import itertools
import math
INF = float('inf')
MOD = 10**9+7

def dijkstra(s, edges):
    dist = [INF] * len(edges)
    dist[s], h = 0, []
    heappush(h, (0, s))
    while (len(h)):
        dv, v = heappop(h)
        if dv > dist[v]:
            continue
        for u, cost in edges[v]:
            if dv + cost < dist[u]:
                dist[u] = dv + cost
                heappush(h, (dist[u], u))
    return dist

N, M, L = map(int, input().split())
es = [[INF] * N for i in range(N)]
for i in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    es[a][b] = es[b][a] = c
for i in range(N):
    es[i][i] = 0
for k in range(N):
    for i in range(N):
        for j in range(N):
            tmp = es[i][k] + es[k][j]
            if tmp < es[i][j]:
                es[i][j] = tmp
es2 = [[] for i in range(N)]
for i in range(N-1):
    for j in range(i+1, N):
        if es[i][j] <= L:
            es2[i].append((j, 1))
            es2[j].append((i, 1))
dist = [dijkstra(i, es2) for i in range(N)]
Q = int(input())
for i in range(Q):
    s, t = map(lambda x: int(x)-1, input().split())
    ans = dist[s][t]
    if ans == INF:
        ans = 0
    print(ans-1)
