import sys

input = sys.stdin.buffer.readline

n, m, limit = map(int, input().split())
infi = 10 ** 15
graph = [[infi] * (n + 1) for _ in range(n + 1)]
step = [[infi] * (n + 1) for _ in range(n + 1)]
for _ in range(m):
    a, b, c = map(int, input().split())
    graph[a][b] = c
    graph[b][a] = c
for i in range(1, n + 1):
    graph[i][i] = 0
for k in range(1, n + 1):
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            graph[i][j] = min(graph[i][k] + graph[k][j], graph[i][j])
for i in range(1, n + 1):
    for j in range(1, n + 1):
        if graph[i][j] <= limit:
            graph[i][j] = 1
        elif graph[i][j] == 0:
            graph[i][j] = 0
        else:
            graph[i][j] = infi
for k in range(1, n + 1):
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            graph[i][j] = min(graph[i][k] + graph[k][j], graph[i][j])


q = int(input())
for _ in range(q):
    a, b = map(int, input().split())
    if graph[a][b] == infi:
        graph[a][b] = 0
    print(graph[a][b] - 1 if graph[i][j] != infi else -1) import sys sys input = sys.stdin.buffer.readline input sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline n, m, limit = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m limit infi = 10 ** 15 infi 10 ** 15 10 15 [infi] * (n + 1) for _ in range(n + 1) for _ in range(n + 1) _ range(n + 1) range n + 1 n 1 for _ in range(n + 1) [infi] * (n + 1) [infi] infi n + 1 n 1 graph = [[infi] * (n + 1) for _ in range(n + 1)] graph [[infi] * (n + 1) for _ in range(n + 1)] [infi] * (n + 1) for _ in range(n + 1) for _ in range(n + 1) _ range(n + 1) range n + 1 n 1 for _ in range(n + 1) [infi] * (n + 1) [infi] infi n + 1 n 1 step = [[infi] * (n + 1) for _ in range(n + 1)] step [[infi] * (n + 1) for _ in range(n + 1)] for _ in range(m):
    a, b, c = map(int, input().split())
    graph[a][b] = c
    graph[b][a] = 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 graph[a][b] = c graph[a][b] [a] graph a b c graph[b][a] = c graph[b][a] [b] graph b a c for i in range(1, n + 1):
    graph[i][i] = 0 i range(1, n + 1) range 1 n + 1 n 1 graph[i][i] = 0 graph[i][i] [i] graph i i 0 for k in range(1, n + 1):
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            graph[i][j] = min(graph[i][k] + graph[k][j], graph[i][j]) k range(1, n + 1) range 1 n + 1 n 1 for i in range(1, n + 1):
        for j in range(1, n + 1):
            graph[i][j] = min(graph[i][k] + graph[k][j], graph[i][j]) i range(1, n + 1) range 1 n + 1 n 1 for j in range(1, n + 1):
            graph[i][j] = min(graph[i][k] + graph[k][j], graph[i][j]) j range(1, n + 1) range 1 n + 1 n 1 graph[i][j] = min(graph[i][k] + graph[k][j], graph[i][j]) graph[i][j] [i] graph i j min(graph[i][k] + graph[k][j], graph[i][j]) min graph[i][k] + graph[k][j] graph[i][k] [i] graph i k graph[k][j] [k] graph k j graph[i][j] [i] graph i j for i in range(1, n + 1):
    for j in range(1, n + 1):
        if graph[i][j] <= limit:
            graph[i][j] = 1
        elif graph[i][j] == 0:
            graph[i][j] = 0
        else:
            graph[i][j] = infi i range(1, n + 1) range 1 n + 1 n 1 for j in range(1, n + 1):
        if graph[i][j] <= limit:
            graph[i][j] = 1
        elif graph[i][j] == 0:
            graph[i][j] = 0
        else:
            graph[i][j] = infi j range(1, n + 1) range 1 n + 1 n 1 if graph[i][j] <= limit:
            graph[i][j] = 1
        elif graph[i][j] == 0:
            graph[i][j] = 0
        else:
            graph[i][j] = infi graph[i][j] <= limit graph[i][j] [i] graph i j limit graph[i][j] = 1 graph[i][j] [i] graph i j 1 elif graph[i][j] == 0:
            graph[i][j] = 0
         graph[i][j] == 0 graph[i][j] [i] graph i j 0 graph[i][j] = 0 graph[i][j] [i] graph i j 0 graph[i][j] = infi graph[i][j] [i] graph i j infi for k in range(1, n + 1):
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            graph[i][j] = min(graph[i][k] + graph[k][j], graph[i][j]) k range(1, n + 1) range 1 n + 1 n 1 for i in range(1, n + 1):
        for j in range(1, n + 1):
            graph[i][j] = min(graph[i][k] + graph[k][j], graph[i][j]) i range(1, n + 1) range 1 n + 1 n 1 for j in range(1, n + 1):
            graph[i][j] = min(graph[i][k] + graph[k][j], graph[i][j]) j range(1, n + 1) range 1 n + 1 n 1 graph[i][j] = min(graph[i][k] + graph[k][j], graph[i][j]) graph[i][j] [i] graph i j min(graph[i][k] + graph[k][j], graph[i][j]) min graph[i][k] + graph[k][j] graph[i][k] [i] graph i k graph[k][j] [k] graph k j graph[i][j] [i] graph i j q = int(input()) q int(input()) int input() input for _ in range(q):
    a, b = map(int, input().split())
    if graph[a][b] == infi:
        graph[a][b] = 0
    print(graph[a][b] - 1 if graph[i][j] != infi else -1) _ range(q) range q a, b = map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b if graph[a][b] == infi:
        graph[a][b] = 0
     graph[a][b] == infi graph[a][b] [a] graph a b infi graph[a][b] = 0 graph[a][b] [a] graph a b 0 print(graph[a][b] - 1 if graph[i][j] != infi else -1) print graph[a][b] - 1 if graph[i][j] != infi else -1 graph[i][j] != infi graph[i][j] [i] graph i j infi graph[a][b] - 1 graph[a][b] [a] graph a b 1 -1 q = int(input()) int(input()) q m, limit = map(int, input().split()) map(int, input().split()) m a, b, c = map(int, input().split()) map(int, input().split()) a c = map(int, input().split()) map(int, input().split()) c a, b = map(int, input().split()) map(int, input().split()) a input = sys.stdin.buffer.readline sys.stdin.buffer.readline input step = [[infi] * (n + 1) for _ in range(n + 1)] [[infi] * (n + 1) for _ in range(n + 1)] step graph = [[infi] * (n + 1) for _ in range(n + 1)] [[infi] * (n + 1) for _ in range(n + 1)] graph limit = map(int, input().split()) map(int, input().split()) limit b, c = map(int, input().split()) map(int, input().split()) b b = map(int, input().split()) map(int, input().split()) b infi = 10 ** 15 10 ** 15 infi n, m, limit = map(int, input().split()) map(int, input().split()) n
import sys

input = sys.stdin.buffer.readline

n, m, limit = map(int, input().split())
infi = 10 ** 15
graph = [[infi] * (n + 1) for _ in range(n + 1)]
step = [[infi] * (n + 1) for _ in range(n + 1)]
for _ in range(m):
    a, b, c = map(int, input().split())
    graph[a][b] = c
    graph[b][a] = c
for i in range(1, n + 1):
    graph[i][i] = 0
for k in range(1, n + 1):
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            graph[i][j] = min(graph[i][k] + graph[k][j], graph[i][j])
for i in range(1, n + 1):
    for j in range(1, n + 1):
        if graph[i][j] <= limit:
            graph[i][j] = 1
        elif graph[i][j] == 0:
            graph[i][j] = 0
        else:
            graph[i][j] = infi
for k in range(1, n + 1):
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            graph[i][j] = min(graph[i][k] + graph[k][j], graph[i][j])


q = int(input())
for _ in range(q):
    a, b = map(int, input().split())
    if graph[a][b] == infi:
        graph[a][b] = 0
    print(graph[a][b] - 1 if graph[i][j] != infi else -1)
