def main():

  import sys

  from scipy.sparse.csgraph import floyd_warshall as f

  n,m,l,*t=list(map(int,sys.stdin.buffer.read().split()))

  d=[[0]*(n+1)for _ in range(n+1)]

  for a,b,c in zip(*[iter(t[:m*3])]*3):d[a][b]=c

  d=f(f(d,0)<=l)-1

  d[d>n]=-1

  d=d.astype(int)

  print(('\n'.join(map(str,[d[i]for i in zip(*[iter(t[m*3+1:])]*2)]))))

main()
def main():

  import sys

  from scipy.sparse.csgraph import floyd_warshall as f

  n,m,l,*t=list(map(int,sys.stdin.buffer.read().split()))

  d=[[0]*(n+1)for _ in range(n+1)]

  for a,b,c in zip(*[iter(t[:m*3])]*3):d[a][b]=c

  d=f(f(d,0)<=l)-1

  d[d==float('inf')]=-1

  print(('\n'.join(map(str,list(map(int,[d[i]for i in zip(*[iter(t[m*3+1:])]*2)]))))))

main()
def main():
    import sys
    from scipy.sparse.csgraph import floyd_warshall as f

    n, m, l, *t = list(map(int, sys.stdin.buffer.read().split()))
    d = [[0] * (n + 1) for _ in range(n + 1)]
    for a, b, c in zip(*[iter(t[: m * 3])] * 3):
        d[a][b] = c
    d = f(f(d, 0) <= l) - 1
    d[d > n] = -1
    d = d.astype(int)
    print(("\n".join(map(str, [d[i] for i in zip(*[iter(t[m * 3 + 1 :])] * 2)]))))


main()

def main():
    import sys
    from scipy.sparse.csgraph import floyd_warshall as f

    n, m, l, *t = list(map(int, sys.stdin.buffer.read().split()))
    d = [[0] * (n + 1) for _ in range(n + 1)]
    for a, b, c in zip(*[iter(t[: m * 3])] * 3):
        d[a][b] = c
    d = f(f(d, 0) <= l) - 1
    d[d == float("inf")] = -1
    print(
        (
            "\n".join(
                map(
                    str,
                    list(map(int, [d[i] for i in zip(*[iter(t[m * 3 + 1 :])] * 2)])),
                )
            )
        )
    )


main()

-    d[d > n] = -1 -    d = d.astype(int) -    print(("\n".join(map(str, [d[i] for i in zip(*[iter(t[m * 3 + 1 :])] * 2)])))) +    d[d == float("inf")] = -1 +    print( +        ( +            "\n".join( +                map( +                    str, +                    list(map(int, [d[i] for i in zip(*[iter(t[m * 3 + 1 :])] * 2)])), +                ) +            ) +        ) +    )