
def resolve():
    INF = 10 ** 18
    N, M, L = map(int, input().split())
    G = [[INF] * N for _ in range(N)]
    for _ in range(M):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        G[a][b] = G[b][a] = c

    for k in range(N):
        for i in range(N):
            for j in range(N):
                G[i][j] = min(G[i][j], G[i][k] + G[k][j])

    Cost = [[INF] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if G[i][j] <= L:
                Cost[i][j] = 1

    for k in range(N):
        for i in range(N):
            for j in range(N):
                Cost[i][j] = min(Cost[i][j], Cost[i][k] + Cost[k][j])

    Q = int(input())
    for _ in range(Q):
        a, b = map(lambda x: int(x) - 1, input().split())
        if Cost[a][b] == INF:
            print(-1)
        else:
            print(Cost[a][b] - 1)


if __name__ == "__main__":
    resolve() def resolve():
    INF = 10 ** 18
    N, M, L = map(int, input().split())
    G = [[INF] * N for _ in range(N)]
    for _ in range(M):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        G[a][b] = G[b][a] = c

    for k in range(N):
        for i in range(N):
            for j in range(N):
                G[i][j] = min(G[i][j], G[i][k] + G[k][j])

    Cost = [[INF] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if G[i][j] <= L:
                Cost[i][j] = 1

    for k in range(N):
        for i in range(N):
            for j in range(N):
                Cost[i][j] = min(Cost[i][j], Cost[i][k] + Cost[k][j])

    Q = int(input())
    for _ in range(Q):
        a, b = map(lambda x: int(x) - 1, input().split())
        if Cost[a][b] == INF:
            print(-1)
        else:
            print(Cost[a][b] - 1) resolve INF = 10 ** 18 INF 10 ** 18 10 18 N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L [INF] * N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF] * N [INF] INF N G = [[INF] * N for _ in range(N)] G [[INF] * N for _ in range(N)] for _ in range(M):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        G[a][b] = G[b][a] = c

     _ range(M) range M a, b, c = map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b c a -= 1 a 1 b -= 1 b 1 G[a][b] = G[b][a] = c G[a][b] [a] G a b c = G[b][a] = c G[b][a] [b] G b a c for k in range(N):
        for i in range(N):
            for j in range(N):
                G[i][j] = min(G[i][j], G[i][k] + G[k][j])

     k range(N) range N for i in range(N):
            for j in range(N):
                G[i][j] = min(G[i][j], G[i][k] + G[k][j])

     i range(N) range N for j in range(N):
                G[i][j] = min(G[i][j], G[i][k] + G[k][j])

     j range(N) range N G[i][j] = min(G[i][j], G[i][k] + G[k][j]) G[i][j] [i] G i j min(G[i][j], G[i][k] + G[k][j]) min G[i][j] [i] G i j G[i][k] + G[k][j] G[i][k] [i] G i k G[k][j] [k] G k j [INF] * N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF] * N [INF] INF N Cost = [[INF] * N for _ in range(N)] Cost [[INF] * N for _ in range(N)] for i in range(N):
        for j in range(N):
            if G[i][j] <= L:
                Cost[i][j] = 1

     i range(N) range N for j in range(N):
            if G[i][j] <= L:
                Cost[i][j] = 1

     j range(N) range N if G[i][j] <= L:
                Cost[i][j] = 1

     G[i][j] <= L G[i][j] [i] G i j L Cost[i][j] = 1 Cost[i][j] [i] Cost i j 1 for k in range(N):
        for i in range(N):
            for j in range(N):
                Cost[i][j] = min(Cost[i][j], Cost[i][k] + Cost[k][j])

     k range(N) range N for i in range(N):
            for j in range(N):
                Cost[i][j] = min(Cost[i][j], Cost[i][k] + Cost[k][j])

     i range(N) range N for j in range(N):
                Cost[i][j] = min(Cost[i][j], Cost[i][k] + Cost[k][j])

     j range(N) range N Cost[i][j] = min(Cost[i][j], Cost[i][k] + Cost[k][j]) Cost[i][j] [i] Cost i j min(Cost[i][j], Cost[i][k] + Cost[k][j]) min Cost[i][j] [i] Cost i j Cost[i][k] + Cost[k][j] Cost[i][k] [i] Cost i k Cost[k][j] [k] Cost k j Q = int(input()) Q int(input()) int input() input for _ in range(Q):
        a, b = map(lambda x: int(x) - 1, input().split())
        if Cost[a][b] == INF:
            print(-1)
        else:
            print(Cost[a][b] - 1) _ range(Q) range Q a, b = map(lambda x: int(x) - 1, input().split()) a 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 b if Cost[a][b] == INF:
            print(-1)
        else:
            print(Cost[a][b] - 1) Cost[a][b] == INF Cost[a][b] [a] Cost a b INF print(-1) print -1 print(Cost[a][b] - 1) print Cost[a][b] - 1 Cost[a][b] [a] Cost a b 1 if __name__ == "__main__":
    resolve() __name__ == "__main__" __name__ "__main__" resolve() resolve def resolve():
    INF = 10 ** 18
    N, M, L = map(int, input().split())
    G = [[INF] * N for _ in range(N)]
    for _ in range(M):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        G[a][b] = G[b][a] = c

    for k in range(N):
        for i in range(N):
            for j in range(N):
                G[i][j] = min(G[i][j], G[i][k] + G[k][j])

    Cost = [[INF] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if G[i][j] <= L:
                Cost[i][j] = 1

    for k in range(N):
        for i in range(N):
            for j in range(N):
                Cost[i][j] = min(Cost[i][j], Cost[i][k] + Cost[k][j])

    Q = int(input())
    for _ in range(Q):
        a, b = map(lambda x: int(x) - 1, input().split())
        if Cost[a][b] == INF:
            print(-1)
        else:
            print(Cost[a][b] - 1) def resolve():
    INF = 10 ** 18
    N, M, L = map(int, input().split())
    G = [[INF] * N for _ in range(N)]
    for _ in range(M):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        G[a][b] = G[b][a] = c

    for k in range(N):
        for i in range(N):
            for j in range(N):
                G[i][j] = min(G[i][j], G[i][k] + G[k][j])

    Cost = [[INF] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if G[i][j] <= L:
                Cost[i][j] = 1

    for k in range(N):
        for i in range(N):
            for j in range(N):
                Cost[i][j] = min(Cost[i][j], Cost[i][k] + Cost[k][j])

    Q = int(input())
    for _ in range(Q):
        a, b = map(lambda x: int(x) - 1, input().split())
        if Cost[a][b] == INF:
            print(-1)
        else:
            print(Cost[a][b] - 1) resolve

def resolve():
    INF = 10 ** 18
    N, M, L = map(int, input().split())
    G = [[INF] * N for _ in range(N)]
    for _ in range(M):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        G[a][b] = G[b][a] = c

    for k in range(N):
        for i in range(N):
            for j in range(N):
                G[i][j] = min(G[i][j], G[i][k] + G[k][j])

    Cost = [[INF] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if G[i][j] <= L:
                Cost[i][j] = 1

    for k in range(N):
        for i in range(N):
            for j in range(N):
                Cost[i][j] = min(Cost[i][j], Cost[i][k] + Cost[k][j])

    Q = int(input())
    for _ in range(Q):
        a, b = map(lambda x: int(x) - 1, input().split())
        if Cost[a][b] == INF:
            print(-1)
        else:
            print(Cost[a][b] - 1)


if __name__ == "__main__":
    resolve()
