def numba_compile(numba_config):
    import os, sys
    if sys.argv[-1] == "ONLINE_JUDGE":
        from numba import njit
        from numba.pycc import CC
        cc = CC("my_module")
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature)(func)
            cc.export(func.__name__, signature)(func)
        cc.compile()
        exit()
    elif os.name == "posix":
        exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
        for func, _ in numba_config:
            globals()[func.__name__] = vars()[func.__name__]
    else:
        from numba import njit
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature, cache=True)(func)
        print("compiled!", file=sys.stderr)

import numpy as np

def solve(N, M, L, ABC, Q, ST):
    inf = 1<<61
    G = np.full((N+1, N+1), inf)
    G.ravel()[::N+2] = 0
    for i in range(M):
        a, b, c = ABC[i]
        G[a, b] = c
        G[b, a] = c
    for k in range(N+1):
        for i in range(N+1):
            for j in range(N+1):
                if G[i, j] > G[i, k] + G[k, j]:
                    G[i, j] = G[i, k] + G[k, j]
    G = np.where(G<=L, 1, inf)
    G.ravel()[::N+2] = 0
    for k in range(N+1):
        for i in range(N+1):
            for j in range(N+1):
                if G[i, j] > G[i, k] + G[k, j]:
                    G[i, j] = G[i, k] + G[k, j]
    G = np.where(G==inf, 0, G) - 1
    #Ans = G[ST[:, 0], ST[:, 1]]
    Ans = np.zeros(Q, dtype=np.int64)
    for i, (s, t) in enumerate(zip(ST[:,0], ST[:,1])):
        Ans[i] = G[s, t]
    return Ans

numba_compile([
    [solve, "i8[:](i8,i8,i8,i8[:,:],i8,i8[:,:])"]
])

N, M, L = map(int, input().split())
ABC = np.array([list(map(int, input().split())) for _ in range(M)], dtype=np.int64)
Q = int(input())
ST = np.array([list(map(int, input().split())) for _ in range(Q)], dtype=np.int64)

