def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    inf = 10**17
    #mod = 10**9 + 7

    N,M,L = map(int, input().split())
    dp = [[inf]*N for _ in range(N)]
    for i in range(N):
        dp[i][i] = 0
    for _ in range(M):
        a,b,c = map(int, input().split())
        dp[a-1][b-1] = c
        dp[b-1][a-1] = c

    #kを経由してiからjに行く行き方を考える
    #これで上手く行くのは与えられた辺の和しか考えていないため
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if dp[i][j] > dp[i][k] + dp[k][j]:
                    dp[i][j] = dp[j][i] = dp[i][k]+dp[k][j]

    dp2 =  [[inf]*N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if dp[i][j] <= L:
                dp2[i][j] = dp2[j][i] = 1

    for k in range(N):
        for i in range(N):
            for j in range(N):
                if dp2[i][j] > dp2[i][k] + dp2[k][j]:
                    dp2[i][j] = dp2[j][i] = dp2[i][k]+dp2[k][j]

    q = int(input())
    for _ in range(q):
        s, t = map(int, input().split())
        if dp2[s-1][t-1] == inf:
            print(-1)
        else:
            print(dp2[s-1][t-1]-1)

if __name__ == '__main__':
    main() def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    inf = 10**17
    #mod = 10**9 + 7

    N,M,L = map(int, input().split())
    dp = [[inf]*N for _ in range(N)]
    for i in range(N):
        dp[i][i] = 0
    for _ in range(M):
        a,b,c = map(int, input().split())
        dp[a-1][b-1] = c
        dp[b-1][a-1] = c

    #kを経由してiからjに行く行き方を考える
    #これで上手く行くのは与えられた辺の和しか考えていないため
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if dp[i][j] > dp[i][k] + dp[k][j]:
                    dp[i][j] = dp[j][i] = dp[i][k]+dp[k][j]

    dp2 =  [[inf]*N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if dp[i][j] <= L:
                dp2[i][j] = dp2[j][i] = 1

    for k in range(N):
        for i in range(N):
            for j in range(N):
                if dp2[i][j] > dp2[i][k] + dp2[k][j]:
                    dp2[i][j] = dp2[j][i] = dp2[i][k]+dp2[k][j]

    q = int(input())
    for _ in range(q):
        s, t = map(int, input().split())
        if dp2[s-1][t-1] == inf:
            print(-1)
        else:
            print(dp2[s-1][t-1]-1) main import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 from collections import Counter, deque from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left,bisect_right from heapq import heapify, heappop, heappush import math math inf = 10**17 inf 10**17 10 17 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 dp = [[inf]*N for _ in range(N)] dp [[inf]*N for _ in range(N)] for i in range(N):
        dp[i][i] = 0
     i range(N) range N dp[i][i] = 0 dp[i][i] [i] dp i i 0 for _ in range(M):
        a,b,c = map(int, input().split())
        dp[a-1][b-1] = c
        dp[b-1][a-1] = c

    #kを経由してiからjに行く行き方を考える
    #これで上手く行くのは与えられた辺の和しか考えていないため
     _ 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 dp[a-1][b-1] = c dp[a-1][b-1] [a-1] dp a-1 a 1 b-1 b 1 c dp[b-1][a-1] = c dp[b-1][a-1] [b-1] dp b-1 b 1 a-1 a 1 c for k in range(N):
        for i in range(N):
            for j in range(N):
                if dp[i][j] > dp[i][k] + dp[k][j]:
                    dp[i][j] = dp[j][i] = dp[i][k]+dp[k][j]

     k range(N) range N for i in range(N):
            for j in range(N):
                if dp[i][j] > dp[i][k] + dp[k][j]:
                    dp[i][j] = dp[j][i] = dp[i][k]+dp[k][j]

     i range(N) range N for j in range(N):
                if dp[i][j] > dp[i][k] + dp[k][j]:
                    dp[i][j] = dp[j][i] = dp[i][k]+dp[k][j]

     j range(N) range N if dp[i][j] > dp[i][k] + dp[k][j]:
                    dp[i][j] = dp[j][i] = dp[i][k]+dp[k][j]

     dp[i][j] > dp[i][k] + dp[k][j] dp[i][j] [i] dp i j dp[i][k] + dp[k][j] dp[i][k] [i] dp i k dp[k][j] [k] dp k j dp[i][j] = dp[j][i] = dp[i][k]+dp[k][j] dp[i][j] [i] dp i j dp[i][k]+dp[k][j] dp[i][k] [i] dp i k dp[k][j] [k] dp k j = dp[j][i] = dp[i][k]+dp[k][j] dp[j][i] [j] dp j i dp[i][k]+dp[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 dp2 =  [[inf]*N for _ in range(N)] dp2 [[inf]*N for _ in range(N)] for i in range(N):
        for j in range(N):
            if dp[i][j] <= L:
                dp2[i][j] = dp2[j][i] = 1

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

     j range(N) range N if dp[i][j] <= L:
                dp2[i][j] = dp2[j][i] = 1

     dp[i][j] <= L dp[i][j] [i] dp i j L dp2[i][j] = dp2[j][i] = 1 dp2[i][j] [i] dp2 i j 1 = dp2[j][i] = 1 dp2[j][i] [j] dp2 j i 1 for k in range(N):
        for i in range(N):
            for j in range(N):
                if dp2[i][j] > dp2[i][k] + dp2[k][j]:
                    dp2[i][j] = dp2[j][i] = dp2[i][k]+dp2[k][j]

     k range(N) range N for i in range(N):
            for j in range(N):
                if dp2[i][j] > dp2[i][k] + dp2[k][j]:
                    dp2[i][j] = dp2[j][i] = dp2[i][k]+dp2[k][j]

     i range(N) range N for j in range(N):
                if dp2[i][j] > dp2[i][k] + dp2[k][j]:
                    dp2[i][j] = dp2[j][i] = dp2[i][k]+dp2[k][j]

     j range(N) range N if dp2[i][j] > dp2[i][k] + dp2[k][j]:
                    dp2[i][j] = dp2[j][i] = dp2[i][k]+dp2[k][j]

     dp2[i][j] > dp2[i][k] + dp2[k][j] dp2[i][j] [i] dp2 i j dp2[i][k] + dp2[k][j] dp2[i][k] [i] dp2 i k dp2[k][j] [k] dp2 k j dp2[i][j] = dp2[j][i] = dp2[i][k]+dp2[k][j] dp2[i][j] [i] dp2 i j dp2[i][k]+dp2[k][j] dp2[i][k] [i] dp2 i k dp2[k][j] [k] dp2 k j = dp2[j][i] = dp2[i][k]+dp2[k][j] dp2[j][i] [j] dp2 j i dp2[i][k]+dp2[k][j] q = int(input()) q int(input()) int input() input for _ in range(q):
        s, t = map(int, input().split())
        if dp2[s-1][t-1] == inf:
            print(-1)
        else:
            print(dp2[s-1][t-1]-1) _ range(q) range q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t if dp2[s-1][t-1] == inf:
            print(-1)
        else:
            print(dp2[s-1][t-1]-1) dp2[s-1][t-1] == inf dp2[s-1][t-1] [s-1] dp2 s-1 s 1 t-1 t 1 inf print(-1) print -1 print(dp2[s-1][t-1]-1) print dp2[s-1][t-1]-1 dp2[s-1][t-1] [s-1] dp2 s-1 s 1 t-1 t 1 1 if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    inf = 10**17
    #mod = 10**9 + 7

    N,M,L = map(int, input().split())
    dp = [[inf]*N for _ in range(N)]
    for i in range(N):
        dp[i][i] = 0
    for _ in range(M):
        a,b,c = map(int, input().split())
        dp[a-1][b-1] = c
        dp[b-1][a-1] = c

    #kを経由してiからjに行く行き方を考える
    #これで上手く行くのは与えられた辺の和しか考えていないため
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if dp[i][j] > dp[i][k] + dp[k][j]:
                    dp[i][j] = dp[j][i] = dp[i][k]+dp[k][j]

    dp2 =  [[inf]*N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if dp[i][j] <= L:
                dp2[i][j] = dp2[j][i] = 1

    for k in range(N):
        for i in range(N):
            for j in range(N):
                if dp2[i][j] > dp2[i][k] + dp2[k][j]:
                    dp2[i][j] = dp2[j][i] = dp2[i][k]+dp2[k][j]

    q = int(input())
    for _ in range(q):
        s, t = map(int, input().split())
        if dp2[s-1][t-1] == inf:
            print(-1)
        else:
            print(dp2[s-1][t-1]-1) def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    inf = 10**17
    #mod = 10**9 + 7

    N,M,L = map(int, input().split())
    dp = [[inf]*N for _ in range(N)]
    for i in range(N):
        dp[i][i] = 0
    for _ in range(M):
        a,b,c = map(int, input().split())
        dp[a-1][b-1] = c
        dp[b-1][a-1] = c

    #kを経由してiからjに行く行き方を考える
    #これで上手く行くのは与えられた辺の和しか考えていないため
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if dp[i][j] > dp[i][k] + dp[k][j]:
                    dp[i][j] = dp[j][i] = dp[i][k]+dp[k][j]

    dp2 =  [[inf]*N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if dp[i][j] <= L:
                dp2[i][j] = dp2[j][i] = 1

    for k in range(N):
        for i in range(N):
            for j in range(N):
                if dp2[i][j] > dp2[i][k] + dp2[k][j]:
                    dp2[i][j] = dp2[j][i] = dp2[i][k]+dp2[k][j]

    q = int(input())
    for _ in range(q):
        s, t = map(int, input().split())
        if dp2[s-1][t-1] == inf:
            print(-1)
        else:
            print(dp2[s-1][t-1]-1) main
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    inf = 10**17
    #mod = 10**9 + 7

    N,M,L = map(int, input().split())
    dp = [[inf]*N for _ in range(N)]
    for i in range(N):
        dp[i][i] = 0
    for _ in range(M):
        a,b,c = map(int, input().split())
        dp[a-1][b-1] = c
        dp[b-1][a-1] = c

    #kを経由してiからjに行く行き方を考える
    #これで上手く行くのは与えられた辺の和しか考えていないため
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if dp[i][j] > dp[i][k] + dp[k][j]:
                    dp[i][j] = dp[j][i] = dp[i][k]+dp[k][j]

    dp2 =  [[inf]*N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if dp[i][j] <= L:
                dp2[i][j] = dp2[j][i] = 1

    for k in range(N):
        for i in range(N):
            for j in range(N):
                if dp2[i][j] > dp2[i][k] + dp2[k][j]:
                    dp2[i][j] = dp2[j][i] = dp2[i][k]+dp2[k][j]

    q = int(input())
    for _ in range(q):
        s, t = map(int, input().split())
        if dp2[s-1][t-1] == inf:
            print(-1)
        else:
            print(dp2[s-1][t-1]-1)

if __name__ == '__main__':
    main()