import sys
import copy

N, M, L = list(map(int, sys.stdin.readline().strip().split(" ")))
INF = 10**10

def warshall_floyd(g_mat):
    dp = copy.copy(g_mat)
    
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j])
    return dp

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

for _ in range(M):
    a, b, c = list(map(int, sys.stdin.readline().strip().split(" ")))
    graph[a-1][b-1] = c
    graph[b-1][a-1] = c

dist_graph = warshall_floyd(graph)
bool_graph = [[INF for _ in range(N)] for _ in range(N)]

for i in range(N):
    for j in range(N):
        if dist_graph[i][j] <= L:
            bool_graph[i][j] = 1

ans_graph = warshall_floyd(bool_graph)

Q = int(sys.stdin.readline().strip())
for _ in range(Q):
    s, t = list(map(int, sys.stdin.readline().strip().split(" ")))
    ans = ans_graph[s-1][t-1]
    print(ans-1 if ans != INF else -1)

     import sys sys import copy copy N, M, L = list(map(int, sys.stdin.readline().strip().split(" "))) N list(map(int, sys.stdin.readline().strip().split(" "))) list map(int, sys.stdin.readline().strip().split(" ")) map int sys.stdin.readline().strip().split(" ") sys.stdin.readline().strip().split sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip split " " M L INF = 10**10 INF 10**10 10 10 def warshall_floyd(g_mat):
    dp = copy.copy(g_mat)
    
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j])
    return dp warshall_floyd dp = copy.copy(g_mat) dp copy.copy(g_mat) copy.copy copy copy g_mat for k in range(N):
        for i in range(N):
            for j in range(N):
                dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j])
     k range(N) range N for i in range(N):
            for j in range(N):
                dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j])
     i range(N) range N for j in range(N):
                dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j])
     j range(N) range N dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j]) dp[i][j] [i] dp i j min(dp[i][j], dp[i][k]+dp[k][j]) min dp[i][j] [i] dp i j dp[i][k]+dp[k][j] dp[i][k] [i] dp i k dp[k][j] [k] dp k j return dp dp g_mat g_mat [INF for _ in range(N)] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF for _ in range(N)] graph = [[INF for _ in range(N)] for _ in range(N)] graph [[INF for _ in range(N)] for _ in range(N)] for _ in range(M):
    a, b, c = list(map(int, sys.stdin.readline().strip().split(" ")))
    graph[a-1][b-1] = c
    graph[b-1][a-1] = c _ range(M) range M a, b, c = list(map(int, sys.stdin.readline().strip().split(" "))) a list(map(int, sys.stdin.readline().strip().split(" "))) list map(int, sys.stdin.readline().strip().split(" ")) map int sys.stdin.readline().strip().split(" ") sys.stdin.readline().strip().split sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip split " " b c graph[a-1][b-1] = c graph[a-1][b-1] [a-1] graph a-1 a 1 b-1 b 1 c graph[b-1][a-1] = c graph[b-1][a-1] [b-1] graph b-1 b 1 a-1 a 1 c dist_graph = warshall_floyd(graph) dist_graph warshall_floyd(graph) warshall_floyd graph [INF for _ in range(N)] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF for _ in range(N)] bool_graph = [[INF for _ in range(N)] for _ in range(N)] bool_graph [[INF for _ in range(N)] for _ in range(N)] for i in range(N):
    for j in range(N):
        if dist_graph[i][j] <= L:
            bool_graph[i][j] = 1 i range(N) range N for j in range(N):
        if dist_graph[i][j] <= L:
            bool_graph[i][j] = 1 j range(N) range N if dist_graph[i][j] <= L:
            bool_graph[i][j] = 1 dist_graph[i][j] <= L dist_graph[i][j] [i] dist_graph i j L bool_graph[i][j] = 1 bool_graph[i][j] [i] bool_graph i j 1 ans_graph = warshall_floyd(bool_graph) ans_graph warshall_floyd(bool_graph) warshall_floyd bool_graph Q = int(sys.stdin.readline().strip()) Q int(sys.stdin.readline().strip()) int sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip for _ in range(Q):
    s, t = list(map(int, sys.stdin.readline().strip().split(" ")))
    ans = ans_graph[s-1][t-1]
    print(ans-1 if ans != INF else -1)

     _ range(Q) range Q s, t = list(map(int, sys.stdin.readline().strip().split(" "))) s list(map(int, sys.stdin.readline().strip().split(" "))) list map(int, sys.stdin.readline().strip().split(" ")) map int sys.stdin.readline().strip().split(" ") sys.stdin.readline().strip().split sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip split " " t ans = ans_graph[s-1][t-1] ans ans_graph[s-1][t-1] [s-1] ans_graph s-1 s 1 t-1 t 1 print(ans-1 if ans != INF else -1) print ans-1 if ans != INF else -1 ans != INF ans INF ans-1 ans 1 -1 ans_graph = warshall_floyd(bool_graph) warshall_floyd(bool_graph) ans_graph dist_graph = warshall_floyd(graph) warshall_floyd(graph) dist_graph graph = [[INF for _ in range(N)] for _ in range(N)] [[INF for _ in range(N)] for _ in range(N)] graph Q = int(sys.stdin.readline().strip()) int(sys.stdin.readline().strip()) Q c = list(map(int, sys.stdin.readline().strip().split(" "))) list(map(int, sys.stdin.readline().strip().split(" "))) c a, b, c = list(map(int, sys.stdin.readline().strip().split(" "))) list(map(int, sys.stdin.readline().strip().split(" "))) a b, c = list(map(int, sys.stdin.readline().strip().split(" "))) list(map(int, sys.stdin.readline().strip().split(" "))) b L = list(map(int, sys.stdin.readline().strip().split(" "))) list(map(int, sys.stdin.readline().strip().split(" "))) L INF = 10**10 10**10 INF def warshall_floyd(g_mat):
    dp = copy.copy(g_mat)
    
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j])
    return dp def warshall_floyd(g_mat):
    dp = copy.copy(g_mat)
    
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j])
    return dp warshall_floyd ans = ans_graph[s-1][t-1] ans_graph[s-1][t-1] ans t = list(map(int, sys.stdin.readline().strip().split(" "))) list(map(int, sys.stdin.readline().strip().split(" "))) t bool_graph = [[INF for _ in range(N)] for _ in range(N)] [[INF for _ in range(N)] for _ in range(N)] bool_graph M, L = list(map(int, sys.stdin.readline().strip().split(" "))) list(map(int, sys.stdin.readline().strip().split(" "))) M s, t = list(map(int, sys.stdin.readline().strip().split(" "))) list(map(int, sys.stdin.readline().strip().split(" "))) s N, M, L = list(map(int, sys.stdin.readline().strip().split(" "))) list(map(int, sys.stdin.readline().strip().split(" "))) N
import sys
import copy

N, M, L = list(map(int, sys.stdin.readline().strip().split(" ")))
INF = 10**10

def warshall_floyd(g_mat):
    dp = copy.copy(g_mat)
    
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j])
    return dp

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

for _ in range(M):
    a, b, c = list(map(int, sys.stdin.readline().strip().split(" ")))
    graph[a-1][b-1] = c
    graph[b-1][a-1] = c

dist_graph = warshall_floyd(graph)
bool_graph = [[INF for _ in range(N)] for _ in range(N)]

for i in range(N):
    for j in range(N):
        if dist_graph[i][j] <= L:
            bool_graph[i][j] = 1

ans_graph = warshall_floyd(bool_graph)

Q = int(sys.stdin.readline().strip())
for _ in range(Q):
    s, t = list(map(int, sys.stdin.readline().strip().split(" ")))
    ans = ans_graph[s-1][t-1]
    print(ans-1 if ans != INF else -1)

    
