import sys



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

lines = sys.stdin.readlines()

INF = 10 ** 18



dists = [[INF] * n for _ in range(n)]



for i in range(n):

    dists[i][i] = 0



for line in lines[:m]:

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

    a -= 1

    b -= 1

    if c > l:

        continue

    dists[a][b] = c

    dists[b][a] = c



for k in range(n):

    dk = dists[k]

    for i in range(n):

        di = dists[i]

        for j in range(n):

            new_dist = di[k] + dk[j]

            if new_dist > l:

                continue

            if di[j] > new_dist:

                di[j] = new_dist



refuels = [[1 if dist < INF else INF for dist in row] for row in dists]



for k in range(n):

    rk = refuels[k]

    for i in range(n):

        ri = refuels[i]

        for j in range(n):

            new_dist = ri[k] + rk[j]

            if ri[j] > new_dist:

                ri[j] = new_dist



buf = []



for line in lines[m + 1:]:

    s, t = list(map(int, line.split()))

    refuel = refuels[s - 1][t - 1]

    buf.append(-1 if refuel == INF else refuel - 1)



print(('\n'.join(map(str, buf))))

import sys



import numpy as np

from scipy.sparse import csr_matrix

from scipy.sparse.csgraph import floyd_warshall



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

lines = sys.stdin.readlines()

INF = 10 ** 18



dists = [[INF] * n for _ in range(n)]



for i in range(n):

    dists[i][i] = 0



for line in lines[:m]:

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

    a -= 1

    b -= 1

    if c > l:

        continue

    dists[a][b] = c

    dists[b][a] = c



dists = floyd_warshall(csr_matrix(dists))

refuels = np.ones((n, n), dtype=np.int64)

refuels[dists > l] = INF

refuels = floyd_warshall(csr_matrix(refuels)).astype(np.int64)

refuels[refuels == INF] = 0

refuels -= 1



buf = []



for line in lines[m + 1:]:

    s, t = list(map(int, line.split()))

    buf.append(refuels[s - 1][t - 1])



print(('\n'.join(map(str, buf))))

import sys

n, m, l = list(map(int, input().split()))
lines = sys.stdin.readlines()
INF = 10**18
dists = [[INF] * n for _ in range(n)]
for i in range(n):
    dists[i][i] = 0
for line in lines[:m]:
    a, b, c = list(map(int, line.split()))
    a -= 1
    b -= 1
    if c > l:
        continue
    dists[a][b] = c
    dists[b][a] = c
for k in range(n):
    dk = dists[k]
    for i in range(n):
        di = dists[i]
        for j in range(n):
            new_dist = di[k] + dk[j]
            if new_dist > l:
                continue
            if di[j] > new_dist:
                di[j] = new_dist
refuels = [[1 if dist < INF else INF for dist in row] for row in dists]
for k in range(n):
    rk = refuels[k]
    for i in range(n):
        ri = refuels[i]
        for j in range(n):
            new_dist = ri[k] + rk[j]
            if ri[j] > new_dist:
                ri[j] = new_dist
buf = []
for line in lines[m + 1 :]:
    s, t = list(map(int, line.split()))
    refuel = refuels[s - 1][t - 1]
    buf.append(-1 if refuel == INF else refuel - 1)
print(("\n".join(map(str, buf))))

import sys
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

n, m, l = list(map(int, input().split()))
lines = sys.stdin.readlines()
INF = 10**18
dists = [[INF] * n for _ in range(n)]
for i in range(n):
    dists[i][i] = 0
for line in lines[:m]:
    a, b, c = list(map(int, line.split()))
    a -= 1
    b -= 1
    if c > l:
        continue
    dists[a][b] = c
    dists[b][a] = c
dists = floyd_warshall(csr_matrix(dists))
refuels = np.ones((n, n), dtype=np.int64)
refuels[dists > l] = INF
refuels = floyd_warshall(csr_matrix(refuels)).astype(np.int64)
refuels[refuels == INF] = 0
refuels -= 1
buf = []
for line in lines[m + 1 :]:
    s, t = list(map(int, line.split()))
    buf.append(refuels[s - 1][t - 1])
print(("\n".join(map(str, buf))))

+import numpy as np +from scipy.sparse import csr_matrix +from scipy.sparse.csgraph import floyd_warshall -for k in range(n): -    dk = dists[k] -    for i in range(n): -        di = dists[i] -        for j in range(n): -            new_dist = di[k] + dk[j] -            if new_dist > l: -                continue -            if di[j] > new_dist: -                di[j] = new_dist -refuels = [[1 if dist < INF else INF for dist in row] for row in dists] -for k in range(n): -    rk = refuels[k] -    for i in range(n): -        ri = refuels[i] -        for j in range(n): -            new_dist = ri[k] + rk[j] -            if ri[j] > new_dist: -                ri[j] = new_dist +dists = floyd_warshall(csr_matrix(dists)) +refuels = np.ones((n, n), dtype=np.int64) +refuels[dists > l] = INF +refuels = floyd_warshall(csr_matrix(refuels)).astype(np.int64) +refuels[refuels == INF] = 0 +refuels -= 1 -    refuel = refuels[s - 1][t - 1] -    buf.append(-1 if refuel == INF else refuel - 1) +    buf.append(refuels[s - 1][t - 1])