import sys

input = sys.stdin.readline



def main():

    n, m, l = list(map(int, input().split()))

    dist = [[float('inf')]*n for _ in range(n)]

    

    def Warshall_Floyd(d):

        for k in range(n):

            for i in range(n):

                for j in range(n):

                    d[i][j] = min(d[i][j], d[i][k]+d[k][j])

        return d

      

    for _ in range(m):

        a, b, c = list(map(int, input().split()))

        if c > l:

            continue

        a -= 1

        b -= 1

        dist[a][b] = c

        dist[b][a] = c



    Warshall_Floyd(dist)



    dist2 = [[float('inf')]*n for _ in range(n)]

    for i in range(n):

        for j in range(n):

            if dist[i][j] <= l:

                dist2[i][j] = 1

    

    Warshall_Floyd(dist2)



    q = int(eval(input()))

    for _ in range(q):

        s, t = list(map(int, input().split()))

        s -= 1

        t -= 1

        if dist2[s][t] == float('inf'):

            print((-1))

            continue

        ans = dist2[s][t]

        print((ans-1))



if __name__ == "__main__":

    main()
import sys

input = sys.stdin.readline



def main():

    n, m, l = list(map(int, input().split()))

    f_inf = float('inf')

    dist = [[f_inf]*n for _ in range(n)]

    

    def Warshall_Floyd(d):

        for k in range(n):

            for i in range(n):

                for j in range(n):

                    d[i][j] = min(d[i][j], d[i][k]+d[k][j])

        return d

      

    for _ in range(m):

        a, b, c = list(map(int, input().split()))

        a -= 1

        b -= 1

        dist[a][b] = c

        dist[b][a] = c



    Warshall_Floyd(dist)



    dist2 = [[f_inf]*n for _ in range(n)]

    for i in range(n):

        for j in range(n):

            if dist[i][j] <= l:

                dist2[i][j] = 1

    

    Warshall_Floyd(dist2)



    q = int(eval(input()))

    for _ in range(q):

        s, t = list(map(int, input().split()))

        s -= 1

        t -= 1

        if dist2[s][t] == f_inf:

            print((-1))

        else:

          ans = dist2[s][t]

          print((ans-1))



if __name__ == "__main__":

    main()
import sys

input = sys.stdin.readline


def main():
    n, m, l = list(map(int, input().split()))
    dist = [[float("inf")] * n for _ in range(n)]

    def Warshall_Floyd(d):
        for k in range(n):
            for i in range(n):
                for j in range(n):
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j])
        return d

    for _ in range(m):
        a, b, c = list(map(int, input().split()))
        if c > l:
            continue
        a -= 1
        b -= 1
        dist[a][b] = c
        dist[b][a] = c
    Warshall_Floyd(dist)
    dist2 = [[float("inf")] * n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            if dist[i][j] <= l:
                dist2[i][j] = 1
    Warshall_Floyd(dist2)
    q = int(eval(input()))
    for _ in range(q):
        s, t = list(map(int, input().split()))
        s -= 1
        t -= 1
        if dist2[s][t] == float("inf"):
            print((-1))
            continue
        ans = dist2[s][t]
        print((ans - 1))


if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline


def main():
    n, m, l = list(map(int, input().split()))
    f_inf = float("inf")
    dist = [[f_inf] * n for _ in range(n)]

    def Warshall_Floyd(d):
        for k in range(n):
            for i in range(n):
                for j in range(n):
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j])
        return d

    for _ in range(m):
        a, b, c = list(map(int, input().split()))
        a -= 1
        b -= 1
        dist[a][b] = c
        dist[b][a] = c
    Warshall_Floyd(dist)
    dist2 = [[f_inf] * n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            if dist[i][j] <= l:
                dist2[i][j] = 1
    Warshall_Floyd(dist2)
    q = int(eval(input()))
    for _ in range(q):
        s, t = list(map(int, input().split()))
        s -= 1
        t -= 1
        if dist2[s][t] == f_inf:
            print((-1))
        else:
            ans = dist2[s][t]
            print((ans - 1))


if __name__ == "__main__":
    main()

-    dist = [[float("inf")] * n for _ in range(n)] +    f_inf = float("inf") +    dist = [[f_inf] * n for _ in range(n)] -        if c > l: -            continue -    dist2 = [[float("inf")] * n for _ in range(n)] +    dist2 = [[f_inf] * n for _ in range(n)] -        if dist2[s][t] == float("inf"): +        if dist2[s][t] == f_inf: -            continue -        ans = dist2[s][t] -        print((ans - 1)) +        else: +            ans = dist2[s][t] +            print((ans - 1))