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

dist = [[10**12] * N for _ in range(N)]

for i in range(N):

    dist[i][i] = 0

    

for _ in range(M):

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

    if c <= L:

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



for k in range(N):

    for i in range(N):

        for j in range(N):

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



old_dist = [row[:] for row in dist]

for i in range(N):

    for j in range(N):

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

            dist[i][j] = 1

            

for k in range(N):

    for i in range(N):

        for j in range(N):

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



Q = int(eval(input()))

for _ in range(Q):

    start, end= list(map(int, input().split()))

    if dist[start-1][end-1] < 10**12:

    	print((dist[start-1][end-1] - 1))

    else:

        print((-1))
#juppy's code for testing run time only. 

def main():

    import sys

    input = sys.stdin.readline

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

    d = [[10**12]*n for _ in [0]*n]

    for i in range(m):

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

        if l >= c:

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

    for i in range(n):

        d[i][i] = 0

 

    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])

 

    edge = [[10**12]*n for _ in [0]*n]

    for i in range(n):

        for j in range(n):

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

                edge[i][j] = 1

 

    for k in range(n):

        for i in range(n):

            for j in range(n):

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

 

    q = int(eval(input()))

    for _ in [0]*q:

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

        if edge[s-1][t-1] >= 10**12:

            print((-1))

        else:

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

 

if __name__ == '__main__':

    main()
N, M, L = list(map(int, input().split()))
dist = [[10**12] * N for _ in range(N)]
for i in range(N):
    dist[i][i] = 0
for _ in range(M):
    a, b, c = list(map(int, input().split()))
    if c <= L:
        dist[a - 1][b - 1] = dist[b - 1][a - 1] = c
for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
old_dist = [row[:] for row in dist]
for i in range(N):
    for j in range(N):
        if old_dist[i][j] <= L:
            dist[i][j] = 1
for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
Q = int(eval(input()))
for _ in range(Q):
    start, end = list(map(int, input().split()))
    if dist[start - 1][end - 1] < 10**12:
        print((dist[start - 1][end - 1] - 1))
    else:
        print((-1))

# juppy's code for testing run time only.
def main():
    import sys

    input = sys.stdin.readline
    n, m, l = list(map(int, input().split()))
    d = [[10**12] * n for _ in [0] * n]
    for i in range(m):
        a, b, c = list(map(int, input().split()))
        if l >= c:
            d[a - 1][b - 1] = d[b - 1][a - 1] = c
    for i in range(n):
        d[i][i] = 0
    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])
    edge = [[10**12] * n for _ in [0] * n]
    for i in range(n):
        for j in range(n):
            if d[i][j] <= l:
                edge[i][j] = 1
    for k in range(n):
        for i in range(n):
            for j in range(n):
                edge[i][j] = min(edge[i][j], edge[i][k] + edge[k][j])
    q = int(eval(input()))
    for _ in [0] * q:
        s, t = list(map(int, input().split()))
        if edge[s - 1][t - 1] >= 10**12:
            print((-1))
        else:
            print((edge[s - 1][t - 1] - 1))


if __name__ == "__main__":
    main()

-N, M, L = list(map(int, input().split())) -dist = [[10**12] * N for _ in range(N)] -for i in range(N): -    dist[i][i] = 0 -for _ in range(M): -    a, b, c = list(map(int, input().split())) -    if c <= L: -        dist[a - 1][b - 1] = dist[b - 1][a - 1] = c -for k in range(N): -    for i in range(N): -        for j in range(N): -            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) -old_dist = [row[:] for row in dist] -for i in range(N): -    for j in range(N): -        if old_dist[i][j] <= L: -            dist[i][j] = 1 -for k in range(N): -    for i in range(N): -        for j in range(N): -            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) -Q = int(eval(input())) -for _ in range(Q): -    start, end = list(map(int, input().split())) -    if dist[start - 1][end - 1] < 10**12: -        print((dist[start - 1][end - 1] - 1)) -    else: -        print((-1)) +# juppy's code for testing run time only. +def main(): +    import sys + +    input = sys.stdin.readline +    n, m, l = list(map(int, input().split())) +    d = [[10**12] * n for _ in [0] * n] +    for i in range(m): +        a, b, c = list(map(int, input().split())) +        if l >= c: +            d[a - 1][b - 1] = d[b - 1][a - 1] = c +    for i in range(n): +        d[i][i] = 0 +    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]) +    edge = [[10**12] * n for _ in [0] * n] +    for i in range(n): +        for j in range(n): +            if d[i][j] <= l: +                edge[i][j] = 1 +    for k in range(n): +        for i in range(n): +            for j in range(n): +                edge[i][j] = min(edge[i][j], edge[i][k] + edge[k][j]) +    q = int(eval(input())) +    for _ in [0] * q: +        s, t = list(map(int, input().split())) +        if edge[s - 1][t - 1] >= 10**12: +            print((-1)) +        else: +            print((edge[s - 1][t - 1] - 1)) + + +if __name__ == "__main__": +    main()