INF = float('inf')

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

cost = [[INF]*N for _ in range(N)]

for i in range(M):

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

    cost[a-1][b-1] = c

    cost[b-1][a-1] = c



for k in range(N):

    for i in range(N):

        for j in range(N):

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

                cost[i][j] = cost[i][k]+cost[k][j]



for i in range(N):

    for j in range(N):

        if cost[i][j] > L:

            cost[i][j] = INF

        else:

            cost[i][j] = 1



for k in range(N):

    for i in range(N):

        for j in range(N):

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

                cost[i][j] = cost[i][k]+cost[k][j]



for i in range(N):

    for j in range(N):

        if cost[i][j] == INF:

            cost[i][j] = -1

        else:

            cost[i][j] -= 1



Q = int(eval(input()))



for i in range(Q):

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

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



from scipy.sparse.csgraph import floyd_warshall as fw

INF = float('inf')

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

cost = [[INF]*N for _ in range(N)]

for i in range(M):

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

    cost[a-1][b-1] = c

    cost[b-1][a-1] = c



cost = fw(cost)



for i in range(N):

    for j in range(N):

        if cost[i][j] > L:

            cost[i][j] = INF

        else:

            cost[i][j] = 1



cost = fw(cost)



for i in range(N):

    for j in range(N):

        if cost[i][j] == INF:

            cost[i][j] = -1

        else:

            cost[i][j] -= 1



Q = int(eval(input()))



for i in range(Q):

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

    print((int(cost[s-1][t-1])))
INF = float("inf")
N, M, L = list(map(int, input().split()))
cost = [[INF] * N for _ in range(N)]
for i in range(M):
    a, b, c = list(map(int, input().split()))
    cost[a - 1][b - 1] = c
    cost[b - 1][a - 1] = c
for k in range(N):
    for i in range(N):
        for j in range(N):
            if cost[i][j] > cost[i][k] + cost[k][j]:
                cost[i][j] = cost[i][k] + cost[k][j]
for i in range(N):
    for j in range(N):
        if cost[i][j] > L:
            cost[i][j] = INF
        else:
            cost[i][j] = 1
for k in range(N):
    for i in range(N):
        for j in range(N):
            if cost[i][j] > cost[i][k] + cost[k][j]:
                cost[i][j] = cost[i][k] + cost[k][j]
for i in range(N):
    for j in range(N):
        if cost[i][j] == INF:
            cost[i][j] = -1
        else:
            cost[i][j] -= 1
Q = int(eval(input()))
for i in range(Q):
    s, t = list(map(int, input().split()))
    print((cost[s - 1][t - 1]))

from scipy.sparse.csgraph import floyd_warshall as fw

INF = float("inf")
N, M, L = list(map(int, input().split()))
cost = [[INF] * N for _ in range(N)]
for i in range(M):
    a, b, c = list(map(int, input().split()))
    cost[a - 1][b - 1] = c
    cost[b - 1][a - 1] = c
cost = fw(cost)
for i in range(N):
    for j in range(N):
        if cost[i][j] > L:
            cost[i][j] = INF
        else:
            cost[i][j] = 1
cost = fw(cost)
for i in range(N):
    for j in range(N):
        if cost[i][j] == INF:
            cost[i][j] = -1
        else:
            cost[i][j] -= 1
Q = int(eval(input()))
for i in range(Q):
    s, t = list(map(int, input().split()))
    print((int(cost[s - 1][t - 1])))

+from scipy.sparse.csgraph import floyd_warshall as fw + -for k in range(N): -    for i in range(N): -        for j in range(N): -            if cost[i][j] > cost[i][k] + cost[k][j]: -                cost[i][j] = cost[i][k] + cost[k][j] +cost = fw(cost) -for k in range(N): -    for i in range(N): -        for j in range(N): -            if cost[i][j] > cost[i][k] + cost[k][j]: -                cost[i][j] = cost[i][k] + cost[k][j] +cost = fw(cost) -    print((cost[s - 1][t - 1])) +    print((int(cost[s - 1][t - 1])))