#!/usr/bin/env python3

N, M, L = [int(s) for s in input().split()]
edge = [[int(s) for s in input().split()] for _ in range(M)]
dist = [[10 ** 10] * N for _ in range(N)]
graph = [[] for _ in range(N)]
Q = int(input())

for i, j, w in edge:
    dist[i - 1][j - 1] = w
    dist[j - 1][i - 1] = w

for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

for i in range(N):
    for j in range(N):
        dist[i][j] = 1 if dist[i][j] <= L else 10 ** 10

for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])


for _ in range(Q):
    s, t = [int(a) - 1 for a in input().split()]
    print(dist[s][t] - 1 if dist[s][t] < 10**10 else -1) int(s) for s in input().split() for s in input().split() s input().split() ().split () input split for s in input().split() int(s) int s N, M, L = [int(s) for s in input().split()] N [int(s) for s in input().split()] M L [int(s) for s in input().split()] for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) [int(s) for s in input().split()] edge = [[int(s) for s in input().split()] for _ in range(M)] edge [[int(s) for s in input().split()] for _ in range(M)] [10 ** 10] * N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [10 ** 10] * N [10 ** 10] 10 ** 10 10 10 N dist = [[10 ** 10] * N for _ in range(N)] dist [[10 ** 10] * N for _ in range(N)] [] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [] graph = [[] for _ in range(N)] graph [[] for _ in range(N)] Q = int(input()) Q int(input()) int input() input for i, j, w in edge:
    dist[i - 1][j - 1] = w
    dist[j - 1][i - 1] = w i j w edge dist[i - 1][j - 1] = w dist[i - 1][j - 1] [i - 1] dist i - 1 i 1 j - 1 j 1 w dist[j - 1][i - 1] = w dist[j - 1][i - 1] [j - 1] dist j - 1 j 1 i - 1 i 1 w for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) k range(N) range N for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) i range(N) range N for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) j range(N) range N dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) dist[i][j] [i] dist i j min(dist[i][j], dist[i][k] + dist[k][j]) min 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 for i in range(N):
    for j in range(N):
        dist[i][j] = 1 if dist[i][j] <= L else 10 ** 10 i range(N) range N for j in range(N):
        dist[i][j] = 1 if dist[i][j] <= L else 10 ** 10 j range(N) range N dist[i][j] = 1 if dist[i][j] <= L else 10 ** 10 dist[i][j] [i] dist i j 1 if dist[i][j] <= L else 10 ** 10 dist[i][j] <= L dist[i][j] [i] dist i j L 1 10 ** 10 10 10 for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) k range(N) range N for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) i range(N) range N for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) j range(N) range N dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) dist[i][j] [i] dist i j min(dist[i][j], dist[i][k] + dist[k][j]) min 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 for _ in range(Q):
    s, t = [int(a) - 1 for a in input().split()]
    print(dist[s][t] - 1 if dist[s][t] < 10**10 else -1) _ range(Q) range Q int(a) - 1 for a in input().split() for a in input().split() a input().split() ().split () input split for a in input().split() int(a) - 1 int(a) int a 1 s, t = [int(a) - 1 for a in input().split()] s [int(a) - 1 for a in input().split()] t print(dist[s][t] - 1 if dist[s][t] < 10**10 else -1) print dist[s][t] - 1 if dist[s][t] < 10**10 else -1 dist[s][t] < 10**10 dist[s][t] [s] dist s t 10**10 10 10 dist[s][t] - 1 dist[s][t] [s] dist s t 1 -1 graph = [[] for _ in range(N)] [[] for _ in range(N)] graph t = [int(a) - 1 for a in input().split()] [int(a) - 1 for a in input().split()] t edge = [[int(s) for s in input().split()] for _ in range(M)] [[int(s) for s in input().split()] for _ in range(M)] edge L = [int(s) for s in input().split()] [int(s) for s in input().split()] L M, L = [int(s) for s in input().split()] [int(s) for s in input().split()] M dist = [[10 ** 10] * N for _ in range(N)] [[10 ** 10] * N for _ in range(N)] dist Q = int(input()) int(input()) Q s, t = [int(a) - 1 for a in input().split()] [int(a) - 1 for a in input().split()] s N, M, L = [int(s) for s in input().split()] [int(s) for s in input().split()] N
#!/usr/bin/env python3

N, M, L = [int(s) for s in input().split()]
edge = [[int(s) for s in input().split()] for _ in range(M)]
dist = [[10 ** 10] * N for _ in range(N)]
graph = [[] for _ in range(N)]
Q = int(input())

for i, j, w in edge:
    dist[i - 1][j - 1] = w
    dist[j - 1][i - 1] = w

for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

for i in range(N):
    for j in range(N):
        dist[i][j] = 1 if dist[i][j] <= L else 10 ** 10

for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])


for _ in range(Q):
    s, t = [int(a) - 1 for a in input().split()]
    print(dist[s][t] - 1 if dist[s][t] < 10**10 else -1)