import sys



def input():

    return sys.stdin.readline()[:-1]



N,M,L = list(map(int,input().split()))



e_list = [[] for i in range(N)]



def warshall_floyd(d):

    #d[i][j]: iからjへの最短距離

    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



d = [[float("inf") for i in range(N)] for i in range(N)] 

#d[u][v] : 辺uvのコスト(存在しないときはinf)

for i in range(M):

    x,y,z = list(map(int,input().split()))

    if z<=L:

        d[x-1][y-1] = z

        d[y-1][x-1] = z



for i in range(N):

    d[i][i] = 0 #自身のところに行くコストは０



d = warshall_floyd(d)



e_list = [[] for i in range(N)]



d2 = [[float("inf") for i in range(N)] for i in range(N)]



for i in range(N):

    for j in range(i+1,N):

        if d[i][j] <= L:

            d2[i][j] = 1

            d2[j][i] = 1



d2 = warshall_floyd(d2)



Q = int(eval(input()))

for i in range(Q):

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

    s,t = s-1,t-1

    if d2[s][t]>10**9:

        print((-1))

    else:

        print((d2[s][t]-1))

import sys



sys.setrecursionlimit(500000)

def input():

    return sys.stdin.readline()[:-1]



def main():

    N,M,L = list(map(int,input().split()))

    e_list = [[] for i in range(N)]

    for i in range(M):

        A,B,C = list(map(int,input().split()))

        A,B = A-1,B-1

        e_list[A].append((B,C))

        e_list[B].append((A,C))



    INF = float('inf')

    D = [[INF]*N for i in range(N)]

    for i in range(N):

        for j,d in e_list[i]:

            D[i][j]=d



    for k in range(N):

        for i in range(N):

            for j in range(N):

                if D[i][j]>D[i][k]+D[k][j]:

                    D[i][j] = D[i][k]+D[k][j]



    E = [[INF]*N for i in range(N)]



    for i in range(N):

        for j in range(N):

            if D[i][j]<=L:

                E[i][j]=1



    for k in range(N):

        for i in range(N):

            for j in range(N):

                if E[i][j]>E[i][k]+E[k][j]:

                    E[i][j] = E[i][k]+E[k][j]



    Q = int(eval(input()))

    for i in range(Q):

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

        s,t = s-1,t-1

        if E[s][t]>10**28:

            print((-1))

        else:

            print((E[s][t]-1))

            

if __name__ == '__main__':

    main()



import sys


def input():
    return sys.stdin.readline()[:-1]


N, M, L = list(map(int, input().split()))
e_list = [[] for i in range(N)]


def warshall_floyd(d):
    # d[i][j]: iからjへの最短距離
    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


d = [[float("inf") for i in range(N)] for i in range(N)]
# d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(M):
    x, y, z = list(map(int, input().split()))
    if z <= L:
        d[x - 1][y - 1] = z
        d[y - 1][x - 1] = z
for i in range(N):
    d[i][i] = 0  # 自身のところに行くコストは０
d = warshall_floyd(d)
e_list = [[] for i in range(N)]
d2 = [[float("inf") for i in range(N)] for i in range(N)]
for i in range(N):
    for j in range(i + 1, N):
        if d[i][j] <= L:
            d2[i][j] = 1
            d2[j][i] = 1
d2 = warshall_floyd(d2)
Q = int(eval(input()))
for i in range(Q):
    s, t = list(map(int, input().split()))
    s, t = s - 1, t - 1
    if d2[s][t] > 10**9:
        print((-1))
    else:
        print((d2[s][t] - 1))

import sys

sys.setrecursionlimit(500000)


def input():
    return sys.stdin.readline()[:-1]


def main():
    N, M, L = list(map(int, input().split()))
    e_list = [[] for i in range(N)]
    for i in range(M):
        A, B, C = list(map(int, input().split()))
        A, B = A - 1, B - 1
        e_list[A].append((B, C))
        e_list[B].append((A, C))
    INF = float("inf")
    D = [[INF] * N for i in range(N)]
    for i in range(N):
        for j, d in e_list[i]:
            D[i][j] = d
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if D[i][j] > D[i][k] + D[k][j]:
                    D[i][j] = D[i][k] + D[k][j]
    E = [[INF] * N for i in range(N)]
    for i in range(N):
        for j in range(N):
            if D[i][j] <= L:
                E[i][j] = 1
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if E[i][j] > E[i][k] + E[k][j]:
                    E[i][j] = E[i][k] + E[k][j]
    Q = int(eval(input()))
    for i in range(Q):
        s, t = list(map(int, input().split()))
        s, t = s - 1, t - 1
        if E[s][t] > 10**28:
            print((-1))
        else:
            print((E[s][t] - 1))


if __name__ == "__main__":
    main()

+ +sys.setrecursionlimit(500000) -N, M, L = list(map(int, input().split())) -e_list = [[] for i in range(N)] - - -def warshall_floyd(d): -    # d[i][j]: iからjへの最短距離 +def main(): +    N, M, L = list(map(int, input().split())) +    e_list = [[] for i in range(N)] +    for i in range(M): +        A, B, C = list(map(int, input().split())) +        A, B = A - 1, B - 1 +        e_list[A].append((B, C)) +        e_list[B].append((A, C)) +    INF = float("inf") +    D = [[INF] * N for i in range(N)] +    for i in range(N): +        for j, d in e_list[i]: +            D[i][j] = d -                d[i][j] = min(d[i][j], d[i][k] + d[k][j]) -    return d +                if D[i][j] > D[i][k] + D[k][j]: +                    D[i][j] = D[i][k] + D[k][j] +    E = [[INF] * N for i in range(N)] +    for i in range(N): +        for j in range(N): +            if D[i][j] <= L: +                E[i][j] = 1 +    for k in range(N): +        for i in range(N): +            for j in range(N): +                if E[i][j] > E[i][k] + E[k][j]: +                    E[i][j] = E[i][k] + E[k][j] +    Q = int(eval(input())) +    for i in range(Q): +        s, t = list(map(int, input().split())) +        s, t = s - 1, t - 1 +        if E[s][t] > 10**28: +            print((-1)) +        else: +            print((E[s][t] - 1)) -d = [[float("inf") for i in range(N)] for i in range(N)] -# d[u][v] : 辺uvのコスト(存在しないときはinf) -for i in range(M): -    x, y, z = list(map(int, input().split())) -    if z <= L: -        d[x - 1][y - 1] = z -        d[y - 1][x - 1] = z -for i in range(N): -    d[i][i] = 0  # 自身のところに行くコストは０ -d = warshall_floyd(d) -e_list = [[] for i in range(N)] -d2 = [[float("inf") for i in range(N)] for i in range(N)] -for i in range(N): -    for j in range(i + 1, N): -        if d[i][j] <= L: -            d2[i][j] = 1 -            d2[j][i] = 1 -d2 = warshall_floyd(d2) -Q = int(eval(input())) -for i in range(Q): -    s, t = list(map(int, input().split())) -    s, t = s - 1, t - 1 -    if d2[s][t] > 10**9: -        print((-1)) -    else: -        print((d2[s][t] - 1)) +if __name__ == "__main__": +    main()