mod = 10 ** 9 + 7
mod2 = 2**61+1
from collections import deque
import heapq
from bisect import bisect_left, insort_left, bisect_right

def iip(listed=True):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def iip_ord():
    return [ord(i) - ord("a") for i in input()]


def main():
    ans = solve()
    if ans is not None:
        print(ans)

def solve():
    N, M, L = iip()

    dis_table = [[10 ** 12 for _ in range(N)] for _ in range(N)]
    for i in range(N):
        dis_table[i][i] = 0

    for i in range(M):
        a, b, c = iip()
        a -= 1
        b -= 1
        if c <= L:
            dis_table[a][b] = c
            dis_table[b][a] = c

    for k in range(N):
        for i in range(N):
            for j in range(N):
                dis_table[i][j] = min(dis_table[i][j], dis_table[i][k] + dis_table[j][k])

    #print(dis_table)

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


    for i in range(N):
        for j in range(N):
            if dis_table[i][j] <= L:
                nt[i][j] = 1

    for i in range(N):
        nt[i][i] = 0

    for k in range(N):
        for i in range(N):
            for j in range(N):
                nt[i][j] = min(nt[i][j], nt[i][k] + nt[j][k])

    q = iip(False)
    ans = []

    for i in range(q):
        a, b = iip()
        c = nt[a-1][b-1]
        if c == 10**12:
            ans.append(-1)
        else:
            ans.append(c-1)

    split_print_enter(ans)


#####################################################ライブラリ集ここから

def split_print_space(s):
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):
    print("\n".join([str(i) for i in s]))


def koenai_saidai_x_index(sorted_list, n):
    l = 0
    r = len(sorted_list)
    if len(sorted_list) == 0:
        return False
    if sorted_list[0] > n:
        return False

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] == n:
            return x
        elif sorted_list[x] > n:
            r = x
        else:
            l = x
    return l


def searchsorted(sorted_list, n, side):
    if side not in ["right", "left"]:
        raise Exception("sideはrightかleftで指定してください")

    l = 0
    r = len(sorted_list)

    if n > sorted_list[-1]:
        # print(sorted_list)
        return len(sorted_list)
    if n < sorted_list[0]:
        return 0

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] > n:
            r = x
        elif sorted_list[x] < n:
            l = x
        else:
            if side == "left":
                r = x
            elif side == "right":
                l = x

    if side == "left":
        if sorted_list[l] == n:
            return r - 1
        else:
            return r

    if side == "right":
        if sorted_list[l] == n:
            return l + 1
        else:
            return l


def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        # print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):
    return power(n, mod - 2)


def power(n, p, mod_= mod):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_


if __name__ == "__main__":
    main() mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 mod2 = 2**61+1 mod2 2**61+1 2**61 2 61 1 from collections import deque import heapq heapq from bisect import bisect_left, insort_left, bisect_right def iip(listed=True):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret iip int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i ret = [int(i) for i in input().split()] ret [int(i) for i in input().split()] if len(ret) == 1 and not listed:
        return ret[0]
     len(ret) == 1 and not listed len(ret) == 1 len(ret) len ret 1 not listed listed return ret[0] ret[0] ret 0 return ret ret listed=True listed True def iip_ord():
    return [ord(i) - ord("a") for i in input()] iip_ord ord(i) - ord("a") for i in input() for i in input() i input() input for i in input() ord(i) - ord("a") ord(i) ord i ord("a") ord "a" return [ord(i) - ord("a") for i in input()] [ord(i) - ord("a") for i in input()] def main():
    ans = solve()
    if ans is not None:
        print(ans) main ans = solve() ans solve() solve if ans is not None:
        print(ans) ans is not None ans None print(ans) print ans def solve():
    N, M, L = iip()

    dis_table = [[10 ** 12 for _ in range(N)] for _ in range(N)]
    for i in range(N):
        dis_table[i][i] = 0

    for i in range(M):
        a, b, c = iip()
        a -= 1
        b -= 1
        if c <= L:
            dis_table[a][b] = c
            dis_table[b][a] = c

    for k in range(N):
        for i in range(N):
            for j in range(N):
                dis_table[i][j] = min(dis_table[i][j], dis_table[i][k] + dis_table[j][k])

    #print(dis_table)

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


    for i in range(N):
        for j in range(N):
            if dis_table[i][j] <= L:
                nt[i][j] = 1

    for i in range(N):
        nt[i][i] = 0

    for k in range(N):
        for i in range(N):
            for j in range(N):
                nt[i][j] = min(nt[i][j], nt[i][k] + nt[j][k])

    q = iip(False)
    ans = []

    for i in range(q):
        a, b = iip()
        c = nt[a-1][b-1]
        if c == 10**12:
            ans.append(-1)
        else:
            ans.append(c-1)

    split_print_enter(ans)


