def main():
    INF = 10 ** 12
    N, M, L = list(map(int, input().split(' ')))
    D = [[INF for _ in range(N)] for _ in range(N)]
    for _ in range(M):
        A, B, C = list(map(int, input().split(' ')))
        A -= 1
        B -= 1
        D[A][B] = C
        D[B][A] = C
    Q = int(input())
    query_list = [list(map(lambda x: int(x) - 1, input().split(' '))) for _ in range(Q)]
    # calc min cost by warshall-floyd method
    for via in range(N):
        for s in range(N):
            for t in range(N):
                d = D[s][via] + D[via][t]
                if D[s][t] > d:
                    D[s][t] = d
                    D[t][s] = d
    # calc min number of charges
    counts = [[INF for _ in range(N)] for _ in range(N)]
    for s in range(N):
        for t in range(N):
            if D[s][t] <= L:
                counts[s][t] = 1
                counts[t][s] = 1
    for via in range(N):
        for s in range(N):
            for t in range(N):
                d = counts[s][via] + counts[via][t]
                if counts[s][t] > d:
                    counts[s][t] = d
                    counts[t][s] = d
    # answer query
    for query in query_list:
        s, t = query
        if counts[s][t] >= INF:
            print(-1)
        else:
            print(counts[s][t] - 1)


if __name__ == '__main__':
    main() def main():
    INF = 10 ** 12
    N, M, L = list(map(int, input().split(' ')))
    D = [[INF for _ in range(N)] for _ in range(N)]
    for _ in range(M):
        A, B, C = list(map(int, input().split(' ')))
        A -= 1
        B -= 1
        D[A][B] = C
        D[B][A] = C
    Q = int(input())
    query_list = [list(map(lambda x: int(x) - 1, input().split(' '))) for _ in range(Q)]
    # calc min cost by warshall-floyd method
    for via in range(N):
        for s in range(N):
            for t in range(N):
                d = D[s][via] + D[via][t]
                if D[s][t] > d:
                    D[s][t] = d
                    D[t][s] = d
    # calc min number of charges
    counts = [[INF for _ in range(N)] for _ in range(N)]
    for s in range(N):
        for t in range(N):
            if D[s][t] <= L:
                counts[s][t] = 1
                counts[t][s] = 1
    for via in range(N):
        for s in range(N):
            for t in range(N):
                d = counts[s][via] + counts[via][t]
                if counts[s][t] > d:
                    counts[s][t] = d
                    counts[t][s] = d
    # answer query
    for query in query_list:
        s, t = query
        if counts[s][t] >= INF:
            print(-1)
        else:
            print(counts[s][t] - 1) main INF = 10 ** 12 INF 10 ** 12 10 12 N, M, L = list(map(int, input().split(' '))) N list(map(int, input().split(' '))) list map(int, input().split(' ')) map int input().split(' ') ().split () input split ' ' M L [INF for _ in range(N)] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF for _ in range(N)] D = [[INF for _ in range(N)] for _ in range(N)] D [[INF for _ in range(N)] for _ in range(N)] for _ in range(M):
        A, B, C = list(map(int, input().split(' ')))
        A -= 1
        B -= 1
        D[A][B] = C
        D[B][A] = C
     _ range(M) range M A, B, C = list(map(int, input().split(' '))) A list(map(int, input().split(' '))) list map(int, input().split(' ')) map int input().split(' ') ().split () input split ' ' B C A -= 1 A 1 B -= 1 B 1 D[A][B] = C D[A][B] [A] D A B C D[B][A] = C D[B][A] [B] D B A C Q = int(input()) Q int(input()) int input() input list(map(lambda x: int(x) - 1, input().split(' '))) for _ in range(Q) for _ in range(Q) _ range(Q) range Q for _ in range(Q) list(map(lambda x: int(x) - 1, input().split(' '))) list map(lambda x: int(x) - 1, input().split(' ')) map lambda x: int(x) - 1 int(x) - 1 int(x) int x 1 x input().split(' ') ().split () input split ' ' query_list = [list(map(lambda x: int(x) - 1, input().split(' '))) for _ in range(Q)] query_list [list(map(lambda x: int(x) - 1, input().split(' '))) for _ in range(Q)] for via in range(N):
        for s in range(N):
            for t in range(N):
                d = D[s][via] + D[via][t]
                if D[s][t] > d:
                    D[s][t] = d
                    D[t][s] = d
    # calc min number of charges
     via range(N) range N for s in range(N):
            for t in range(N):
                d = D[s][via] + D[via][t]
                if D[s][t] > d:
                    D[s][t] = d
                    D[t][s] = d
    # calc min number of charges
     s range(N) range N for t in range(N):
                d = D[s][via] + D[via][t]
                if D[s][t] > d:
                    D[s][t] = d
                    D[t][s] = d
    # calc min number of charges
     t range(N) range N d = D[s][via] + D[via][t] d D[s][via] + D[via][t] D[s][via] [s] D s via D[via][t] [via] D via t if D[s][t] > d:
                    D[s][t] = d
                    D[t][s] = d
    # calc min number of charges
     D[s][t] > d D[s][t] [s] D s t d D[s][t] = d D[s][t] [s] D s t d D[t][s] = d D[t][s] [t] D t s d [INF for _ in range(N)] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF for _ in range(N)] counts = [[INF for _ in range(N)] for _ in range(N)] counts [[INF for _ in range(N)] for _ in range(N)] for s in range(N):
        for t in range(N):
            if D[s][t] <= L:
                counts[s][t] = 1
                counts[t][s] = 1
     s range(N) range N for t in range(N):
            if D[s][t] <= L:
                counts[s][t] = 1
                counts[t][s] = 1
     t range(N) range N if D[s][t] <= L:
                counts[s][t] = 1
                counts[t][s] = 1
     D[s][t] <= L D[s][t] [s] D s t L counts[s][t] = 1 counts[s][t] [s] counts s t 1 counts[t][s] = 1 counts[t][s] [t] counts t s 1 for via in range(N):
        for s in range(N):
            for t in range(N):
                d = counts[s][via] + counts[via][t]
                if counts[s][t] > d:
                    counts[s][t] = d
                    counts[t][s] = d
    # answer query
     via range(N) range N for s in range(N):
            for t in range(N):
                d = counts[s][via] + counts[via][t]
                if counts[s][t] > d:
                    counts[s][t] = d
                    counts[t][s] = d
    # answer query
     s range(N) range N for t in range(N):
                d = counts[s][via] + counts[via][t]
                if counts[s][t] > d:
                    counts[s][t] = d
                    counts[t][s] = d
    # answer query
     t range(N) range N d = counts[s][via] + counts[via][t] d counts[s][via] + counts[via][t] counts[s][via] [s] counts s via counts[via][t] [via] counts via t if counts[s][t] > d:
                    counts[s][t] = d
                    counts[t][s] = d
    # answer query
     counts[s][t] > d counts[s][t] [s] counts s t d counts[s][t] = d counts[s][t] [s] counts s t d counts[t][s] = d counts[t][s] [t] counts t s d for query in query_list:
        s, t = query
        if counts[s][t] >= INF:
            print(-1)
        else:
            print(counts[s][t] - 1) query query_list s, t = query s query t if counts[s][t] >= INF:
            print(-1)
        else:
            print(counts[s][t] - 1) counts[s][t] >= INF counts[s][t] [s] counts s t INF print(-1) print -1 print(counts[s][t] - 1) print counts[s][t] - 1 counts[s][t] [s] counts s t 1 if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    INF = 10 ** 12
    N, M, L = list(map(int, input().split(' ')))
    D = [[INF for _ in range(N)] for _ in range(N)]
    for _ in range(M):
        A, B, C = list(map(int, input().split(' ')))
        A -= 1
        B -= 1
        D[A][B] = C
        D[B][A] = C
    Q = int(input())
    query_list = [list(map(lambda x: int(x) - 1, input().split(' '))) for _ in range(Q)]
    # calc min cost by warshall-floyd method
    for via in range(N):
        for s in range(N):
            for t in range(N):
                d = D[s][via] + D[via][t]
                if D[s][t] > d:
                    D[s][t] = d
                    D[t][s] = d
    # calc min number of charges
    counts = [[INF for _ in range(N)] for _ in range(N)]
    for s in range(N):
        for t in range(N):
            if D[s][t] <= L:
                counts[s][t] = 1
                counts[t][s] = 1
    for via in range(N):
        for s in range(N):
            for t in range(N):
                d = counts[s][via] + counts[via][t]
                if counts[s][t] > d:
                    counts[s][t] = d
                    counts[t][s] = d
    # answer query
    for query in query_list:
        s, t = query
        if counts[s][t] >= INF:
            print(-1)
        else:
            print(counts[s][t] - 1) def main():
    INF = 10 ** 12
    N, M, L = list(map(int, input().split(' ')))
    D = [[INF for _ in range(N)] for _ in range(N)]
    for _ in range(M):
        A, B, C = list(map(int, input().split(' ')))
        A -= 1
        B -= 1
        D[A][B] = C
        D[B][A] = C
    Q = int(input())
    query_list = [list(map(lambda x: int(x) - 1, input().split(' '))) for _ in range(Q)]
    # calc min cost by warshall-floyd method
    for via in range(N):
        for s in range(N):
            for t in range(N):
                d = D[s][via] + D[via][t]
                if D[s][t] > d:
                    D[s][t] = d
                    D[t][s] = d
    # calc min number of charges
    counts = [[INF for _ in range(N)] for _ in range(N)]
    for s in range(N):
        for t in range(N):
            if D[s][t] <= L:
                counts[s][t] = 1
                counts[t][s] = 1
    for via in range(N):
        for s in range(N):
            for t in range(N):
                d = counts[s][via] + counts[via][t]
                if counts[s][t] > d:
                    counts[s][t] = d
                    counts[t][s] = d
    # answer query
    for query in query_list:
        s, t = query
        if counts[s][t] >= INF:
            print(-1)
        else:
            print(counts[s][t] - 1) main
