N, M, L = list(map(int, input().split()))

edges = [list(map(int, input().split())) for _ in range(M)]

Q = int(eval(input()))

X = [list(map(int, input().split())) for _ in range(Q)]



INF = 10 ** 9 + 6

graph = [[INF] * N for _ in range(N)]



for i in range(N):

    graph[i][i] = 0



for u, v, l in edges:

    graph[u - 1][v - 1] = l

    graph[v - 1][u - 1] = l



for k in range(N):

    for i in range(N):

        if graph[i][k] == INF:

            continue

        for j in range(N):

            if graph[k][j] == INF:

                continue

            graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])



cnt = [[INF] * N for _ in range(N)]



for i in range(N):

    cnt[i][i] = 0



for i in range(N):

    for j in range(N):

        if i == j:

            continue

        if graph[i][j] <= L:

            cnt[i][j] = 1

            cnt[j][i] = 1



for k in range(N):

    for i in range(N):

        if cnt[i][k] == INF:

            continue

        for j in range(N):

            if cnt[k][j] == INF:

                continue

            cnt[i][j] = min(cnt[i][j], cnt[i][k] + cnt[k][j])



for s, t in X:

    if cnt[s - 1][t - 1] == INF:

        print((-1))

    else:

        print((cnt[s - 1][t - 1] - 1))

N, M, L = list(map(int, input().split()))

X = [list(map(int, input().split())) for _ in range(M)]

Q = int(eval(input()))

Y = [list(map(int, input().split())) for _ in range(Q)]



inf = 10 ** 9 + 7

graph = [[inf] * N for _ in range(N)]

count = [[inf] * N for _ in range(N)]



for i in range(N):

    graph[i][i] = 0

    count[i][i] = 0

    

for a, b, c in X:

    graph[a - 1][b - 1] = c

    graph[b - 1][a - 1] = c



for k in range(N):

    for i in range(N):

        for j in range(N):

            graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])



for i in range(N):

    for j in range(N):

        if i != j and graph[i][j] <= L:

            count[i][j] = 1



for k in range(N):

    for i in range(N):

        for j in range(N):

            count[i][j] = min(count[i][j], count[i][k] + count[k][j])



for s, t in Y:

    if count[s - 1][t - 1] == inf:

        print((-1))

    else:

        print((count[s - 1][t - 1] - 1))

N, M, L = list(map(int, input().split()))
edges = [list(map(int, input().split())) for _ in range(M)]
Q = int(eval(input()))
X = [list(map(int, input().split())) for _ in range(Q)]
INF = 10**9 + 6
graph = [[INF] * N for _ in range(N)]
for i in range(N):
    graph[i][i] = 0
for u, v, l in edges:
    graph[u - 1][v - 1] = l
    graph[v - 1][u - 1] = l
for k in range(N):
    for i in range(N):
        if graph[i][k] == INF:
            continue
        for j in range(N):
            if graph[k][j] == INF:
                continue
            graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])
cnt = [[INF] * N for _ in range(N)]
for i in range(N):
    cnt[i][i] = 0
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        if graph[i][j] <= L:
            cnt[i][j] = 1
            cnt[j][i] = 1
for k in range(N):
    for i in range(N):
        if cnt[i][k] == INF:
            continue
        for j in range(N):
            if cnt[k][j] == INF:
                continue
            cnt[i][j] = min(cnt[i][j], cnt[i][k] + cnt[k][j])
for s, t in X:
    if cnt[s - 1][t - 1] == INF:
        print((-1))
    else:
        print((cnt[s - 1][t - 1] - 1))

N, M, L = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(M)]
Q = int(eval(input()))
Y = [list(map(int, input().split())) for _ in range(Q)]
inf = 10**9 + 7
graph = [[inf] * N for _ in range(N)]
count = [[inf] * N for _ in range(N)]
for i in range(N):
    graph[i][i] = 0
    count[i][i] = 0
for a, b, c in X:
    graph[a - 1][b - 1] = c
    graph[b - 1][a - 1] = c
for k in range(N):
    for i in range(N):
        for j in range(N):
            graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])
for i in range(N):
    for j in range(N):
        if i != j and graph[i][j] <= L:
            count[i][j] = 1
for k in range(N):
    for i in range(N):
        for j in range(N):
            count[i][j] = min(count[i][j], count[i][k] + count[k][j])
for s, t in Y:
    if count[s - 1][t - 1] == inf:
        print((-1))
    else:
        print((count[s - 1][t - 1] - 1))

-edges = [list(map(int, input().split())) for _ in range(M)] +X = [list(map(int, input().split())) for _ in range(M)] -X = [list(map(int, input().split())) for _ in range(Q)] -INF = 10**9 + 6 -graph = [[INF] * N for _ in range(N)] +Y = [list(map(int, input().split())) for _ in range(Q)] +inf = 10**9 + 7 +graph = [[inf] * N for _ in range(N)] +count = [[inf] * N for _ in range(N)] -for u, v, l in edges: -    graph[u - 1][v - 1] = l -    graph[v - 1][u - 1] = l +    count[i][i] = 0 +for a, b, c in X: +    graph[a - 1][b - 1] = c +    graph[b - 1][a - 1] = c -        if graph[i][k] == INF: -            continue -            if graph[k][j] == INF: -                continue -cnt = [[INF] * N for _ in range(N)] -for i in range(N): -    cnt[i][i] = 0 -        if i == j: -            continue -        if graph[i][j] <= L: -            cnt[i][j] = 1 -            cnt[j][i] = 1 +        if i != j and graph[i][j] <= L: +            count[i][j] = 1 -        if cnt[i][k] == INF: -            continue -            if cnt[k][j] == INF: -                continue -            cnt[i][j] = min(cnt[i][j], cnt[i][k] + cnt[k][j]) -for s, t in X: -    if cnt[s - 1][t - 1] == INF: +            count[i][j] = min(count[i][j], count[i][k] + count[k][j]) +for s, t in Y: +    if count[s - 1][t - 1] == inf: -        print((cnt[s - 1][t - 1] - 1)) +        print((count[s - 1][t - 1] - 1))