n,m,l=list(map(int,input().split()))

cost=[[10**9+1]*n for i in range(n)]

length=[[10**9]*n for i in range(n)]

for i in range(m):

    a,b,c=list(map(int,input().split()))

    a-=1

    b-=1

    cost[a][b]=c

    cost[b][a]=c

q=int(eval(input()))

st=[list(map(int,input().split()))for i in range(q)]



for k in range(n):

    for i in range(n):

        for j in range(n):

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

for i in range(n):

    length[i][i]=0

for i in range(n):

    for j in range(n):

        if cost[i][j]<=l:

            length[i][j]=0

for k in range(n):

    for i in range(n):

        for j in range(n):

            length[i][j]=min(length[i][j],length[i][k]+length[k][j]+1)

for s,t in st:

    ch=min(length[s-1][t-1],length[t-1][s-1])

    print((-1 if ch>10**8 else ch))
import numpy as np

from scipy.sparse import lil_matrix, csr_matrix

from scipy.sparse.csgraph import shortest_path



n,m,limit=list(map(int,input().split()))

G=np.zeros((n,n),dtype=np.int64)

for i in range(m):

    a,b,cost=list(map(int,input().split()))

    G[a-1,b-1]=cost

    G[b-1,a-1]=cost

G=shortest_path(G,method='FW')

for c in range(n):

    for l in range(n):

        if G[c][l]<=limit:

            G[c][l]=1

        else:

            G[c][l]=0

G=shortest_path(G,method='FW')

q=int(eval(input()))

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

for a,b in Q:

    print((int(G[a-1][b-1])-1 if G[a-1][b-1]<10**18 else -1))
n, m, l = list(map(int, input().split()))
cost = [[10**9 + 1] * n for i in range(n)]
length = [[10**9] * n for i in range(n)]
for i in range(m):
    a, b, c = list(map(int, input().split()))
    a -= 1
    b -= 1
    cost[a][b] = c
    cost[b][a] = c
q = int(eval(input()))
st = [list(map(int, input().split())) for i in range(q)]
for k in range(n):
    for i in range(n):
        for j in range(n):
            cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])
for i in range(n):
    length[i][i] = 0
for i in range(n):
    for j in range(n):
        if cost[i][j] <= l:
            length[i][j] = 0
for k in range(n):
    for i in range(n):
        for j in range(n):
            length[i][j] = min(length[i][j], length[i][k] + length[k][j] + 1)
for s, t in st:
    ch = min(length[s - 1][t - 1], length[t - 1][s - 1])
    print((-1 if ch > 10**8 else ch))

import numpy as np
from scipy.sparse import lil_matrix, csr_matrix
from scipy.sparse.csgraph import shortest_path

n, m, limit = list(map(int, input().split()))
G = np.zeros((n, n), dtype=np.int64)
for i in range(m):
    a, b, cost = list(map(int, input().split()))
    G[a - 1, b - 1] = cost
    G[b - 1, a - 1] = cost
G = shortest_path(G, method="FW")
for c in range(n):
    for l in range(n):
        if G[c][l] <= limit:
            G[c][l] = 1
        else:
            G[c][l] = 0
G = shortest_path(G, method="FW")
q = int(eval(input()))
Q = [list(map(int, input().split())) for i in range(q)]
for a, b in Q:
    print((int(G[a - 1][b - 1]) - 1 if G[a - 1][b - 1] < 10**18 else -1))

-n, m, l = list(map(int, input().split())) -cost = [[10**9 + 1] * n for i in range(n)] -length = [[10**9] * n for i in range(n)] +import numpy as np +from scipy.sparse import lil_matrix, csr_matrix +from scipy.sparse.csgraph import shortest_path + +n, m, limit = list(map(int, input().split())) +G = np.zeros((n, n), dtype=np.int64) -    a, b, c = list(map(int, input().split())) -    a -= 1 -    b -= 1 -    cost[a][b] = c -    cost[b][a] = c +    a, b, cost = list(map(int, input().split())) +    G[a - 1, b - 1] = cost +    G[b - 1, a - 1] = cost +G = shortest_path(G, method="FW") +for c in range(n): +    for l in range(n): +        if G[c][l] <= limit: +            G[c][l] = 1 +        else: +            G[c][l] = 0 +G = shortest_path(G, method="FW") -st = [list(map(int, input().split())) for i in range(q)] -for k in range(n): -    for i in range(n): -        for j in range(n): -            cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]) -for i in range(n): -    length[i][i] = 0 -for i in range(n): -    for j in range(n): -        if cost[i][j] <= l: -            length[i][j] = 0 -for k in range(n): -    for i in range(n): -        for j in range(n): -            length[i][j] = min(length[i][j], length[i][k] + length[k][j] + 1) -for s, t in st: -    ch = min(length[s - 1][t - 1], length[t - 1][s - 1]) -    print((-1 if ch > 10**8 else ch)) +Q = [list(map(int, input().split())) for i in range(q)] +for a, b in Q: +    print((int(G[a - 1][b - 1]) - 1 if G[a - 1][b - 1] < 10**18 else -1))