def main():
    INF = 10 ** 12
    N, M, L = list(map(int, input().split(' ')))
    D = [[INF for _ in range(N)] for _ in range(N)]
    for _ in range(M):
        A, B, C = list(map(int, input().split(' ')))
        A -= 1
        B -= 1
        D[A][B] = C
        D[B][A] = C
    Q = int(input())
    query_list = [list(map(lambda x: int(x) - 1, input().split(' '))) for _ in range(Q)]
    # calc min cost by warshall-floyd method
    for via in range(N):
        for s in range(N):
            for t in range(N):
                d = D[s][via] + D[via][t]
                if D[s][t] > d:
                    D[s][t] = d
                    D[t][s] = d
    # calc min number of charges
    counts = [[INF for _ in range(N)] for _ in range(N)]
    for s in range(N):
        for t in range(N):
            if D[s][t] <= L:
                counts[s][t] = 1
                counts[t][s] = 1
    for via in range(N):
        for s in range(N):
            for t in range(N):
                d = counts[s][via] + counts[via][t]
                if counts[s][t] > d:
                    counts[s][t] = d
                    counts[t][s] = d
    # answer query
    for query in query_list:
        s, t = query
        if counts[s][t] >= INF:
            print(-1)
        else:
            print(counts[s][t] - 1)


if __name__ == '__main__':
    main()