import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    wn, wm, l = list(map(int, readline().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, readline().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])

    inf = 10 ** 13
    wwl = [[inf] * wn for _ in range(wn)]
    for i in range(wn):
        wwl[i][i] = 0

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

    for i in range(wn):
        for j in range(wn):
            for k in range(wn):
                wwl[j][k] = min(wwl[j][k], wwl[j][i] + wwl[i][k])
    q = int(readline())
    for i in range(q):
        s, t = list(map(int, readline().split()))
        print(wwl[s-1][t-1] - 1 if wwl[s-1][t-1] != inf else -1)


if __name__ == '__main__':
    solve() import sys sys def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    wn, wm, l = list(map(int, readline().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, readline().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])

    inf = 10 ** 13
    wwl = [[inf] * wn for _ in range(wn)]
    for i in range(wn):
        wwl[i][i] = 0

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

    for i in range(wn):
        for j in range(wn):
            for k in range(wn):
                wwl[j][k] = min(wwl[j][k], wwl[j][i] + wwl[i][k])
    q = int(readline())
    for i in range(q):
        s, t = list(map(int, readline().split()))
        print(wwl[s-1][t-1] - 1 if wwl[s-1][t-1] != inf else -1) solve readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 wn, wm, l = list(map(int, readline().split())) wn list(map(int, readline().split())) list map(int, readline().split()) map int readline().split() ().split () readline split wm l 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, readline().split()))
        wl[wa - 1][wb - 1] = wc
        wl[wb - 1][wa - 1] = wc

     i range(wm) range wm wa, wb, wc = list(map(int, readline().split())) wa list(map(int, readline().split())) list map(int, readline().split()) map int readline().split() ().split () readline 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 = 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 wwl = [[inf] * wn for _ in range(wn)] wwl [[inf] * wn for _ in range(wn)] for i in range(wn):
        wwl[i][i] = 0

     i range(wn) range wn wwl[i][i] = 0 wwl[i][i] [i] wwl i i 0 for i in range(wn):
        for j in range(wn):
            if i != j and wl[i][j] <= l:
                wwl[i][j] = 1

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

     j range(wn) range wn if i != j and wl[i][j] <= l:
                wwl[i][j] = 1

     i != j and wl[i][j] <= l i != j i j wl[i][j] <= l wl[i][j] [i] wl i j l wwl[i][j] = 1 wwl[i][j] [i] wwl i j 1 for i in range(wn):
        for j in range(wn):
            for k in range(wn):
                wwl[j][k] = min(wwl[j][k], wwl[j][i] + wwl[i][k])
     i range(wn) range wn for j in range(wn):
            for k in range(wn):
                wwl[j][k] = min(wwl[j][k], wwl[j][i] + wwl[i][k])
     j range(wn) range wn for k in range(wn):
                wwl[j][k] = min(wwl[j][k], wwl[j][i] + wwl[i][k])
     k range(wn) range wn wwl[j][k] = min(wwl[j][k], wwl[j][i] + wwl[i][k]) wwl[j][k] [j] wwl j k min(wwl[j][k], wwl[j][i] + wwl[i][k]) min wwl[j][k] [j] wwl j k wwl[j][i] + wwl[i][k] wwl[j][i] [j] wwl j i wwl[i][k] [i] wwl i k q = int(readline()) q int(readline()) int readline() readline for i in range(q):
        s, t = list(map(int, readline().split()))
        print(wwl[s-1][t-1] - 1 if wwl[s-1][t-1] != inf else -1) i range(q) range q s, t = list(map(int, readline().split())) s list(map(int, readline().split())) list map(int, readline().split()) map int readline().split() ().split () readline split t print(wwl[s-1][t-1] - 1 if wwl[s-1][t-1] != inf else -1) print wwl[s-1][t-1] - 1 if wwl[s-1][t-1] != inf else -1 wwl[s-1][t-1] != inf wwl[s-1][t-1] [s-1] wwl s-1 s 1 t-1 t 1 inf wwl[s-1][t-1] - 1 wwl[s-1][t-1] [s-1] wwl s-1 s 1 t-1 t 1 1 -1 if __name__ == '__main__':
    solve() __name__ == '__main__' __name__ '__main__' solve() solve def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    wn, wm, l = list(map(int, readline().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, readline().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])

    inf = 10 ** 13
    wwl = [[inf] * wn for _ in range(wn)]
    for i in range(wn):
        wwl[i][i] = 0

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

    for i in range(wn):
        for j in range(wn):
            for k in range(wn):
                wwl[j][k] = min(wwl[j][k], wwl[j][i] + wwl[i][k])
    q = int(readline())
    for i in range(q):
        s, t = list(map(int, readline().split()))
        print(wwl[s-1][t-1] - 1 if wwl[s-1][t-1] != inf else -1) def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    wn, wm, l = list(map(int, readline().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, readline().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])

    inf = 10 ** 13
    wwl = [[inf] * wn for _ in range(wn)]
    for i in range(wn):
        wwl[i][i] = 0

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

    for i in range(wn):
        for j in range(wn):
            for k in range(wn):
                wwl[j][k] = min(wwl[j][k], wwl[j][i] + wwl[i][k])
    q = int(readline())
    for i in range(q):
        s, t = list(map(int, readline().split()))
        print(wwl[s-1][t-1] - 1 if wwl[s-1][t-1] != inf else -1) solve
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    wn, wm, l = list(map(int, readline().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, readline().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])

    inf = 10 ** 13
    wwl = [[inf] * wn for _ in range(wn)]
    for i in range(wn):
        wwl[i][i] = 0

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

    for i in range(wn):
        for j in range(wn):
            for k in range(wn):
                wwl[j][k] = min(wwl[j][k], wwl[j][i] + wwl[i][k])
    q = int(readline())
    for i in range(q):
        s, t = list(map(int, readline().split()))
        print(wwl[s-1][t-1] - 1 if wwl[s-1][t-1] != inf else -1)


if __name__ == '__main__':
    solve()