#####################################################ライブラリ集ここから solve N, M, L = iip() N iip() iip M L [10 ** 12 for _ in range(N)] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [10 ** 12 for _ in range(N)] dis_table = [[10 ** 12 for _ in range(N)] for _ in range(N)] dis_table [[10 ** 12 for _ in range(N)] for _ in range(N)] for i in range(N):
        dis_table[i][i] = 0

     i range(N) range N dis_table[i][i] = 0 dis_table[i][i] [i] dis_table i i 0 for i in range(M):
        a, b, c = iip()
        a -= 1
        b -= 1
        if c <= L:
            dis_table[a][b] = c
            dis_table[b][a] = c

     i range(M) range M a, b, c = iip() a iip() iip b c a -= 1 a 1 b -= 1 b 1 if c <= L:
            dis_table[a][b] = c
            dis_table[b][a] = c

     c <= L c L dis_table[a][b] = c dis_table[a][b] [a] dis_table a b c dis_table[b][a] = c dis_table[b][a] [b] dis_table b a c for k in range(N):
        for i in range(N):
            for j in range(N):
                dis_table[i][j] = min(dis_table[i][j], dis_table[i][k] + dis_table[j][k])

    #print(dis_table)

     k range(N) range N for i in range(N):
            for j in range(N):
                dis_table[i][j] = min(dis_table[i][j], dis_table[i][k] + dis_table[j][k])

    #print(dis_table)

     i range(N) range N for j in range(N):
                dis_table[i][j] = min(dis_table[i][j], dis_table[i][k] + dis_table[j][k])

    #print(dis_table)

     j range(N) range N dis_table[i][j] = min(dis_table[i][j], dis_table[i][k] + dis_table[j][k]) dis_table[i][j] [i] dis_table i j min(dis_table[i][j], dis_table[i][k] + dis_table[j][k]) min dis_table[i][j] [i] dis_table i j dis_table[i][k] + dis_table[j][k] dis_table[i][k] [i] dis_table i k dis_table[j][k] [j] dis_table j k [10 ** 12 for _ in range(N)] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [10 ** 12 for _ in range(N)] nt = [[10 ** 12 for _ in range(N)] for _ in range(N)] nt [[10 ** 12 for _ in range(N)] for _ in range(N)] for i in range(N):
        for j in range(N):
            if dis_table[i][j] <= L:
                nt[i][j] = 1

     i range(N) range N for j in range(N):
            if dis_table[i][j] <= L:
                nt[i][j] = 1

     j range(N) range N if dis_table[i][j] <= L:
                nt[i][j] = 1

     dis_table[i][j] <= L dis_table[i][j] [i] dis_table i j L nt[i][j] = 1 nt[i][j] [i] nt i j 1 for i in range(N):
        nt[i][i] = 0

     i range(N) range N nt[i][i] = 0 nt[i][i] [i] nt i i 0 for k in range(N):
        for i in range(N):
            for j in range(N):
                nt[i][j] = min(nt[i][j], nt[i][k] + nt[j][k])

     k range(N) range N for i in range(N):
            for j in range(N):
                nt[i][j] = min(nt[i][j], nt[i][k] + nt[j][k])

     i range(N) range N for j in range(N):
                nt[i][j] = min(nt[i][j], nt[i][k] + nt[j][k])

     j range(N) range N nt[i][j] = min(nt[i][j], nt[i][k] + nt[j][k]) nt[i][j] [i] nt i j min(nt[i][j], nt[i][k] + nt[j][k]) min nt[i][j] [i] nt i j nt[i][k] + nt[j][k] nt[i][k] [i] nt i k nt[j][k] [j] nt j k q = iip(False) q iip(False) iip False ans = [] ans [] for i in range(q):
        a, b = iip()
        c = nt[a-1][b-1]
        if c == 10**12:
            ans.append(-1)
        else:
            ans.append(c-1)

     i range(q) range q a, b = iip() a iip() iip b c = nt[a-1][b-1] c nt[a-1][b-1] [a-1] nt a-1 a 1 b-1 b 1 if c == 10**12:
            ans.append(-1)
        else:
            ans.append(c-1)

     c == 10**12 c 10**12 10 12 ans.append(-1) ans.append ans append -1 ans.append(c-1) ans.append ans append c-1 c 1 split_print_enter(ans) split_print_enter ans def split_print_space(s):
    print(" ".join([str(i) for i in s])) split_print_space str(i) for i in s for i in s i s for i in s str(i) str i print(" ".join([str(i) for i in s])) print " ".join([str(i) for i in s]) " ".join " " join [str(i) for i in s] s s def split_print_enter(s):
    print("\n".join([str(i) for i in s])) split_print_enter str(i) for i in s for i in s i s for i in s str(i) str i print("\n".join([str(i) for i in s])) print "\n".join([str(i) for i in s]) "\n".join "\n" join [str(i) for i in s] s s def koenai_saidai_x_index(sorted_list, n):
    l = 0
    r = len(sorted_list)
    if len(sorted_list) == 0:
        return False
    if sorted_list[0] > n:
        return False

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] == n:
            return x
        elif sorted_list[x] > n:
            r = x
        else:
            l = x
    return l koenai_saidai_x_index l = 0 l 0 r = len(sorted_list) r len(sorted_list) len sorted_list if len(sorted_list) == 0:
        return False
     len(sorted_list) == 0 len(sorted_list) len sorted_list 0 return False False if sorted_list[0] > n:
        return False

     sorted_list[0] > n sorted_list[0] sorted_list 0 n return False False while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] == n:
            return x
        elif sorted_list[x] > n:
            r = x
        else:
            l = x
     r - l > 1 r - l r l 1 x = (l + r) // 2 x (l + r) // 2 l + r l r 2 if sorted_list[x] == n:
            return x
        elif sorted_list[x] > n:
            r = x
        else:
            l = x
     sorted_list[x] == n sorted_list[x] sorted_list x n return x x elif sorted_list[x] > n:
            r = x
         sorted_list[x] > n sorted_list[x] sorted_list x n r = x r x l = x l x return l l sorted_list sorted_list n n def searchsorted(sorted_list, n, side):
    if side not in ["right", "left"]:
        raise Exception("sideはrightかleftで指定してください")

    l = 0
    r = len(sorted_list)

    if n > sorted_list[-1]:
        # print(sorted_list)
        return len(sorted_list)
    if n < sorted_list[0]:
        return 0

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] > n:
            r = x
        elif sorted_list[x] < n:
            l = x
        else:
            if side == "left":
                r = x
            elif side == "right":
                l = x

    if side == "left":
        if sorted_list[l] == n:
            return r - 1
        else:
            return r

    if side == "right":
        if sorted_list[l] == n:
            return l + 1
        else:
            return l searchsorted if side not in ["right", "left"]:
        raise Exception("sideはrightかleftで指定してください")

     side not in ["right", "left"] side ["right", "left"] "right" "left" raise Exception("sideはrightかleftで指定してください") Exception("sideはrightかleftで指定してください") Exception "sideはrightかleftで指定してください" l = 0 l 0 r = len(sorted_list) r len(sorted_list) len sorted_list if n > sorted_list[-1]:
        # print(sorted_list)
        return len(sorted_list)
     n > sorted_list[-1] n sorted_list[-1] sorted_list -1 return len(sorted_list) len(sorted_list) len sorted_list if n < sorted_list[0]:
        return 0

     n < sorted_list[0] n sorted_list[0] sorted_list 0 return 0 0 while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] > n:
            r = x
        elif sorted_list[x] < n:
            l = x
        else:
            if side == "left":
                r = x
            elif side == "right":
                l = x

     r - l > 1 r - l r l 1 x = (l + r) // 2 x (l + r) // 2 l + r l r 2 if sorted_list[x] > n:
            r = x
        elif sorted_list[x] < n:
            l = x
        else:
            if side == "left":
                r = x
            elif side == "right":
                l = x

     sorted_list[x] > n sorted_list[x] sorted_list x n r = x r x elif sorted_list[x] < n:
            l = x
         sorted_list[x] < n sorted_list[x] sorted_list x n l = x l x if side == "left":
                r = x
            elif side == "right":
                l = x

     side == "left" side "left" r = x r x elif side == "right":
                l = x

     side == "right" side "right" l = x l x if side == "left":
        if sorted_list[l] == n:
            return r - 1
        else:
            return r

     side == "left" side "left" if sorted_list[l] == n:
            return r - 1
        else:
            return r

     sorted_list[l] == n sorted_list[l] sorted_list l n return r - 1 r - 1 r 1 return r r if side == "right":
        if sorted_list[l] == n:
            return l + 1
        else:
            return l side == "right" side "right" if sorted_list[l] == n:
            return l + 1
        else:
            return l sorted_list[l] == n sorted_list[l] sorted_list l n return l + 1 l + 1 l 1 return l l sorted_list sorted_list n n side side def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret soinsuu_bunkai ret = [] ret [] for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
     i range(2, int(n ** 0.5) + 1) range 2 int(n ** 0.5) + 1 int(n ** 0.5) int n ** 0.5 n 0.5 1 while n % i == 0:
            n //= i
            ret.append(i)
         n % i == 0 n % i n i 0 n //= i n i ret.append(i) ret.append ret append i if i > n:
            break
     i > n i n break if n != 1:
        ret.append(n)
     n != 1 n 1 ret.append(n) ret.append ret append n return ret ret n n def conbination(n, r, mod, test=False):
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        # print(f"{n}C{r} = {ret}")
        pass
    return ret conbination if n <= 0:
        return 0
     n <= 0 n 0 return 0 0 if r == 0:
        return 1
     r == 0 r 0 return 1 1 if r < 0:
        return 0
     r < 0 r 0 return 0 0 if r == 1:
        return n
     r == 1 r 1 return n n ret = 1 ret 1 for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

     i range(n - r + 1, n + 1) range n - r + 1 n - r n r 1 n + 1 n 1 ret *= i ret i ret = ret % mod ret ret % mod ret mod bunbo = 1 bunbo 1 for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

     i range(1, r + 1) range 1 r + 1 r 1 bunbo *= i bunbo i bunbo = bunbo % mod bunbo bunbo % mod bunbo mod ret = (ret * inv(bunbo, mod)) % mod ret (ret * inv(bunbo, mod)) % mod ret * inv(bunbo, mod) ret inv(bunbo, mod) inv bunbo mod mod if test:
        # print(f"{n}C{r} = {ret}")
        pass
     test return ret ret n n r r mod mod test=False test False def inv(n, mod):
    return power(n, mod - 2) inv return power(n, mod - 2) power(n, mod - 2) power n mod - 2 mod 2 n n mod mod def power(n, p, mod_= mod):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_ power if p == 0:
        return 1
     p == 0 p 0 return 1 1 if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
     p % 2 == 0 p % 2 p 2 0 return (power(n, p // 2, mod_) ** 2) % mod_ (power(n, p // 2, mod_) ** 2) % mod_ power(n, p // 2, mod_) ** 2 power(n, p // 2, mod_) power n p // 2 p 2 mod_ 2 mod_ if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_ p % 2 == 1 p % 2 p 2 1 return (n * power(n, p - 1, mod_)) % mod_ (n * power(n, p - 1, mod_)) % mod_ n * power(n, p - 1, mod_) n power(n, p - 1, mod_) power n p - 1 p 1 mod_ mod_ n n p p mod_= mod mod_ mod if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def inv(n, mod):
    return power(n, mod - 2) def inv(n, mod):
    return power(n, mod - 2) inv def power(n, p, mod_= mod):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_ def power(n, p, mod_= mod):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_ power def conbination(n, r, mod, test=False):
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        # print(f"{n}C{r} = {ret}")
        pass
    return ret def conbination(n, r, mod, test=False):
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        # print(f"{n}C{r} = {ret}")
        pass
    return ret conbination def main():
    ans = solve()
    if ans is not None:
        print(ans) def main():
    ans = solve()
    if ans is not None:
        print(ans) main def searchsorted(sorted_list, n, side):
    if side not in ["right", "left"]:
        raise Exception("sideはrightかleftで指定してください")

    l = 0
    r = len(sorted_list)

    if n > sorted_list[-1]:
        # print(sorted_list)
        return len(sorted_list)
    if n < sorted_list[0]:
        return 0

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] > n:
            r = x
        elif sorted_list[x] < n:
            l = x
        else:
            if side == "left":
                r = x
            elif side == "right":
                l = x

    if side == "left":
        if sorted_list[l] == n:
            return r - 1
        else:
            return r

    if side == "right":
        if sorted_list[l] == n:
            return l + 1
        else:
            return l def searchsorted(sorted_list, n, side):
    if side not in ["right", "left"]:
        raise Exception("sideはrightかleftで指定してください")

    l = 0
    r = len(sorted_list)

    if n > sorted_list[-1]:
        # print(sorted_list)
        return len(sorted_list)
    if n < sorted_list[0]:
        return 0

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] > n:
            r = x
        elif sorted_list[x] < n:
            l = x
        else:
            if side == "left":
                r = x
            elif side == "right":
                l = x

    if side == "left":
        if sorted_list[l] == n:
            return r - 1
        else:
            return r

    if side == "right":
        if sorted_list[l] == n:
            return l + 1
        else:
            return l searchsorted def iip_ord():
    return [ord(i) - ord("a") for i in input()] def iip_ord():
    return [ord(i) - ord("a") for i in input()] iip_ord def iip(listed=True):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret def iip(listed=True):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret iip def koenai_saidai_x_index(sorted_list, n):
    l = 0
    r = len(sorted_list)
    if len(sorted_list) == 0:
        return False
    if sorted_list[0] > n:
        return False

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] == n:
            return x
        elif sorted_list[x] > n:
            r = x
        else:
            l = x
    return l def koenai_saidai_x_index(sorted_list, n):
    l = 0
    r = len(sorted_list)
    if len(sorted_list) == 0:
        return False
    if sorted_list[0] > n:
        return False

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] == n:
            return x
        elif sorted_list[x] > n:
            r = x
        else:
            l = x
    return l koenai_saidai_x_index mod2 = 2**61+1 2**61+1 mod2 def solve():
    N, M, L = iip()

    dis_table = [[10 ** 12 for _ in range(N)] for _ in range(N)]
    for i in range(N):
        dis_table[i][i] = 0

    for i in range(M):
        a, b, c = iip()
        a -= 1
        b -= 1
        if c <= L:
            dis_table[a][b] = c
            dis_table[b][a] = c

    for k in range(N):
        for i in range(N):
            for j in range(N):
                dis_table[i][j] = min(dis_table[i][j], dis_table[i][k] + dis_table[j][k])

    #print(dis_table)

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


    for i in range(N):
        for j in range(N):
            if dis_table[i][j] <= L:
                nt[i][j] = 1

    for i in range(N):
        nt[i][i] = 0

    for k in range(N):
        for i in range(N):
            for j in range(N):
                nt[i][j] = min(nt[i][j], nt[i][k] + nt[j][k])

    q = iip(False)
    ans = []

    for i in range(q):
        a, b = iip()
        c = nt[a-1][b-1]
        if c == 10**12:
            ans.append(-1)
        else:
            ans.append(c-1)

    split_print_enter(ans)


