import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    wn, wm, wwl = list(map(int, input().rstrip('\n').split()))
    inf = 10 ** 13
    wl = [[inf] * wn for _ in range(wn)]
    for i in range(wn):
        wl[i][i] = 0

    for i in range(wm):
        wa, wb, wc = list(map(int, input().rstrip('\n').split()))
        wl[wa - 1][wb - 1] = wc
        wl[wb - 1][wa - 1] = wc

    for i in range(wn):
        for j in range(wn):
            for k in range(wn):
                wl[j][k] = min(wl[j][k], wl[j][i] + wl[i][k])

    nwl = [[inf] * wn for _ in range(wn)]
    for i in range(wn):
        for j in range(wn):
            if wl[i][j] <= wwl:
                nwl[i][j] = 1

    for i in range(wn):
        for j in range(wn):
            for k in range(wn):
                nwl[j][k] = min(nwl[j][k], nwl[j][i] + nwl[i][k])

    q = int(input().rstrip('\n'))
    for i in range(q):
        s, t = list(map(int, input().rstrip('\n').split()))
        print(nwl[s-1][t-1] - 1 if nwl[s-1][t-1] != inf else -1)


if __name__ == '__main__':
    solve() import sys sys def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    wn, wm, wwl = list(map(int, input().rstrip('\n').split()))
    inf = 10 ** 13
    wl = [[inf] * wn for _ in range(wn)]
    for i in range(wn):
        wl[i][i] = 0

    for i in range(wm):
        wa, wb, wc = list(map(int, input().rstrip('\n').split()))
        wl[wa - 1][wb - 1] = wc
        wl[wb - 1][wa - 1] = wc

    for i in range(wn):
        for j in range(wn):
            for k in range(wn):
                wl[j][k] = min(wl[j][k], wl[j][i] + wl[i][k])

    nwl = [[inf] * wn for _ in range(wn)]
    for i in range(wn):
        for j in range(wn):
            if wl[i][j] <= wwl:
                nwl[i][j] = 1

    for i in range(wn):
        for j in range(wn):
            for k in range(wn):
                nwl[j][k] = min(nwl[j][k], nwl[j][i] + nwl[i][k])

    q = int(input().rstrip('\n'))
    for i in range(q):
        s, t = list(map(int, input().rstrip('\n').split()))
        print(nwl[s-1][t-1] - 1 if nwl[s-1][t-1] != inf else -1) solve input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 wn, wm, wwl = list(map(int, input().rstrip('\n').split())) wn list(map(int, input().rstrip('\n').split())) list map(int, input().rstrip('\n').split()) map int input().rstrip('\n').split() ().rstrip('\n').split ().rstrip('\n') ().rstrip () input rstrip '\n' split wm wwl inf = 10 ** 13 inf 10 ** 13 10 13 [inf] * wn for _ in range(wn) for _ in range(wn) _ range(wn) range wn for _ in range(wn) [inf] * wn [inf] inf wn wl = [[inf] * wn for _ in range(wn)] wl [[inf] * wn for _ in range(wn)] for i in range(wn):
        wl[i][i] = 0

     i range(wn) range wn wl[i][i] = 0 wl[i][i] [i] wl i i 0 for i in range(wm):
        wa, wb, wc = list(map(int, input().rstrip('\n').split()))
        wl[wa - 1][wb - 1] = wc
        wl[wb - 1][wa - 1] = wc

     i range(wm) range wm wa, wb, wc = list(map(int, input().rstrip('\n').split())) wa list(map(int, input().rstrip('\n').split())) list map(int, input().rstrip('\n').split()) map int input().rstrip('\n').split() ().rstrip('\n').split ().rstrip('\n') ().rstrip () input rstrip '\n' split wb wc wl[wa - 1][wb - 1] = wc wl[wa - 1][wb - 1] [wa - 1] wl wa - 1 wa 1 wb - 1 wb 1 wc wl[wb - 1][wa - 1] = wc wl[wb - 1][wa - 1] [wb - 1] wl wb - 1 wb 1 wa - 1 wa 1 wc for i in range(wn):
        for j in range(wn):
            for k in range(wn):
                wl[j][k] = min(wl[j][k], wl[j][i] + wl[i][k])

     i range(wn) range wn for j in range(wn):
            for k in range(wn):
                wl[j][k] = min(wl[j][k], wl[j][i] + wl[i][k])

     j range(wn) range wn for k in range(wn):
                wl[j][k] = min(wl[j][k], wl[j][i] + wl[i][k])

     k range(wn) range wn wl[j][k] = min(wl[j][k], wl[j][i] + wl[i][k]) wl[j][k] [j] wl j k min(wl[j][k], wl[j][i] + wl[i][k]) min wl[j][k] [j] wl j k wl[j][i] + wl[i][k] wl[j][i] [j] wl j i wl[i][k] [i] wl i k [inf] * wn for _ in range(wn) for _ in range(wn) _ range(wn) range wn for _ in range(wn) [inf] * wn [inf] inf wn nwl = [[inf] * wn for _ in range(wn)] nwl [[inf] * wn for _ in range(wn)] for i in range(wn):
        for j in range(wn):
            if wl[i][j] <= wwl:
                nwl[i][j] = 1

     i range(wn) range wn for j in range(wn):
            if wl[i][j] <= wwl:
                nwl[i][j] = 1

     j range(wn) range wn if wl[i][j] <= wwl:
                nwl[i][j] = 1

     wl[i][j] <= wwl wl[i][j] [i] wl i j wwl nwl[i][j] = 1 nwl[i][j] [i] nwl i j 1 for i in range(wn):
        for j in range(wn):
            for k in range(wn):
                nwl[j][k] = min(nwl[j][k], nwl[j][i] + nwl[i][k])

     i range(wn) range wn for j in range(wn):
            for k in range(wn):
                nwl[j][k] = min(nwl[j][k], nwl[j][i] + nwl[i][k])

     j range(wn) range wn for k in range(wn):
                nwl[j][k] = min(nwl[j][k], nwl[j][i] + nwl[i][k])

     k range(wn) range wn nwl[j][k] = min(nwl[j][k], nwl[j][i] + nwl[i][k]) nwl[j][k] [j] nwl j k min(nwl[j][k], nwl[j][i] + nwl[i][k]) min nwl[j][k] [j] nwl j k nwl[j][i] + nwl[i][k] nwl[j][i] [j] nwl j i nwl[i][k] [i] nwl i k q = int(input().rstrip('\n')) q int(input().rstrip('\n')) int input().rstrip('\n') ().rstrip () input rstrip '\n' for i in range(q):
        s, t = list(map(int, input().rstrip('\n').split()))
        print(nwl[s-1][t-1] - 1 if nwl[s-1][t-1] != inf else -1) i range(q) range q s, t = list(map(int, input().rstrip('\n').split())) s list(map(int, input().rstrip('\n').split())) list map(int, input().rstrip('\n').split()) map int input().rstrip('\n').split() ().rstrip('\n').split ().rstrip('\n') ().rstrip () input rstrip '\n' split t print(nwl[s-1][t-1] - 1 if nwl[s-1][t-1] != inf else -1) print nwl[s-1][t-1] - 1 if nwl[s-1][t-1] != inf else -1 nwl[s-1][t-1] != inf nwl[s-1][t-1] [s-1] nwl s-1 s 1 t-1 t 1 inf nwl[s-1][t-1] - 1 nwl[s-1][t-1] [s-1] nwl s-1 s 1 t-1 t 1 1 -1 if __name__ == '__main__':
    solve() __name__ == '__main__' __name__ '__main__' solve() solve def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    wn, wm, wwl = list(map(int, input().rstrip('\n').split()))
    inf = 10 ** 13
    wl = [[inf] * wn for _ in range(wn)]
    for i in range(wn):
        wl[i][i] = 0

    for i in range(wm):
        wa, wb, wc = list(map(int, input().rstrip('\n').split()))
        wl[wa - 1][wb - 1] = wc
        wl[wb - 1][wa - 1] = wc

    for i in range(wn):
        for j in range(wn):
            for k in range(wn):
                wl[j][k] = min(wl[j][k], wl[j][i] + wl[i][k])

    nwl = [[inf] * wn for _ in range(wn)]
    for i in range(wn):
        for j in range(wn):
            if wl[i][j] <= wwl:
                nwl[i][j] = 1

    for i in range(wn):
        for j in range(wn):
            for k in range(wn):
                nwl[j][k] = min(nwl[j][k], nwl[j][i] + nwl[i][k])

    q = int(input().rstrip('\n'))
    for i in range(q):
        s, t = list(map(int, input().rstrip('\n').split()))
        print(nwl[s-1][t-1] - 1 if nwl[s-1][t-1] != inf else -1) def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    wn, wm, wwl = list(map(int, input().rstrip('\n').split()))
    inf = 10 ** 13
    wl = [[inf] * wn for _ in range(wn)]
    for i in range(wn):
        wl[i][i] = 0

    for i in range(wm):
        wa, wb, wc = list(map(int, input().rstrip('\n').split()))
        wl[wa - 1][wb - 1] = wc
        wl[wb - 1][wa - 1] = wc

    for i in range(wn):
        for j in range(wn):
            for k in range(wn):
                wl[j][k] = min(wl[j][k], wl[j][i] + wl[i][k])

    nwl = [[inf] * wn for _ in range(wn)]
    for i in range(wn):
        for j in range(wn):
            if wl[i][j] <= wwl:
                nwl[i][j] = 1

    for i in range(wn):
        for j in range(wn):
            for k in range(wn):
                nwl[j][k] = min(nwl[j][k], nwl[j][i] + nwl[i][k])

    q = int(input().rstrip('\n'))
    for i in range(q):
        s, t = list(map(int, input().rstrip('\n').split()))
        print(nwl[s-1][t-1] - 1 if nwl[s-1][t-1] != inf else -1) solve
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    wn, wm, wwl = list(map(int, input().rstrip('\n').split()))
    inf = 10 ** 13
    wl = [[inf] * wn for _ in range(wn)]
    for i in range(wn):
        wl[i][i] = 0

    for i in range(wm):
        wa, wb, wc = list(map(int, input().rstrip('\n').split()))
        wl[wa - 1][wb - 1] = wc
        wl[wb - 1][wa - 1] = wc

    for i in range(wn):
        for j in range(wn):
            for k in range(wn):
                wl[j][k] = min(wl[j][k], wl[j][i] + wl[i][k])

    nwl = [[inf] * wn for _ in range(wn)]
    for i in range(wn):
        for j in range(wn):
            if wl[i][j] <= wwl:
                nwl[i][j] = 1

    for i in range(wn):
        for j in range(wn):
            for k in range(wn):
                nwl[j][k] = min(nwl[j][k], nwl[j][i] + nwl[i][k])

    q = int(input().rstrip('\n'))
    for i in range(q):
        s, t = list(map(int, input().rstrip('\n').split()))
        print(nwl[s-1][t-1] - 1 if nwl[s-1][t-1] != inf else -1)


if __name__ == '__main__':
    solve()
