inf = 10 ** 13

n, m, l = map(int, input().split())

d = [[inf] * n for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    d[a - 1][b - 1] = d[b - 1][a - 1] = c
for k in range(n):
    for i in range(n):
        for j in range(n):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j])

e = [[1 if d[i][j] <= l else inf for j in range(n)] for i in range(n)]
for k in range(n):
    for i in range(n):
        for j in range(n):
            e[i][j] = min(e[i][j], e[i][k] + e[k][j])

q = int(input())
for _ in range(q):
    s, t = map(int, input().split())
    a = e[s - 1][t - 1]
    print(a - 1 if a < inf else -1) inf = 10 ** 13 inf 10 ** 13 10 13 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 d = [[inf] * n for _ in range(n)] d [[inf] * n for _ in range(n)] for _ in range(m):
    a, b, c = map(int, input().split())
    d[a - 1][b - 1] = d[b - 1][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 d[a - 1][b - 1] = d[b - 1][a - 1] = c d[a - 1][b - 1] [a - 1] d a - 1 a 1 b - 1 b 1 c = d[b - 1][a - 1] = c d[b - 1][a - 1] [b - 1] d b - 1 b 1 a - 1 a 1 c for k in range(n):
    for i in range(n):
        for j in range(n):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j]) k range(n) range n for i in range(n):
        for j in range(n):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j]) i range(n) range n for j in range(n):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j]) j range(n) range n d[i][j] = min(d[i][j], d[i][k] + d[k][j]) d[i][j] [i] d i j min(d[i][j], d[i][k] + d[k][j]) min d[i][j] [i] d i j d[i][k] + d[k][j] d[i][k] [i] d i k d[k][j] [k] d k j [1 if d[i][j] <= l else inf for j in range(n)] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [1 if d[i][j] <= l else inf for j in range(n)] e = [[1 if d[i][j] <= l else inf for j in range(n)] for i in range(n)] e [[1 if d[i][j] <= l else inf for j in range(n)] for i in range(n)] for k in range(n):
    for i in range(n):
        for j in range(n):
            e[i][j] = min(e[i][j], e[i][k] + e[k][j]) k range(n) range n for i in range(n):
        for j in range(n):
            e[i][j] = min(e[i][j], e[i][k] + e[k][j]) i range(n) range n for j in range(n):
            e[i][j] = min(e[i][j], e[i][k] + e[k][j]) j range(n) range n e[i][j] = min(e[i][j], e[i][k] + e[k][j]) e[i][j] [i] e i j min(e[i][j], e[i][k] + e[k][j]) min e[i][j] [i] e i j e[i][k] + e[k][j] e[i][k] [i] e i k e[k][j] [k] e k j q = int(input()) q int(input()) int input() input for _ in range(q):
    s, t = map(int, input().split())
    a = e[s - 1][t - 1]
    print(a - 1 if a < 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 a = e[s - 1][t - 1] a e[s - 1][t - 1] [s - 1] e s - 1 s 1 t - 1 t 1 print(a - 1 if a < inf else -1) print a - 1 if a < inf else -1 a < inf a inf a - 1 a 1 -1 q = int(input()) int(input()) q m, l = map(int, input().split()) map(int, input().split()) m a, b, c = map(int, input().split()) map(int, input().split()) a b, c = map(int, input().split()) map(int, input().split()) b s, t = map(int, input().split()) map(int, input().split()) s l = map(int, input().split()) map(int, input().split()) l t = map(int, input().split()) map(int, input().split()) t d = [[inf] * n for _ in range(n)] [[inf] * n for _ in range(n)] d a = e[s - 1][t - 1] e[s - 1][t - 1] a e = [[1 if d[i][j] <= l else inf for j in range(n)] for i in range(n)] [[1 if d[i][j] <= l else inf for j in range(n)] for i in range(n)] e n, m, l = map(int, input().split()) map(int, input().split()) n inf = 10 ** 13 10 ** 13 inf c = map(int, input().split()) map(int, input().split()) c
inf = 10 ** 13

n, m, l = map(int, input().split())

d = [[inf] * n for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    d[a - 1][b - 1] = d[b - 1][a - 1] = c
for k in range(n):
    for i in range(n):
        for j in range(n):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j])

e = [[1 if d[i][j] <= l else inf for j in range(n)] for i in range(n)]
for k in range(n):
    for i in range(n):
        for j in range(n):
            e[i][j] = min(e[i][j], e[i][k] + e[k][j])

q = int(input())
for _ in range(q):
    s, t = map(int, input().split())
    a = e[s - 1][t - 1]
    print(a - 1 if a < inf else -1)
