n, m, l = [int(i) for i in input().split()]
d = [[10 ** 18] * n for _ in range(n)]
for i in range(n):
    d[i][i] = 0

for _ in range(m):
    a, b, c = [int(i) for i in input().split()]
    a -= 1
    b -= 1
    d[a][b] = min(d[a][b], c)
    d[b][a] = min(d[b][a], c)

for i in range(n):
    for j in range(n):
        for k in range(n):
            d[j][k] = min(d[j][k], d[j][i] + d[i][k])

d2 = [[10 ** 18] * n for _ in range(n)]
for i in range(n):
    d2[i][i] = 0

for i in range(n):
    for j in range(n):
        if d[i][j] <= l:
            d2[i][j] = min(d2[i][j], 1)

for i in range(n):
    for j in range(n):
        for k in range(n):
            d2[j][k] = min(d2[j][k], d2[j][i] + d2[i][k])

q = int(input())
for _ in range(q):
    s, t = [int(i) - 1 for i in input().split()]
    if d2[s][t] == 10 ** 18:
        print(-1)
    else:
        print(d2[s][t]-1) int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i n, m, l = [int(i) for i in input().split()] n [int(i) for i in input().split()] m l [10 ** 18] * n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [10 ** 18] * n [10 ** 18] 10 ** 18 10 18 n d = [[10 ** 18] * n for _ in range(n)] d [[10 ** 18] * n for _ in range(n)] for i in range(n):
    d[i][i] = 0 i range(n) range n d[i][i] = 0 d[i][i] [i] d i i 0 for _ in range(m):
    a, b, c = [int(i) for i in input().split()]
    a -= 1
    b -= 1
    d[a][b] = min(d[a][b], c)
    d[b][a] = min(d[b][a], c) _ range(m) range m int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i a, b, c = [int(i) for i in input().split()] a [int(i) for i in input().split()] b c a -= 1 a 1 b -= 1 b 1 d[a][b] = min(d[a][b], c) d[a][b] [a] d a b min(d[a][b], c) min d[a][b] [a] d a b c d[b][a] = min(d[b][a], c) d[b][a] [b] d b a min(d[b][a], c) min d[b][a] [b] d b a c for i in range(n):
    for j in range(n):
        for k in range(n):
            d[j][k] = min(d[j][k], d[j][i] + d[i][k]) i range(n) range n for j in range(n):
        for k in range(n):
            d[j][k] = min(d[j][k], d[j][i] + d[i][k]) j range(n) range n for k in range(n):
            d[j][k] = min(d[j][k], d[j][i] + d[i][k]) k range(n) range n d[j][k] = min(d[j][k], d[j][i] + d[i][k]) d[j][k] [j] d j k min(d[j][k], d[j][i] + d[i][k]) min d[j][k] [j] d j k d[j][i] + d[i][k] d[j][i] [j] d j i d[i][k] [i] d i k [10 ** 18] * n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [10 ** 18] * n [10 ** 18] 10 ** 18 10 18 n d2 = [[10 ** 18] * n for _ in range(n)] d2 [[10 ** 18] * n for _ in range(n)] for i in range(n):
    d2[i][i] = 0 i range(n) range n d2[i][i] = 0 d2[i][i] [i] d2 i i 0 for i in range(n):
    for j in range(n):
        if d[i][j] <= l:
            d2[i][j] = min(d2[i][j], 1) i range(n) range n for j in range(n):
        if d[i][j] <= l:
            d2[i][j] = min(d2[i][j], 1) j range(n) range n if d[i][j] <= l:
            d2[i][j] = min(d2[i][j], 1) d[i][j] <= l d[i][j] [i] d i j l d2[i][j] = min(d2[i][j], 1) d2[i][j] [i] d2 i j min(d2[i][j], 1) min d2[i][j] [i] d2 i j 1 for i in range(n):
    for j in range(n):
        for k in range(n):
            d2[j][k] = min(d2[j][k], d2[j][i] + d2[i][k]) i range(n) range n for j in range(n):
        for k in range(n):
            d2[j][k] = min(d2[j][k], d2[j][i] + d2[i][k]) j range(n) range n for k in range(n):
            d2[j][k] = min(d2[j][k], d2[j][i] + d2[i][k]) k range(n) range n d2[j][k] = min(d2[j][k], d2[j][i] + d2[i][k]) d2[j][k] [j] d2 j k min(d2[j][k], d2[j][i] + d2[i][k]) min d2[j][k] [j] d2 j k d2[j][i] + d2[i][k] d2[j][i] [j] d2 j i d2[i][k] [i] d2 i k q = int(input()) q int(input()) int input() input for _ in range(q):
    s, t = [int(i) - 1 for i in input().split()]
    if d2[s][t] == 10 ** 18:
        print(-1)
    else:
        print(d2[s][t]-1) _ range(q) range q int(i) - 1 for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) - 1 int(i) int i 1 s, t = [int(i) - 1 for i in input().split()] s [int(i) - 1 for i in input().split()] t if d2[s][t] == 10 ** 18:
        print(-1)
    else:
        print(d2[s][t]-1) d2[s][t] == 10 ** 18 d2[s][t] [s] d2 s t 10 ** 18 10 18 print(-1) print -1 print(d2[s][t]-1) print d2[s][t]-1 d2[s][t] [s] d2 s t 1 n, m, l = [int(i) for i in input().split()] [int(i) for i in input().split()] n l = [int(i) for i in input().split()] [int(i) for i in input().split()] l t = [int(i) - 1 for i in input().split()] [int(i) - 1 for i in input().split()] t b, c = [int(i) for i in input().split()] [int(i) for i in input().split()] b a -= 1 1 a q = int(input()) int(input()) q c = [int(i) for i in input().split()] [int(i) for i in input().split()] c b -= 1 1 b a, b, c = [int(i) for i in input().split()] [int(i) for i in input().split()] a s, t = [int(i) - 1 for i in input().split()] [int(i) - 1 for i in input().split()] s m, l = [int(i) for i in input().split()] [int(i) for i in input().split()] m d2 = [[10 ** 18] * n for _ in range(n)] [[10 ** 18] * n for _ in range(n)] d2 d = [[10 ** 18] * n for _ in range(n)] [[10 ** 18] * n for _ in range(n)] d
n, m, l = [int(i) for i in input().split()]
d = [[10 ** 18] * n for _ in range(n)]
for i in range(n):
    d[i][i] = 0

for _ in range(m):
    a, b, c = [int(i) for i in input().split()]
    a -= 1
    b -= 1
    d[a][b] = min(d[a][b], c)
    d[b][a] = min(d[b][a], c)

for i in range(n):
    for j in range(n):
        for k in range(n):
            d[j][k] = min(d[j][k], d[j][i] + d[i][k])

d2 = [[10 ** 18] * n for _ in range(n)]
for i in range(n):
    d2[i][i] = 0

for i in range(n):
    for j in range(n):
        if d[i][j] <= l:
            d2[i][j] = min(d2[i][j], 1)

for i in range(n):
    for j in range(n):
        for k in range(n):
            d2[j][k] = min(d2[j][k], d2[j][i] + d2[i][k])

q = int(input())
for _ in range(q):
    s, t = [int(i) - 1 for i in input().split()]
    if d2[s][t] == 10 ** 18:
        print(-1)
    else:
        print(d2[s][t]-1)
