import sys
from collections import defaultdict
from queue import deque
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    N, M, L = geta(int)
    INF = 10**10

    d = [[INF] * (N + 1) for _ in range(N + 1)]

    for i in range(1, N + 1):
        d[i][i] = 0

    for _ in range(M):
        a, b, c = geta(int)
        d[a][b] = c
        d[b][a] = c

    def warshall_froyd(_d):
        for k in range(1, N + 1):
            for i in range(1, N + 1):
                for j in range(1, N + 1):
                    l = _d[i][k] + _d[k][j]
                    if _d[i][j] > l:
                        _d[i][j] = l

    warshall_froyd(d)

    f = [[INF] * (N + 1) for _ in range(N + 1)]
    for i in range(N + 1):
        f[i][i] = 0
        for j in range(N + 1):
            if d[i][j] <= L:
                f[i][j] = 1

    warshall_froyd(f)

    for _ in range(gete(int)):
        s, t = geta(int)
        ret = f[s][t]
        print(ret - 1 if ret != INF else -1)


if __name__ == "__main__":
    main() import sys sys from collections import defaultdict from queue import deque readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split()) geta return map(fn, readline().split()) map(fn, readline().split()) map fn readline().split() ().split () readline split fn=lambda s: s.decode() fn lambda s: s.decode() s.decode() s.decode s decode s def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip()) gete return fn(readline().rstrip()) fn(readline().rstrip()) fn readline().rstrip() ().rstrip () readline rstrip fn=lambda s: s.decode() fn lambda s: s.decode() s.decode() s.decode s decode s def main():
    N, M, L = geta(int)
    INF = 10**10

    d = [[INF] * (N + 1) for _ in range(N + 1)]

    for i in range(1, N + 1):
        d[i][i] = 0

    for _ in range(M):
        a, b, c = geta(int)
        d[a][b] = c
        d[b][a] = c

    def warshall_froyd(_d):
        for k in range(1, N + 1):
            for i in range(1, N + 1):
                for j in range(1, N + 1):
                    l = _d[i][k] + _d[k][j]
                    if _d[i][j] > l:
                        _d[i][j] = l

    warshall_froyd(d)

    f = [[INF] * (N + 1) for _ in range(N + 1)]
    for i in range(N + 1):
        f[i][i] = 0
        for j in range(N + 1):
            if d[i][j] <= L:
                f[i][j] = 1

    warshall_froyd(f)

    for _ in range(gete(int)):
        s, t = geta(int)
        ret = f[s][t]
        print(ret - 1 if ret != INF else -1) main N, M, L = geta(int) N geta(int) geta int M L INF = 10**10 INF 10**10 10 10 [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 d = [[INF] * (N + 1) for _ in range(N + 1)] d [[INF] * (N + 1) for _ in range(N + 1)] for i in range(1, N + 1):
        d[i][i] = 0

     i range(1, N + 1) range 1 N + 1 N 1 d[i][i] = 0 d[i][i] [i] d i i 0 for _ in range(M):
        a, b, c = geta(int)
        d[a][b] = c
        d[b][a] = c

     _ range(M) range M a, b, c = geta(int) a geta(int) geta int b c d[a][b] = c d[a][b] [a] d a b c d[b][a] = c d[b][a] [b] d b a c def warshall_froyd(_d):
        for k in range(1, N + 1):
            for i in range(1, N + 1):
                for j in range(1, N + 1):
                    l = _d[i][k] + _d[k][j]
                    if _d[i][j] > l:
                        _d[i][j] = l

     warshall_froyd for k in range(1, N + 1):
            for i in range(1, N + 1):
                for j in range(1, N + 1):
                    l = _d[i][k] + _d[k][j]
                    if _d[i][j] > l:
                        _d[i][j] = l

     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):
                    l = _d[i][k] + _d[k][j]
                    if _d[i][j] > l:
                        _d[i][j] = l

     i range(1, N + 1) range 1 N + 1 N 1 for j in range(1, N + 1):
                    l = _d[i][k] + _d[k][j]
                    if _d[i][j] > l:
                        _d[i][j] = l

     j range(1, N + 1) range 1 N + 1 N 1 l = _d[i][k] + _d[k][j] l _d[i][k] + _d[k][j] _d[i][k] [i] _d i k _d[k][j] [k] _d k j if _d[i][j] > l:
                        _d[i][j] = l

     _d[i][j] > l _d[i][j] [i] _d i j l _d[i][j] = l _d[i][j] [i] _d i j l _d _d warshall_froyd(d) warshall_froyd d [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 f = [[INF] * (N + 1) for _ in range(N + 1)] f [[INF] * (N + 1) for _ in range(N + 1)] for i in range(N + 1):
        f[i][i] = 0
        for j in range(N + 1):
            if d[i][j] <= L:
                f[i][j] = 1

     i range(N + 1) range N + 1 N 1 f[i][i] = 0 f[i][i] [i] f i i 0 for j in range(N + 1):
            if d[i][j] <= L:
                f[i][j] = 1

     j range(N + 1) range N + 1 N 1 if d[i][j] <= L:
                f[i][j] = 1

     d[i][j] <= L d[i][j] [i] d i j L f[i][j] = 1 f[i][j] [i] f i j 1 warshall_froyd(f) warshall_froyd f for _ in range(gete(int)):
        s, t = geta(int)
        ret = f[s][t]
        print(ret - 1 if ret != INF else -1) _ range(gete(int)) range gete(int) gete int s, t = geta(int) s geta(int) geta int t ret = f[s][t] ret f[s][t] [s] f s t print(ret - 1 if ret != INF else -1) print ret - 1 if ret != INF else -1 ret != INF ret INF ret - 1 ret 1 -1 if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    N, M, L = geta(int)
    INF = 10**10

    d = [[INF] * (N + 1) for _ in range(N + 1)]

    for i in range(1, N + 1):
        d[i][i] = 0

    for _ in range(M):
        a, b, c = geta(int)
        d[a][b] = c
        d[b][a] = c

    def warshall_froyd(_d):
        for k in range(1, N + 1):
            for i in range(1, N + 1):
                for j in range(1, N + 1):
                    l = _d[i][k] + _d[k][j]
                    if _d[i][j] > l:
                        _d[i][j] = l

    warshall_froyd(d)

    f = [[INF] * (N + 1) for _ in range(N + 1)]
    for i in range(N + 1):
        f[i][i] = 0
        for j in range(N + 1):
            if d[i][j] <= L:
                f[i][j] = 1

    warshall_froyd(f)

    for _ in range(gete(int)):
        s, t = geta(int)
        ret = f[s][t]
        print(ret - 1 if ret != INF else -1) def main():
    N, M, L = geta(int)
    INF = 10**10

    d = [[INF] * (N + 1) for _ in range(N + 1)]

    for i in range(1, N + 1):
        d[i][i] = 0

    for _ in range(M):
        a, b, c = geta(int)
        d[a][b] = c
        d[b][a] = c

    def warshall_froyd(_d):
        for k in range(1, N + 1):
            for i in range(1, N + 1):
                for j in range(1, N + 1):
                    l = _d[i][k] + _d[k][j]
                    if _d[i][j] > l:
                        _d[i][j] = l

    warshall_froyd(d)

    f = [[INF] * (N + 1) for _ in range(N + 1)]
    for i in range(N + 1):
        f[i][i] = 0
        for j in range(N + 1):
            if d[i][j] <= L:
                f[i][j] = 1

    warshall_froyd(f)

    for _ in range(gete(int)):
        s, t = geta(int)
        ret = f[s][t]
        print(ret - 1 if ret != INF else -1) main def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip()) def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip()) gete def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split()) def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split()) geta readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline
import sys
from collections import defaultdict
from queue import deque
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    N, M, L = geta(int)
    INF = 10**10

    d = [[INF] * (N + 1) for _ in range(N + 1)]

    for i in range(1, N + 1):
        d[i][i] = 0

    for _ in range(M):
        a, b, c = geta(int)
        d[a][b] = c
        d[b][a] = c

    def warshall_froyd(_d):
        for k in range(1, N + 1):
            for i in range(1, N + 1):
                for j in range(1, N + 1):
                    l = _d[i][k] + _d[k][j]
                    if _d[i][j] > l:
                        _d[i][j] = l

    warshall_froyd(d)

    f = [[INF] * (N + 1) for _ in range(N + 1)]
    for i in range(N + 1):
        f[i][i] = 0
        for j in range(N + 1):
            if d[i][j] <= L:
                f[i][j] = 1

    warshall_froyd(f)

    for _ in range(gete(int)):
        s, t = geta(int)
        ret = f[s][t]
        print(ret - 1 if ret != INF else -1)


if __name__ == "__main__":
    main()