# ABC143E - Travel by Car
def floyd_warshall(dist):
    """
    Compute the shortest paths of all pairs and modify dist.
    """
    V = len(dist)
    for i in range(V):  # intermediate point
        for j, c2 in enumerate(dist[j][i] for j in range(V)):  #  source
            for k, (c1, c3) in enumerate(zip(dist[j], dist[i])):  # target
                if c2 + c3 < c1:
                    dist[j][k] = c2 + c3


def main():
    # FW -> once more FW to edges <= L
    N, M, L, *X = map(int, open(0).read().split())
    ABC, ST = X[: 3 * M], X[3 * M + 1 :]
    INF = 1 << 60
    dist = [[INF] * (N + 1) for _ in range(N + 1)]
    for i in range(N + 1):
        dist[i][i] = 0
    for v, u, cost in zip(*[iter(ABC)] * 3):
        dist[v][u] = dist[u][v] = cost
    floyd_warshall(dist)

    # assume distance within L as 1 and compute the number of fueling
    modified_dist = [[1 if x <= L else INF for x in d] for d in dist]
    floyd_warshall(modified_dist)
    ans = [
        modified_dist[s][t] - 1 if modified_dist[s][t] < INF else -1
        for s, t in zip(*[iter(ST)] * 2)
    ]
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main() def floyd_warshall(dist):
    """
    Compute the shortest paths of all pairs and modify dist.
    """
    V = len(dist)
    for i in range(V):  # intermediate point
        for j, c2 in enumerate(dist[j][i] for j in range(V)):  #  source
            for k, (c1, c3) in enumerate(zip(dist[j], dist[i])):  # target
                if c2 + c3 < c1:
                    dist[j][k] = c2 + c3 floyd_warshall """
    Compute the shortest paths of all pairs and modify dist.
    """ V = len(dist) V len(dist) len dist for i in range(V):  # intermediate point
        for j, c2 in enumerate(dist[j][i] for j in range(V)):  #  source
            for k, (c1, c3) in enumerate(zip(dist[j], dist[i])):  # target
                if c2 + c3 < c1:
                    dist[j][k] = c2 + c3 i range(V) range V for j, c2 in enumerate(dist[j][i] for j in range(V)):  #  source
            for k, (c1, c3) in enumerate(zip(dist[j], dist[i])):  # target
                if c2 + c3 < c1:
                    dist[j][k] = c2 + c3 j c2 enumerate(dist[j][i] for j in range(V)) enumerate dist[j][i] [j] dist j i for k, (c1, c3) in enumerate(zip(dist[j], dist[i])):  # target
                if c2 + c3 < c1:
                    dist[j][k] = c2 + c3 k (c1, c3) c1 c3 enumerate(zip(dist[j], dist[i])) enumerate zip(dist[j], dist[i]) zip dist[j] dist j dist[i] dist i if c2 + c3 < c1:
                    dist[j][k] = c2 + c3 c2 + c3 < c1 c2 + c3 c2 c3 c1 dist[j][k] = c2 + c3 dist[j][k] [j] dist j k c2 + c3 c2 c3 dist dist def main():
    # FW -> once more FW to edges <= L
    N, M, L, *X = map(int, open(0).read().split())
    ABC, ST = X[: 3 * M], X[3 * M + 1 :]
    INF = 1 << 60
    dist = [[INF] * (N + 1) for _ in range(N + 1)]
    for i in range(N + 1):
        dist[i][i] = 0
    for v, u, cost in zip(*[iter(ABC)] * 3):
        dist[v][u] = dist[u][v] = cost
    floyd_warshall(dist)

    # assume distance within L as 1 and compute the number of fueling
    modified_dist = [[1 if x <= L else INF for x in d] for d in dist]
    floyd_warshall(modified_dist)
    ans = [
        modified_dist[s][t] - 1 if modified_dist[s][t] < INF else -1
        for s, t in zip(*[iter(ST)] * 2)
    ]
    print("\n".join(map(str, ans))) main N, M, L, *X = map(int, open(0).read().split()) N map(int, open(0).read().split()) map int open(0).read().split() (0).read().split (0).read() (0).read (0) open 0 read split M L *X X ABC, ST = X[: 3 * M], X[3 * M + 1 :] ABC X[: 3 * M] X : 3 * M 3 * M 3 M ST X[3 * M + 1 :] X 3 * M + 1 : 3 * M + 1 3 * M 3 M 1 INF = 1 << 60 INF 1 << 60 1 60 [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 dist = [[INF] * (N + 1) for _ in range(N + 1)] dist [[INF] * (N + 1) for _ in range(N + 1)] for i in range(N + 1):
        dist[i][i] = 0
     i range(N + 1) range N + 1 N 1 dist[i][i] = 0 dist[i][i] [i] dist i i 0 for v, u, cost in zip(*[iter(ABC)] * 3):
        dist[v][u] = dist[u][v] = cost
     v u cost zip(*[iter(ABC)] * 3) zip *[iter(ABC)] * 3 [iter(ABC)] * 3 [iter(ABC)] iter(ABC) iter ABC 3 dist[v][u] = dist[u][v] = cost dist[v][u] [v] dist v u cost = dist[u][v] = cost dist[u][v] [u] dist u v cost floyd_warshall(dist) floyd_warshall dist [1 if x <= L else INF for x in d] for d in dist for d in dist d dist for d in dist [1 if x <= L else INF for x in d] modified_dist = [[1 if x <= L else INF for x in d] for d in dist] modified_dist [[1 if x <= L else INF for x in d] for d in dist] floyd_warshall(modified_dist) floyd_warshall modified_dist modified_dist[s][t] - 1 if modified_dist[s][t] < INF else -1
        for s, t in zip(*[iter(ST)] * 2) for s, t in zip(*[iter(ST)] * 2) s t zip(*[iter(ST)] * 2) zip *[iter(ST)] * 2 [iter(ST)] * 2 [iter(ST)] iter(ST) iter ST 2 for s, t in zip(*[iter(ST)] * 2) modified_dist[s][t] - 1 if modified_dist[s][t] < INF else -1 modified_dist[s][t] < INF modified_dist[s][t] [s] modified_dist s t INF modified_dist[s][t] - 1 modified_dist[s][t] [s] modified_dist s t 1 -1 ans = [
        modified_dist[s][t] - 1 if modified_dist[s][t] < INF else -1
        for s, t in zip(*[iter(ST)] * 2)
    ] ans [
        modified_dist[s][t] - 1 if modified_dist[s][t] < INF else -1
        for s, t in zip(*[iter(ST)] * 2)
    ] print("\n".join(map(str, ans))) print "\n".join(map(str, ans)) "\n".join "\n" join map(str, ans) map str ans if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    # FW -> once more FW to edges <= L
    N, M, L, *X = map(int, open(0).read().split())
    ABC, ST = X[: 3 * M], X[3 * M + 1 :]
    INF = 1 << 60
    dist = [[INF] * (N + 1) for _ in range(N + 1)]
    for i in range(N + 1):
        dist[i][i] = 0
    for v, u, cost in zip(*[iter(ABC)] * 3):
        dist[v][u] = dist[u][v] = cost
    floyd_warshall(dist)

    # assume distance within L as 1 and compute the number of fueling
    modified_dist = [[1 if x <= L else INF for x in d] for d in dist]
    floyd_warshall(modified_dist)
    ans = [
        modified_dist[s][t] - 1 if modified_dist[s][t] < INF else -1
        for s, t in zip(*[iter(ST)] * 2)
    ]
    print("\n".join(map(str, ans))) def main():
    # FW -> once more FW to edges <= L
    N, M, L, *X = map(int, open(0).read().split())
    ABC, ST = X[: 3 * M], X[3 * M + 1 :]
    INF = 1 << 60
    dist = [[INF] * (N + 1) for _ in range(N + 1)]
    for i in range(N + 1):
        dist[i][i] = 0
    for v, u, cost in zip(*[iter(ABC)] * 3):
        dist[v][u] = dist[u][v] = cost
    floyd_warshall(dist)

    # assume distance within L as 1 and compute the number of fueling
    modified_dist = [[1 if x <= L else INF for x in d] for d in dist]
    floyd_warshall(modified_dist)
    ans = [
        modified_dist[s][t] - 1 if modified_dist[s][t] < INF else -1
        for s, t in zip(*[iter(ST)] * 2)
    ]
    print("\n".join(map(str, ans))) main def floyd_warshall(dist):
    """
    Compute the shortest paths of all pairs and modify dist.
    """
    V = len(dist)
    for i in range(V):  # intermediate point
        for j, c2 in enumerate(dist[j][i] for j in range(V)):  #  source
            for k, (c1, c3) in enumerate(zip(dist[j], dist[i])):  # target
                if c2 + c3 < c1:
                    dist[j][k] = c2 + c3 def floyd_warshall(dist):
    """
    Compute the shortest paths of all pairs and modify dist.
    """
    V = len(dist)
    for i in range(V):  # intermediate point
        for j, c2 in enumerate(dist[j][i] for j in range(V)):  #  source
            for k, (c1, c3) in enumerate(zip(dist[j], dist[i])):  # target
                if c2 + c3 < c1:
                    dist[j][k] = c2 + c3 floyd_warshall
# ABC143E - Travel by Car
def floyd_warshall(dist):
    """
    Compute the shortest paths of all pairs and modify dist.
    """
    V = len(dist)
    for i in range(V):  # intermediate point
        for j, c2 in enumerate(dist[j][i] for j in range(V)):  #  source
            for k, (c1, c3) in enumerate(zip(dist[j], dist[i])):  # target
                if c2 + c3 < c1:
                    dist[j][k] = c2 + c3


def main():
    # FW -> once more FW to edges <= L
    N, M, L, *X = map(int, open(0).read().split())
    ABC, ST = X[: 3 * M], X[3 * M + 1 :]
    INF = 1 << 60
    dist = [[INF] * (N + 1) for _ in range(N + 1)]
    for i in range(N + 1):
        dist[i][i] = 0
    for v, u, cost in zip(*[iter(ABC)] * 3):
        dist[v][u] = dist[u][v] = cost
    floyd_warshall(dist)

    # assume distance within L as 1 and compute the number of fueling
    modified_dist = [[1 if x <= L else INF for x in d] for d in dist]
    floyd_warshall(modified_dist)
    ans = [
        modified_dist[s][t] - 1 if modified_dist[s][t] < INF else -1
        for s, t in zip(*[iter(ST)] * 2)
    ]
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()
