import sys
input = sys.stdin.readline

N, M, L = map(int, input().split())
inf = 10**15
V = [[] for _ in range(N)]

for _ in range(M):
    A, B, C = map(int, input().split())
    if C>L:continue
    V[A-1].append((B-1, C))
    V[B-1].append((A-1, C))

dists = []
for i in range(N):
    dist = [(inf,inf)] * N
    dist[i] = (0, 0)
    u = [False] * N
    for _ in range(N):
        (charged, used), j = min([(dist[i], i) for i in range(N) if not u[i]])
        u[j] = True
        for k, next_cost in V[j]:
            if j==k: continue
            c = (charged+1, next_cost) if used+next_cost>L else (charged, used+next_cost)
            if dist[k] > c:
                dist[k] = c
    dists.append(dist)

Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    ans = dists[s-1][t-1][0]
    print(ans if ans!=inf else -1) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L inf = 10**15 inf 10**15 10 15 [] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [] V = [[] for _ in range(N)] V [[] for _ in range(N)] for _ in range(M):
    A, B, C = map(int, input().split())
    if C>L:continue
    V[A-1].append((B-1, C))
    V[B-1].append((A-1, C)) _ 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 V[A-1].append((B-1, C)) [A-1].append [A-1] V A-1 A 1 append (B-1, C) B-1 B 1 C V[B-1].append((A-1, C)) [B-1].append [B-1] V B-1 B 1 append (A-1, C) A-1 A 1 C dists = [] dists [] for i in range(N):
    dist = [(inf,inf)] * N
    dist[i] = (0, 0)
    u = [False] * N
    for _ in range(N):
        (charged, used), j = min([(dist[i], i) for i in range(N) if not u[i]])
        u[j] = True
        for k, next_cost in V[j]:
            if j==k: continue
            c = (charged+1, next_cost) if used+next_cost>L else (charged, used+next_cost)
            if dist[k] > c:
                dist[k] = c
    dists.append(dist) i range(N) range N dist = [(inf,inf)] * N dist [(inf,inf)] * N [(inf,inf)] (inf,inf) inf inf N dist[i] = (0, 0) dist[i] dist i (0, 0) 0 0 u = [False] * N u [False] * N [False] False N for _ in range(N):
        (charged, used), j = min([(dist[i], i) for i in range(N) if not u[i]])
        u[j] = True
        for k, next_cost in V[j]:
            if j==k: continue
            c = (charged+1, next_cost) if used+next_cost>L else (charged, used+next_cost)
            if dist[k] > c:
                dist[k] = c
     _ range(N) range N (dist[i], i) for i in range(N) if not u[i] for i in range(N) if not u[i] i range(N) range N not u[i] u[i] u i if not u[i] (dist[i], i) dist[i] dist i i (charged, used), j = min([(dist[i], i) for i in range(N) if not u[i]]) (charged, used) charged used min([(dist[i], i) for i in range(N) if not u[i]]) min [(dist[i], i) for i in range(N) if not u[i]] j u[j] = True u[j] u j True for k, next_cost in V[j]:
            if j==k: continue
            c = (charged+1, next_cost) if used+next_cost>L else (charged, used+next_cost)
            if dist[k] > c:
                dist[k] = c
     k next_cost V[j] V j if j==k: continue
             j==k j k c = (charged+1, next_cost) if used+next_cost>L else (charged, used+next_cost) c (charged+1, next_cost) if used+next_cost>L else (charged, used+next_cost) used+next_cost>L used+next_cost used next_cost L (charged+1, next_cost) charged+1 charged 1 next_cost (charged, used+next_cost) charged used+next_cost used next_cost if dist[k] > c:
                dist[k] = c
     dist[k] > c dist[k] dist k c dist[k] = c dist[k] dist k c dists.append(dist) dists.append dists append dist Q = int(input()) Q int(input()) int input() input for _ in range(Q):
    s, t = map(int, input().split())
    ans = dists[s-1][t-1][0]
    print(ans if ans!=inf else -1) _ range(Q) range Q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t ans = dists[s-1][t-1][0] ans dists[s-1][t-1][0] [t-1] [s-1] dists s-1 s 1 t-1 t 1 0 print(ans if ans!=inf else -1) print ans if ans!=inf else -1 ans!=inf ans inf ans -1 dist = [(inf,inf)] * N [(inf,inf)] * N dist s, t = map(int, input().split()) map(int, input().split()) s j = min([(dist[i], i) for i in range(N) if not u[i]]) min([(dist[i], i) for i in range(N) if not u[i]]) j input = sys.stdin.readline sys.stdin.readline input t = map(int, input().split()) map(int, input().split()) t Q = int(input()) int(input()) Q N, M, L = map(int, input().split()) map(int, input().split()) N dists = [] [] dists B, C = map(int, input().split()) map(int, input().split()) B ans = dists[s-1][t-1][0] dists[s-1][t-1][0] ans inf = 10**15 10**15 inf V = [[] for _ in range(N)] [[] for _ in range(N)] V c = (charged+1, next_cost) if used+next_cost>L else (charged, used+next_cost) (charged+1, next_cost) if used+next_cost>L else (charged, used+next_cost) c L = map(int, input().split()) map(int, input().split()) L A, B, C = map(int, input().split()) map(int, input().split()) A C = map(int, input().split()) map(int, input().split()) C u = [False] * N [False] * N u M, L = map(int, input().split()) map(int, input().split()) M
import sys
input = sys.stdin.readline

N, M, L = map(int, input().split())
inf = 10**15
V = [[] for _ in range(N)]

for _ in range(M):
    A, B, C = map(int, input().split())
    if C>L:continue
    V[A-1].append((B-1, C))
    V[B-1].append((A-1, C))

dists = []
for i in range(N):
    dist = [(inf,inf)] * N
    dist[i] = (0, 0)
    u = [False] * N
    for _ in range(N):
        (charged, used), j = min([(dist[i], i) for i in range(N) if not u[i]])
        u[j] = True
        for k, next_cost in V[j]:
            if j==k: continue
            c = (charged+1, next_cost) if used+next_cost>L else (charged, used+next_cost)
            if dist[k] > c:
                dist[k] = c
    dists.append(dist)

Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    ans = dists[s-1][t-1][0]
    print(ans if ans!=inf else -1)