Ans = solve(N, M, L, ABC, Q, ST)
print("\n".join(map(str, Ans.tolist()))) def numba_compile(numba_config):
    import os, sys
    if sys.argv[-1] == "ONLINE_JUDGE":
        from numba import njit
        from numba.pycc import CC
        cc = CC("my_module")
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature)(func)
            cc.export(func.__name__, signature)(func)
        cc.compile()
        exit()
    elif os.name == "posix":
        exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
        for func, _ in numba_config:
            globals()[func.__name__] = vars()[func.__name__]
    else:
        from numba import njit
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature, cache=True)(func)
        print("compiled!", file=sys.stderr) numba_compile import os, sys os sys if sys.argv[-1] == "ONLINE_JUDGE":
        from numba import njit
        from numba.pycc import CC
        cc = CC("my_module")
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature)(func)
            cc.export(func.__name__, signature)(func)
        cc.compile()
        exit()
    elif os.name == "posix":
        exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
        for func, _ in numba_config:
            globals()[func.__name__] = vars()[func.__name__]
    else:
        from numba import njit
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature, cache=True)(func)
        print("compiled!", file=sys.stderr) sys.argv[-1] == "ONLINE_JUDGE" sys.argv[-1] sys.argv sys argv -1 "ONLINE_JUDGE" from numba import njit from numba.pycc import CC cc = CC("my_module") cc CC("my_module") CC "my_module" for func, signature in numba_config:
            globals()[func.__name__] = njit(signature)(func)
            cc.export(func.__name__, signature)(func)
         func signature numba_config globals()[func.__name__] = njit(signature)(func) globals()[func.__name__] () globals func.__name__ func __name__ njit(signature)(func) (signature) njit signature func cc.export(func.__name__, signature)(func) cc.export(func.__name__, signature) cc.export cc export func.__name__ func __name__ signature func cc.compile() cc.compile cc compile exit() exit elif os.name == "posix":
        exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
        for func, _ in numba_config:
            globals()[func.__name__] = vars()[func.__name__]
     os.name == "posix" os.name os name "posix" exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}") exec f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}" for func, _ in numba_config:
            globals()[func.__name__] = vars()[func.__name__]
     func _ numba_config globals()[func.__name__] = vars()[func.__name__] globals()[func.__name__] () globals func.__name__ func __name__ vars()[func.__name__] () vars func.__name__ func __name__ from numba import njit for func, signature in numba_config:
            globals()[func.__name__] = njit(signature, cache=True)(func)
         func signature numba_config globals()[func.__name__] = njit(signature, cache=True)(func) globals()[func.__name__] () globals func.__name__ func __name__ njit(signature, cache=True)(func) (signature, cache=True) njit signature cache=True cache True func print("compiled!", file=sys.stderr) print "compiled!" file=sys.stderr file sys.stderr sys stderr numba_config numba_config import numpy as np numpy def solve(N, M, L, ABC, Q, ST):
    inf = 1<<61
    G = np.full((N+1, N+1), inf)
    G.ravel()[::N+2] = 0
    for i in range(M):
        a, b, c = ABC[i]
        G[a, b] = c
        G[b, a] = c
    for k in range(N+1):
        for i in range(N+1):
            for j in range(N+1):
                if G[i, j] > G[i, k] + G[k, j]:
                    G[i, j] = G[i, k] + G[k, j]
    G = np.where(G<=L, 1, inf)
    G.ravel()[::N+2] = 0
    for k in range(N+1):
        for i in range(N+1):
            for j in range(N+1):
                if G[i, j] > G[i, k] + G[k, j]:
                    G[i, j] = G[i, k] + G[k, j]
    G = np.where(G==inf, 0, G) - 1
    #Ans = G[ST[:, 0], ST[:, 1]]
    Ans = np.zeros(Q, dtype=np.int64)
    for i, (s, t) in enumerate(zip(ST[:,0], ST[:,1])):
        Ans[i] = G[s, t]
    return Ans solve inf = 1<<61 inf 1<<61 1 61 G = np.full((N+1, N+1), inf) G np.full((N+1, N+1), inf) np.full np full (N+1, N+1) N+1 N 1 N+1 N 1 inf G.ravel()[::N+2] = 0 G.ravel()[::N+2] G.ravel() G.ravel G ravel ::N+2 N+2 N 2 0 for i in range(M):
        a, b, c = ABC[i]
        G[a, b] = c
        G[b, a] = c
     i range(M) range M a, b, c = ABC[i] a ABC[i] ABC i b c G[a, b] = c G[a, b] G a c G[b, a] = c G[b, a] G b c for k in range(N+1):
        for i in range(N+1):
            for j in range(N+1):
                if G[i, j] > G[i, k] + G[k, j]:
                    G[i, j] = G[i, k] + G[k, j]
     k range(N+1) range N+1 N 1 for i in range(N+1):
            for j in range(N+1):
                if G[i, j] > G[i, k] + G[k, j]:
                    G[i, j] = G[i, k] + G[k, j]
     i range(N+1) range N+1 N 1 for j in range(N+1):
                if G[i, j] > G[i, k] + G[k, j]:
                    G[i, j] = G[i, k] + G[k, j]
     j range(N+1) range N+1 N 1 if G[i, j] > G[i, k] + G[k, j]:
                    G[i, j] = G[i, k] + G[k, j]
     G[i, j] > G[i, k] + G[k, j] G[i, j] G i G[i, k] + G[k, j] G[i, k] G i G[k, j] G k G[i, j] = G[i, k] + G[k, j] G[i, j] G i G[i, k] + G[k, j] G[i, k] G i G[k, j] G k G = np.where(G<=L, 1, inf) G np.where(G<=L, 1, inf) np.where np where G<=L G L 1 inf G.ravel()[::N+2] = 0 G.ravel()[::N+2] G.ravel() G.ravel G ravel ::N+2 N+2 N 2 0 for k in range(N+1):
        for i in range(N+1):
            for j in range(N+1):
                if G[i, j] > G[i, k] + G[k, j]:
                    G[i, j] = G[i, k] + G[k, j]
     k range(N+1) range N+1 N 1 for i in range(N+1):
            for j in range(N+1):
                if G[i, j] > G[i, k] + G[k, j]:
                    G[i, j] = G[i, k] + G[k, j]
     i range(N+1) range N+1 N 1 for j in range(N+1):
                if G[i, j] > G[i, k] + G[k, j]:
                    G[i, j] = G[i, k] + G[k, j]
     j range(N+1) range N+1 N 1 if G[i, j] > G[i, k] + G[k, j]:
                    G[i, j] = G[i, k] + G[k, j]
     G[i, j] > G[i, k] + G[k, j] G[i, j] G i G[i, k] + G[k, j] G[i, k] G i G[k, j] G k G[i, j] = G[i, k] + G[k, j] G[i, j] G i G[i, k] + G[k, j] G[i, k] G i G[k, j] G k G = np.where(G==inf, 0, G) - 1 G np.where(G==inf, 0, G) - 1 np.where(G==inf, 0, G) np.where np where G==inf G inf 0 G 1 Ans = np.zeros(Q, dtype=np.int64) Ans np.zeros(Q, dtype=np.int64) np.zeros np zeros Q dtype=np.int64 dtype np.int64 np int64 for i, (s, t) in enumerate(zip(ST[:,0], ST[:,1])):
        Ans[i] = G[s, t]
     i (s, t) s t enumerate(zip(ST[:,0], ST[:,1])) enumerate zip(ST[:,0], ST[:,1]) zip ST[:,0] ST : ST[:,1] ST : Ans[i] = G[s, t] Ans[i] Ans i G[s, t] G s return Ans Ans N N M M L L ABC ABC Q Q ST ST numba_compile([
    [solve, "i8[:](i8,i8,i8,i8[:,:],i8,i8[:,:])"]
]) numba_compile [
    [solve, "i8[:](i8,i8,i8,i8[:,:],i8,i8[:,:])"]
] [solve, "i8[:](i8,i8,i8,i8[:,:],i8,i8[:,:])"] solve "i8[:](i8,i8,i8,i8[:,:],i8,i8[:,:])" N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L list(map(int, input().split())) for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split ABC = np.array([list(map(int, input().split())) for _ in range(M)], dtype=np.int64) ABC np.array([list(map(int, input().split())) for _ in range(M)], dtype=np.int64) np.array np array [list(map(int, input().split())) for _ in range(M)] dtype=np.int64 dtype np.int64 np int64 Q = int(input()) Q int(input()) int input() input list(map(int, input().split())) for _ in range(Q) for _ in range(Q) _ range(Q) range Q for _ in range(Q) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split ST = np.array([list(map(int, input().split())) for _ in range(Q)], dtype=np.int64) ST np.array([list(map(int, input().split())) for _ in range(Q)], dtype=np.int64) np.array np array [list(map(int, input().split())) for _ in range(Q)] dtype=np.int64 dtype np.int64 np int64 Ans = solve(N, M, L, ABC, Q, ST) Ans solve(N, M, L, ABC, Q, ST) solve N M L ABC Q ST print("\n".join(map(str, Ans.tolist()))) print "\n".join(map(str, Ans.tolist())) "\n".join "\n" join map(str, Ans.tolist()) map str Ans.tolist() Ans.tolist Ans tolist def solve(N, M, L, ABC, Q, ST):
    inf = 1<<61
    G = np.full((N+1, N+1), inf)
    G.ravel()[::N+2] = 0
    for i in range(M):
        a, b, c = ABC[i]
        G[a, b] = c
        G[b, a] = c
    for k in range(N+1):
        for i in range(N+1):
            for j in range(N+1):
                if G[i, j] > G[i, k] + G[k, j]:
                    G[i, j] = G[i, k] + G[k, j]
    G = np.where(G<=L, 1, inf)
    G.ravel()[::N+2] = 0
    for k in range(N+1):
        for i in range(N+1):
            for j in range(N+1):
                if G[i, j] > G[i, k] + G[k, j]:
                    G[i, j] = G[i, k] + G[k, j]
    G = np.where(G==inf, 0, G) - 1
    #Ans = G[ST[:, 0], ST[:, 1]]
    Ans = np.zeros(Q, dtype=np.int64)
    for i, (s, t) in enumerate(zip(ST[:,0], ST[:,1])):
        Ans[i] = G[s, t]
    return Ans def solve(N, M, L, ABC, Q, ST):
    inf = 1<<61
    G = np.full((N+1, N+1), inf)
    G.ravel()[::N+2] = 0
    for i in range(M):
        a, b, c = ABC[i]
        G[a, b] = c
        G[b, a] = c
    for k in range(N+1):
        for i in range(N+1):
            for j in range(N+1):
                if G[i, j] > G[i, k] + G[k, j]:
                    G[i, j] = G[i, k] + G[k, j]
    G = np.where(G<=L, 1, inf)
    G.ravel()[::N+2] = 0
    for k in range(N+1):
        for i in range(N+1):
            for j in range(N+1):
                if G[i, j] > G[i, k] + G[k, j]:
                    G[i, j] = G[i, k] + G[k, j]
    G = np.where(G==inf, 0, G) - 1
    #Ans = G[ST[:, 0], ST[:, 1]]
    Ans = np.zeros(Q, dtype=np.int64)
    for i, (s, t) in enumerate(zip(ST[:,0], ST[:,1])):
        Ans[i] = G[s, t]
    return Ans solve L = map(int, input().split()) map(int, input().split()) L ABC = np.array([list(map(int, input().split())) for _ in range(M)], dtype=np.int64) np.array([list(map(int, input().split())) for _ in range(M)], dtype=np.int64) ABC N, M, L = map(int, input().split()) map(int, input().split()) N M, L = map(int, input().split()) map(int, input().split()) M Q = int(input()) int(input()) Q ST = np.array([list(map(int, input().split())) for _ in range(Q)], dtype=np.int64) np.array([list(map(int, input().split())) for _ in range(Q)], dtype=np.int64) ST Ans = solve(N, M, L, ABC, Q, ST) solve(N, M, L, ABC, Q, ST) Ans def numba_compile(numba_config):
    import os, sys
    if sys.argv[-1] == "ONLINE_JUDGE":
        from numba import njit
        from numba.pycc import CC
        cc = CC("my_module")
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature)(func)
            cc.export(func.__name__, signature)(func)
        cc.compile()
        exit()
    elif os.name == "posix":
        exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
        for func, _ in numba_config:
            globals()[func.__name__] = vars()[func.__name__]
    else:
        from numba import njit
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature, cache=True)(func)
        print("compiled!", file=sys.stderr) def numba_compile(numba_config):
    import os, sys
    if sys.argv[-1] == "ONLINE_JUDGE":
        from numba import njit
        from numba.pycc import CC
        cc = CC("my_module")
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature)(func)
            cc.export(func.__name__, signature)(func)
        cc.compile()
        exit()
    elif os.name == "posix":
        exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
        for func, _ in numba_config:
            globals()[func.__name__] = vars()[func.__name__]
    else:
        from numba import njit
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature, cache=True)(func)
        print("compiled!", file=sys.stderr) numba_compile