#####################################################ライブラリ集ここから def solve():
    N, M, L = iip()

    dis_table = [[10 ** 12 for _ in range(N)] for _ in range(N)]
    for i in range(N):
        dis_table[i][i] = 0

    for i in range(M):
        a, b, c = iip()
        a -= 1
        b -= 1
        if c <= L:
            dis_table[a][b] = c
            dis_table[b][a] = c

    for k in range(N):
        for i in range(N):
            for j in range(N):
                dis_table[i][j] = min(dis_table[i][j], dis_table[i][k] + dis_table[j][k])

    #print(dis_table)

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


    for i in range(N):
        for j in range(N):
            if dis_table[i][j] <= L:
                nt[i][j] = 1

    for i in range(N):
        nt[i][i] = 0

    for k in range(N):
        for i in range(N):
            for j in range(N):
                nt[i][j] = min(nt[i][j], nt[i][k] + nt[j][k])

    q = iip(False)
    ans = []

    for i in range(q):
        a, b = iip()
        c = nt[a-1][b-1]
        if c == 10**12:
            ans.append(-1)
        else:
            ans.append(c-1)

    split_print_enter(ans)


#####################################################ライブラリ集ここから solve def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret soinsuu_bunkai def split_print_space(s):
    print(" ".join([str(i) for i in s])) def split_print_space(s):
    print(" ".join([str(i) for i in s])) split_print_space def split_print_enter(s):
    print("\n".join([str(i) for i in s])) def split_print_enter(s):
    print("\n".join([str(i) for i in s])) split_print_enter mod = 10 ** 9 + 7 10 ** 9 + 7 mod
