import sys
input = sys.stdin.readline
inf = 1000
inf5 = 10**10
n, m, l = map(int, input().split())
graph = [[inf5] * (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

inf = 1000


def warshall_floyd(d):
    for k in range(1, n+1):
        for i in range(1, n+1):
            for j in range(1, n+1):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])


warshall_floyd(graph)

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

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

 import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline inf = 1000 inf 1000 inf5 = 10**10 inf5 10**10 10 10 n, m, l = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m l [inf5] * (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) [inf5] * (n+1) [inf5] inf5 n+1 n 1 graph = [[inf5] * (n+1) for _ in range(n+1)] graph [[inf5] * (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 inf = 1000 inf 1000 def warshall_floyd(d):
    for k in range(1, n+1):
        for i in range(1, n+1):
            for j in range(1, n+1):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]) warshall_floyd for k in range(1, n+1):
        for i in range(1, n+1):
            for j in range(1, n+1):
                d[i][j] = min(d[i][j], d[i][k] + d[k][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):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]) i range(1, n+1) range 1 n+1 n 1 for j in range(1, n+1):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]) j range(1, n+1) range 1 n+1 n 1 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 warshall_floyd(graph) warshall_floyd graph [inf] * (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) [inf] * (n+1) [inf] inf n+1 n 1 ans = [[inf] * (n+1) for _ in range(n+1)] ans [[inf] * (n+1) for _ in range(n+1)] for i in range(1, n+1):
    for j in range(1, n+1):
        if graph[i][j] <= l:
            ans[i][j] = 1 i range(1, n+1) range 1 n+1 n 1 for j in range(1, n+1):
        if graph[i][j] <= l:
            ans[i][j] = 1 j range(1, n+1) range 1 n+1 n 1 if graph[i][j] <= l:
            ans[i][j] = 1 graph[i][j] <= l graph[i][j] [i] graph i j l ans[i][j] = 1 ans[i][j] [i] ans i j 1 warshall_floyd(ans) warshall_floyd ans q = int(input()) q int(input()) int input() input for _ in range(q):
    s, t = map(int, input().split())
    if ans[s][t] == inf:
        print(-1)
        continue
    print(ans[s][t] - 1) _ range(q) range q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t if ans[s][t] == inf:
        print(-1)
        continue
     ans[s][t] == inf ans[s][t] [s] ans s t inf print(-1) print -1 continue print(ans[s][t] - 1) print ans[s][t] - 1 ans[s][t] [s] ans s t 1 m, l = map(int, input().split()) map(int, input().split()) m l = map(int, input().split()) map(int, input().split()) l b, c = map(int, input().split()) map(int, input().split()) b s, t = map(int, input().split()) map(int, input().split()) s ans = [[inf] * (n+1) for _ in range(n+1)] [[inf] * (n+1) for _ in range(n+1)] ans input = sys.stdin.readline sys.stdin.readline input graph = [[inf5] * (n+1) for _ in range(n+1)] [[inf5] * (n+1) for _ in range(n+1)] graph inf5 = 10**10 10**10 inf5 c = map(int, input().split()) map(int, input().split()) c q = int(input()) int(input()) q n, m, l = map(int, input().split()) map(int, input().split()) n a, b, c = map(int, input().split()) map(int, input().split()) a inf = 1000 1000 inf def warshall_floyd(d):
    for k in range(1, n+1):
        for i in range(1, n+1):
            for j in range(1, n+1):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]) def warshall_floyd(d):
    for k in range(1, n+1):
        for i in range(1, n+1):
            for j in range(1, n+1):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]) warshall_floyd t = map(int, input().split()) map(int, input().split()) t inf = 1000 1000 inf
import sys
input = sys.stdin.readline
inf = 1000
inf5 = 10**10
n, m, l = map(int, input().split())
graph = [[inf5] * (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

inf = 1000


def warshall_floyd(d):
    for k in range(1, n+1):
        for i in range(1, n+1):
            for j in range(1, n+1):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])


warshall_floyd(graph)

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

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


