import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N, M, L = map(int, input().split())
        ABC = [tuple(map(int, input().split())) for _ in range(M)]
        Q = int(input())
        st = [tuple(map(int, input().split())) for _ in range(Q)]

        INF = 10 **10
        load = [[INF] * N for _ in range(N)]
        for a, b, c in ABC:
            a -= 1
            b -= 1
            load[a][b] = c
            load[b][a] = c

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

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

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

        for s, t in st:
            s -=1
            t-=1
            if load2[s][t] == INF:
                print(-1)
            else:
                print(load2[s][t] - 1)


# Run main
if __name__ == '__main__':
    AtCoder().main() import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline class AtCoder:
    def main(self):
        N, M, L = map(int, input().split())
        ABC = [tuple(map(int, input().split())) for _ in range(M)]
        Q = int(input())
        st = [tuple(map(int, input().split())) for _ in range(Q)]

        INF = 10 **10
        load = [[INF] * N for _ in range(N)]
        for a, b, c in ABC:
            a -= 1
            b -= 1
            load[a][b] = c
            load[b][a] = c

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

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

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

        for s, t in st:
            s -=1
            t-=1
            if load2[s][t] == INF:
                print(-1)
            else:
                print(load2[s][t] - 1)


# Run main AtCoder def main(self):
        N, M, L = map(int, input().split())
        ABC = [tuple(map(int, input().split())) for _ in range(M)]
        Q = int(input())
        st = [tuple(map(int, input().split())) for _ in range(Q)]

        INF = 10 **10
        load = [[INF] * N for _ in range(N)]
        for a, b, c in ABC:
            a -= 1
            b -= 1
            load[a][b] = c
            load[b][a] = c

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

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

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

        for s, t in st:
            s -=1
            t-=1
            if load2[s][t] == INF:
                print(-1)
            else:
                print(load2[s][t] - 1)


# Run main main N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L tuple(map(int, input().split())) for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) tuple(map(int, input().split())) tuple map(int, input().split()) map int input().split() ().split () input split ABC = [tuple(map(int, input().split())) for _ in range(M)] ABC [tuple(map(int, input().split())) for _ in range(M)] Q = int(input()) Q int(input()) int input() input tuple(map(int, input().split())) for _ in range(Q) for _ in range(Q) _ range(Q) range Q for _ in range(Q) tuple(map(int, input().split())) tuple map(int, input().split()) map int input().split() ().split () input split st = [tuple(map(int, input().split())) for _ in range(Q)] st [tuple(map(int, input().split())) for _ in range(Q)] INF = 10 **10 INF 10 **10 10 10 [INF] * N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF] * N [INF] INF N load = [[INF] * N for _ in range(N)] load [[INF] * N for _ in range(N)] for a, b, c in ABC:
            a -= 1
            b -= 1
            load[a][b] = c
            load[b][a] = c

         a b c ABC a -= 1 a 1 b -= 1 b 1 load[a][b] = c load[a][b] [a] load a b c load[b][a] = c load[b][a] [b] load b a c for k in range(N):
            for i in range(N):
                for j in range(N):
                    load[i][j] = min(load[i][j], load[i][k] + load[k][j])

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

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

         j range(N) range N load[i][j] = min(load[i][j], load[i][k] + load[k][j]) load[i][j] [i] load i j min(load[i][j], load[i][k] + load[k][j]) min load[i][j] [i] load i j load[i][k] + load[k][j] load[i][k] [i] load i k load[k][j] [k] load 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 load2 = [[INF] * N for _ in range(N)] load2 [[INF] * N for _ in range(N)] for i in range(N):
            for j in range(N):
                if load[i][j] <= L:
                    load2[i][j] = 1

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

         j range(N) range N if load[i][j] <= L:
                    load2[i][j] = 1

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

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

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

         j range(N) range N load2[i][j] = min(load2[i][j], load2[i][k] + load2[k][j]) load2[i][j] [i] load2 i j min(load2[i][j], load2[i][k] + load2[k][j]) min load2[i][j] [i] load2 i j load2[i][k] + load2[k][j] load2[i][k] [i] load2 i k load2[k][j] [k] load2 k j for s, t in st:
            s -=1
            t-=1
            if load2[s][t] == INF:
                print(-1)
            else:
                print(load2[s][t] - 1)


# Run main s t st s -=1 s 1 t-=1 t 1 if load2[s][t] == INF:
                print(-1)
            else:
                print(load2[s][t] - 1)


# Run main load2[s][t] == INF load2[s][t] [s] load2 s t INF print(-1) print -1 print(load2[s][t] - 1) print load2[s][t] - 1 load2[s][t] [s] load2 s t 1 self self if __name__ == '__main__':
    AtCoder().main() __name__ == '__main__' __name__ '__main__' AtCoder().main() ().main () AtCoder main input = sys.stdin.readline sys.stdin.readline input class AtCoder:
    def main(self):
        N, M, L = map(int, input().split())
        ABC = [tuple(map(int, input().split())) for _ in range(M)]
        Q = int(input())
        st = [tuple(map(int, input().split())) for _ in range(Q)]

        INF = 10 **10
        load = [[INF] * N for _ in range(N)]
        for a, b, c in ABC:
            a -= 1
            b -= 1
            load[a][b] = c
            load[b][a] = c

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

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

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

        for s, t in st:
            s -=1
            t-=1
            if load2[s][t] == INF:
                print(-1)
            else:
                print(load2[s][t] - 1)


# Run main class AtCoder:
    def main(self):
        N, M, L = map(int, input().split())
        ABC = [tuple(map(int, input().split())) for _ in range(M)]
        Q = int(input())
        st = [tuple(map(int, input().split())) for _ in range(Q)]

        INF = 10 **10
        load = [[INF] * N for _ in range(N)]
        for a, b, c in ABC:
            a -= 1
            b -= 1
            load[a][b] = c
            load[b][a] = c

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

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

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

        for s, t in st:
            s -=1
            t-=1
            if load2[s][t] == INF:
                print(-1)
            else:
                print(load2[s][t] - 1)


# Run main AtCoder
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N, M, L = map(int, input().split())
        ABC = [tuple(map(int, input().split())) for _ in range(M)]
        Q = int(input())
        st = [tuple(map(int, input().split())) for _ in range(Q)]

        INF = 10 **10
        load = [[INF] * N for _ in range(N)]
        for a, b, c in ABC:
            a -= 1
            b -= 1
            load[a][b] = c
            load[b][a] = c

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

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

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

        for s, t in st:
            s -=1
            t-=1
            if load2[s][t] == INF:
                print(-1)
            else:
                print(load2[s][t] - 1)


# Run main
if __name__ == '__main__':
    AtCoder().main()