def numba_compile(numba_config):
    import os, sys
    if sys.argv[-1] == "ONLINE_JUDGE":
        from numba import njit
        from numba.pycc import CC
        cc = CC("my_module")
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature)(func)
            cc.export(func.__name__, signature)(func)
        cc.compile()
        exit()
    elif os.name == "posix":
        exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
        for func, _ in numba_config:
            globals()[func.__name__] = vars()[func.__name__]
    else:
        from numba import njit
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature, cache=True)(func)
        print("compiled!", file=sys.stderr)

import numpy as np

def solve(N, M, L, ABC, Q, ST):
    inf = 1<<61
    G = np.full((N+1, N+1), inf)
    G.ravel()[::N+2] = 0
    for i in range(M):
        a, b, c = ABC[i]
        G[a, b] = c
        G[b, a] = c
    for k in range(N+1):
        for i in range(N+1):
            for j in range(N+1):
                if G[i, j] > G[i, k] + G[k, j]:
                    G[i, j] = G[i, k] + G[k, j]
    G = np.where(G<=L, 1, inf)
    G.ravel()[::N+2] = 0
    for k in range(N+1):
        for i in range(N+1):
            for j in range(N+1):
                if G[i, j] > G[i, k] + G[k, j]:
                    G[i, j] = G[i, k] + G[k, j]
    G = np.where(G==inf, 0, G) - 1
    #Ans = G[ST[:, 0], ST[:, 1]]
    Ans = np.zeros(Q, dtype=np.int64)
    for i, (s, t) in enumerate(zip(ST[:,0], ST[:,1])):
        Ans[i] = G[s, t]
    return Ans

numba_compile([
    [solve, "i8[:](i8,i8,i8,i8[:,:],i8,i8[:,:])"]
])

N, M, L = map(int, input().split())
ABC = np.array([list(map(int, input().split())) for _ in range(M)], dtype=np.int64)
Q = int(input())
ST = np.array([list(map(int, input().split())) for _ in range(Q)], dtype=np.int64)

Ans = solve(N, M, L, ABC, Q, ST)
print("\n".join(map(str, Ans.tolist())))
