n, m, l = map(int, input().split())
def warshall_floyd(d, v):
    for k in range(v):
        for i in range(v):
            for j in range(v):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])

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

warshall_floyd(d, n)

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

warshall_floyd(e, n)


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

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

warshall_floyd(d, n)

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

warshall_floyd(e, n)


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