import sys
input = sys.stdin.readline


def calc(N, g):
    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])


def main():
    N, M, L = map(int, input().split())
    adj = [{} for _ in range(N)]
    for _ in range(M):
        A, B, C = map(int, input().split())
        adj[A-1][B-1] = C
        adj[B-1][A-1] = C
    dst = [[float("inf")] * N for _ in range(N)]
    for i in range(N):
        dst[i][i] = 0
        for j in adj[i]:
            dst[i][j] = adj[i][j]
    calc(N, dst)
    ans = [[float("inf")] * N for _ in range(N)]
    for i in range(N):
        ans[i][i] = 0
        for j in range(i+1, N):
            if dst[i][j] <= L:
                ans[i][j] = 1
                ans[j][i] = 1
    calc(N, ans)
    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        x = ans[s-1][t-1]
        print(-1 if x == float("inf") else x-1)


if __name__ == "__main__":
    main() import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def calc(N, g):
    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]) calc 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 N N g g def main():
    N, M, L = map(int, input().split())
    adj = [{} for _ in range(N)]
    for _ in range(M):
        A, B, C = map(int, input().split())
        adj[A-1][B-1] = C
        adj[B-1][A-1] = C
    dst = [[float("inf")] * N for _ in range(N)]
    for i in range(N):
        dst[i][i] = 0
        for j in adj[i]:
            dst[i][j] = adj[i][j]
    calc(N, dst)
    ans = [[float("inf")] * N for _ in range(N)]
    for i in range(N):
        ans[i][i] = 0
        for j in range(i+1, N):
            if dst[i][j] <= L:
                ans[i][j] = 1
                ans[j][i] = 1
    calc(N, ans)
    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        x = ans[s-1][t-1]
        print(-1 if x == float("inf") else x-1) main N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L {} for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) {} adj = [{} for _ in range(N)] adj [{} for _ in range(N)] for _ in range(M):
        A, B, C = map(int, input().split())
        adj[A-1][B-1] = C
        adj[B-1][A-1] = 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 adj[A-1][B-1] = C adj[A-1][B-1] [A-1] adj A-1 A 1 B-1 B 1 C adj[B-1][A-1] = C adj[B-1][A-1] [B-1] adj B-1 B 1 A-1 A 1 C [float("inf")] * N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [float("inf")] * N [float("inf")] float("inf") float "inf" N dst = [[float("inf")] * N for _ in range(N)] dst [[float("inf")] * N for _ in range(N)] for i in range(N):
        dst[i][i] = 0
        for j in adj[i]:
            dst[i][j] = adj[i][j]
     i range(N) range N dst[i][i] = 0 dst[i][i] [i] dst i i 0 for j in adj[i]:
            dst[i][j] = adj[i][j]
     j adj[i] adj i dst[i][j] = adj[i][j] dst[i][j] [i] dst i j adj[i][j] [i] adj i j calc(N, dst) calc N dst [float("inf")] * N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [float("inf")] * N [float("inf")] float("inf") float "inf" N ans = [[float("inf")] * N for _ in range(N)] ans [[float("inf")] * N for _ in range(N)] for i in range(N):
        ans[i][i] = 0
        for j in range(i+1, N):
            if dst[i][j] <= L:
                ans[i][j] = 1
                ans[j][i] = 1
     i range(N) range N ans[i][i] = 0 ans[i][i] [i] ans i i 0 for j in range(i+1, N):
            if dst[i][j] <= L:
                ans[i][j] = 1
                ans[j][i] = 1
     j range(i+1, N) range i+1 i 1 N if dst[i][j] <= L:
                ans[i][j] = 1
                ans[j][i] = 1
     dst[i][j] <= L dst[i][j] [i] dst i j L ans[i][j] = 1 ans[i][j] [i] ans i j 1 ans[j][i] = 1 ans[j][i] [j] ans j i 1 calc(N, ans) calc N ans Q = int(input()) Q int(input()) int input() input for _ in range(Q):
        s, t = map(int, input().split())
        x = ans[s-1][t-1]
        print(-1 if x == float("inf") else x-1) _ range(Q) range Q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t x = ans[s-1][t-1] x ans[s-1][t-1] [s-1] ans s-1 s 1 t-1 t 1 print(-1 if x == float("inf") else x-1) print -1 if x == float("inf") else x-1 x == float("inf") x float("inf") float "inf" -1 x-1 x 1 if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def calc(N, g):
    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]) def calc(N, g):
    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]) calc input = sys.stdin.readline sys.stdin.readline input def main():
    N, M, L = map(int, input().split())
    adj = [{} for _ in range(N)]
    for _ in range(M):
        A, B, C = map(int, input().split())
        adj[A-1][B-1] = C
        adj[B-1][A-1] = C
    dst = [[float("inf")] * N for _ in range(N)]
    for i in range(N):
        dst[i][i] = 0
        for j in adj[i]:
            dst[i][j] = adj[i][j]
    calc(N, dst)
    ans = [[float("inf")] * N for _ in range(N)]
    for i in range(N):
        ans[i][i] = 0
        for j in range(i+1, N):
            if dst[i][j] <= L:
                ans[i][j] = 1
                ans[j][i] = 1
    calc(N, ans)
    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        x = ans[s-1][t-1]
        print(-1 if x == float("inf") else x-1) def main():
    N, M, L = map(int, input().split())
    adj = [{} for _ in range(N)]
    for _ in range(M):
        A, B, C = map(int, input().split())
        adj[A-1][B-1] = C
        adj[B-1][A-1] = C
    dst = [[float("inf")] * N for _ in range(N)]
    for i in range(N):
        dst[i][i] = 0
        for j in adj[i]:
            dst[i][j] = adj[i][j]
    calc(N, dst)
    ans = [[float("inf")] * N for _ in range(N)]
    for i in range(N):
        ans[i][i] = 0
        for j in range(i+1, N):
            if dst[i][j] <= L:
                ans[i][j] = 1
                ans[j][i] = 1
    calc(N, ans)
    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        x = ans[s-1][t-1]
        print(-1 if x == float("inf") else x-1) main
import sys
input = sys.stdin.readline


def calc(N, g):
    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])


def main():
    N, M, L = map(int, input().split())
    adj = [{} for _ in range(N)]
    for _ in range(M):
        A, B, C = map(int, input().split())
        adj[A-1][B-1] = C
        adj[B-1][A-1] = C
    dst = [[float("inf")] * N for _ in range(N)]
    for i in range(N):
        dst[i][i] = 0
        for j in adj[i]:
            dst[i][j] = adj[i][j]
    calc(N, dst)
    ans = [[float("inf")] * N for _ in range(N)]
    for i in range(N):
        ans[i][i] = 0
        for j in range(i+1, N):
            if dst[i][j] <= L:
                ans[i][j] = 1
                ans[j][i] = 1
    calc(N, ans)
    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        x = ans[s-1][t-1]
        print(-1 if x == float("inf") else x-1)


if __name__ == "__main__":
    main()
