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



l1 = [[10 ** 15 for i in range(n)] for i in range(n)]

for i in range(n):

    l1[i][i] = 0



for _ in range(m):

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

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

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



for i in range(n):

    for j in range(n):

        for k in range(n):

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



l2 = [[10 ** 4 for i in range(n)] for i in range(n)]

for i in range(n):

    l2[i][i] = 0



for i in range(n):

    for j in range(n):

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

            l2[i][j] = 1



for i in range(n):

    for j in range(n):

        for k in range(n):

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



q = int(eval(input()))

lq = []

for _ in range(q):

    lq.append(list(map(int, input().split())))



for sq in lq:

    res = l2[sq[0] - 1][sq[1] - 1]

    if res == 10 ** 4:

        print((-1))

    else:

        print((res - 1))

def wf(l, n):

    for i in range(n):

        for j in range(n):

            for k in range(n):

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

    return l





def main():

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



    l1 = [[10 ** 15 for i in range(n)] for i in range(n)]



    for _ in range(m):

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

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

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



    l1 = wf(l1, n)



    l2 = [[10 ** 4 for i in range(n)] for i in range(n)]



    for i in range(n):

        for j in range(n):

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

                l2[i][j] = 1



    l2 = wf(l2, n)



    q = int(eval(input()))

    lq = []

    for _ in range(q):

        lq.append(list(map(int, input().split())))



    for sq in lq:

        res = l2[sq[0] - 1][sq[1] - 1]

        if res == 10 ** 4:

            print((-1))

        else:

            print((res - 1))





main()

n, m, l = list(map(int, input().split()))
l1 = [[10**15 for i in range(n)] for i in range(n)]
for i in range(n):
    l1[i][i] = 0
for _ in range(m):
    a, b, c = list(map(int, input().split()))
    l1[a - 1][b - 1] = c
    l1[b - 1][a - 1] = c
for i in range(n):
    for j in range(n):
        for k in range(n):
            l1[j][k] = min(l1[j][k], l1[j][i] + l1[i][k])
l2 = [[10**4 for i in range(n)] for i in range(n)]
for i in range(n):
    l2[i][i] = 0
for i in range(n):
    for j in range(n):
        if l1[i][j] <= l:
            l2[i][j] = 1
for i in range(n):
    for j in range(n):
        for k in range(n):
            l2[j][k] = min(l2[j][k], l2[j][i] + l2[i][k])
q = int(eval(input()))
lq = []
for _ in range(q):
    lq.append(list(map(int, input().split())))
for sq in lq:
    res = l2[sq[0] - 1][sq[1] - 1]
    if res == 10**4:
        print((-1))
    else:
        print((res - 1))

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


def main():
    n, m, l = list(map(int, input().split()))
    l1 = [[10**15 for i in range(n)] for i in range(n)]
    for _ in range(m):
        a, b, c = list(map(int, input().split()))
        l1[a - 1][b - 1] = c
        l1[b - 1][a - 1] = c
    l1 = wf(l1, n)
    l2 = [[10**4 for i in range(n)] for i in range(n)]
    for i in range(n):
        for j in range(n):
            if l1[i][j] <= l:
                l2[i][j] = 1
    l2 = wf(l2, n)
    q = int(eval(input()))
    lq = []
    for _ in range(q):
        lq.append(list(map(int, input().split())))
    for sq in lq:
        res = l2[sq[0] - 1][sq[1] - 1]
        if res == 10**4:
            print((-1))
        else:
            print((res - 1))


main()

-n, m, l = list(map(int, input().split())) -l1 = [[10**15 for i in range(n)] for i in range(n)] -for i in range(n): -    l1[i][i] = 0 -for _ in range(m): -    a, b, c = list(map(int, input().split())) -    l1[a - 1][b - 1] = c -    l1[b - 1][a - 1] = c -for i in range(n): -    for j in range(n): -        for k in range(n): -            l1[j][k] = min(l1[j][k], l1[j][i] + l1[i][k]) -l2 = [[10**4 for i in range(n)] for i in range(n)] -for i in range(n): -    l2[i][i] = 0 -for i in range(n): -    for j in range(n): -        if l1[i][j] <= l: -            l2[i][j] = 1 -for i in range(n): -    for j in range(n): -        for k in range(n): -            l2[j][k] = min(l2[j][k], l2[j][i] + l2[i][k]) -q = int(eval(input())) -lq = [] -for _ in range(q): -    lq.append(list(map(int, input().split()))) -for sq in lq: -    res = l2[sq[0] - 1][sq[1] - 1] -    if res == 10**4: -        print((-1)) -    else: -        print((res - 1)) +def wf(l, n): +    for i in range(n): +        for j in range(n): +            for k in range(n): +                l[j][k] = min(l[j][k], l[j][i] + l[i][k]) +    return l + + +def main(): +    n, m, l = list(map(int, input().split())) +    l1 = [[10**15 for i in range(n)] for i in range(n)] +    for _ in range(m): +        a, b, c = list(map(int, input().split())) +        l1[a - 1][b - 1] = c +        l1[b - 1][a - 1] = c +    l1 = wf(l1, n) +    l2 = [[10**4 for i in range(n)] for i in range(n)] +    for i in range(n): +        for j in range(n): +            if l1[i][j] <= l: +                l2[i][j] = 1 +    l2 = wf(l2, n) +    q = int(eval(input())) +    lq = [] +    for _ in range(q): +        lq.append(list(map(int, input().split()))) +    for sq in lq: +        res = l2[sq[0] - 1][sq[1] - 1] +        if res == 10**4: +            print((-1)) +        else: +            print((res - 1)) + + +main()