mod = 10 ** 9 + 7
mod2 = 2**61+1
from collections import deque
import heapq
from bisect import bisect_left, insort_left, bisect_right

def iip(listed=True):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def iip_ord():
    return [ord(i) - ord("a") for i in input()]


def main():
    ans = solve()
    if ans is not None:
        print(ans)

def solve():
    N, M, L = iip()

    dis_table = [[10 ** 12 for _ in range(N)] for _ in range(N)]
    for i in range(N):
        dis_table[i][i] = 0

    for i in range(M):
        a, b, c = iip()
        a -= 1
        b -= 1
        if c <= L:
            dis_table[a][b] = c
            dis_table[b][a] = c

    for k in range(N):
        for i in range(N):
            for j in range(N):
                dis_table[i][j] = min(dis_table[i][j], dis_table[i][k] + dis_table[j][k])

    #print(dis_table)

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


    for i in range(N):
        for j in range(N):
            if dis_table[i][j] <= L:
                nt[i][j] = 1

    for i in range(N):
        nt[i][i] = 0

    for k in range(N):
        for i in range(N):
            for j in range(N):
                nt[i][j] = min(nt[i][j], nt[i][k] + nt[j][k])

    q = iip(False)
    ans = []

    for i in range(q):
        a, b = iip()
        c = nt[a-1][b-1]
        if c == 10**12:
            ans.append(-1)
        else:
            ans.append(c-1)

    split_print_enter(ans)


#####################################################ライブラリ集ここから

def split_print_space(s):
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):
    print("\n".join([str(i) for i in s]))


def koenai_saidai_x_index(sorted_list, n):
    l = 0
    r = len(sorted_list)
    if len(sorted_list) == 0:
        return False
    if sorted_list[0] > n:
        return False

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] == n:
            return x
        elif sorted_list[x] > n:
            r = x
        else:
            l = x
    return l


def searchsorted(sorted_list, n, side):
    if side not in ["right", "left"]:
        raise Exception("sideはrightかleftで指定してください")

    l = 0
    r = len(sorted_list)

    if n > sorted_list[-1]:
        # print(sorted_list)
        return len(sorted_list)
    if n < sorted_list[0]:
        return 0

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] > n:
            r = x
        elif sorted_list[x] < n:
            l = x
        else:
            if side == "left":
                r = x
            elif side == "right":
                l = x

    if side == "left":
        if sorted_list[l] == n:
            return r - 1
        else:
            return r

    if side == "right":
        if sorted_list[l] == n:
            return l + 1
        else:
            return l


def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        # print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):
    return power(n, mod - 2)


def power(n, p, mod_= mod):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_


if __name__ == "__main__":
    main()