import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m, l = map(int, input().split())
    cost = [[f_inf] * n for _ in range(n)]
    for i in range(n):
        cost[i][i] = 0
    for _ in range(m):
        a, b, c = map(int, input().split())
        cost[a - 1][b - 1] = c
        cost[b - 1][a - 1] = c

    for k in range(n):
        for i in range(n):
            for j in range(n):
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])

    res = [[f_inf] * n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            if cost[i][j] <= l:
                res[i][j] = 1

    for k in range(n):
        for i in range(n):
            for j in range(n):
                res[i][j] = min(res[i][j], res[i][k] + res[k][j])

    q = int(input())
    for _ in range(q):
        s, t = map(int, input().split())
        print(-1 if res[s - 1][t - 1] == f_inf else res[s - 1][t - 1] - 1)


if __name__ == '__main__':
    resolve() import sys sys sys.setrecursionlimit(10 ** 7) sys.setrecursionlimit sys setrecursionlimit 10 ** 7 10 7 input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline f_inf = float('inf') f_inf float('inf') float 'inf' mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 def resolve():
    n, m, l = map(int, input().split())
    cost = [[f_inf] * n for _ in range(n)]
    for i in range(n):
        cost[i][i] = 0
    for _ in range(m):
        a, b, c = map(int, input().split())
        cost[a - 1][b - 1] = c
        cost[b - 1][a - 1] = c

    for k in range(n):
        for i in range(n):
            for j in range(n):
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])

    res = [[f_inf] * n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            if cost[i][j] <= l:
                res[i][j] = 1

    for k in range(n):
        for i in range(n):
            for j in range(n):
                res[i][j] = min(res[i][j], res[i][k] + res[k][j])

    q = int(input())
    for _ in range(q):
        s, t = map(int, input().split())
        print(-1 if res[s - 1][t - 1] == f_inf else res[s - 1][t - 1] - 1) resolve n, m, l = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m l [f_inf] * n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [f_inf] * n [f_inf] f_inf n cost = [[f_inf] * n for _ in range(n)] cost [[f_inf] * n for _ in range(n)] for i in range(n):
        cost[i][i] = 0
     i range(n) range n cost[i][i] = 0 cost[i][i] [i] cost i i 0 for _ in range(m):
        a, b, c = map(int, input().split())
        cost[a - 1][b - 1] = c
        cost[b - 1][a - 1] = c

     _ range(m) range m a, b, c = map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b c cost[a - 1][b - 1] = c cost[a - 1][b - 1] [a - 1] cost a - 1 a 1 b - 1 b 1 c cost[b - 1][a - 1] = c cost[b - 1][a - 1] [b - 1] cost b - 1 b 1 a - 1 a 1 c for k in range(n):
        for i in range(n):
            for j in range(n):
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])

     k range(n) range n for i in range(n):
            for j in range(n):
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])

     i range(n) range n for j in range(n):
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])

     j range(n) range n cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]) cost[i][j] [i] cost i j min(cost[i][j], cost[i][k] + cost[k][j]) min cost[i][j] [i] cost i j cost[i][k] + cost[k][j] cost[i][k] [i] cost i k cost[k][j] [k] cost k j [f_inf] * n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [f_inf] * n [f_inf] f_inf n res = [[f_inf] * n for _ in range(n)] res [[f_inf] * n for _ in range(n)] for i in range(n):
        for j in range(n):
            if cost[i][j] <= l:
                res[i][j] = 1

     i range(n) range n for j in range(n):
            if cost[i][j] <= l:
                res[i][j] = 1

     j range(n) range n if cost[i][j] <= l:
                res[i][j] = 1

     cost[i][j] <= l cost[i][j] [i] cost i j l res[i][j] = 1 res[i][j] [i] res i j 1 for k in range(n):
        for i in range(n):
            for j in range(n):
                res[i][j] = min(res[i][j], res[i][k] + res[k][j])

     k range(n) range n for i in range(n):
            for j in range(n):
                res[i][j] = min(res[i][j], res[i][k] + res[k][j])

     i range(n) range n for j in range(n):
                res[i][j] = min(res[i][j], res[i][k] + res[k][j])

     j range(n) range n res[i][j] = min(res[i][j], res[i][k] + res[k][j]) res[i][j] [i] res i j min(res[i][j], res[i][k] + res[k][j]) min res[i][j] [i] res i j res[i][k] + res[k][j] res[i][k] [i] res i k res[k][j] [k] res k j q = int(input()) q int(input()) int input() input for _ in range(q):
        s, t = map(int, input().split())
        print(-1 if res[s - 1][t - 1] == f_inf else res[s - 1][t - 1] - 1) _ range(q) range q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t print(-1 if res[s - 1][t - 1] == f_inf else res[s - 1][t - 1] - 1) print -1 if res[s - 1][t - 1] == f_inf else res[s - 1][t - 1] - 1 res[s - 1][t - 1] == f_inf res[s - 1][t - 1] [s - 1] res s - 1 s 1 t - 1 t 1 f_inf -1 res[s - 1][t - 1] - 1 res[s - 1][t - 1] [s - 1] res s - 1 s 1 t - 1 t 1 1 if __name__ == '__main__':
    resolve() __name__ == '__main__' __name__ '__main__' resolve() resolve input = sys.stdin.readline sys.stdin.readline input def resolve():
    n, m, l = map(int, input().split())
    cost = [[f_inf] * n for _ in range(n)]
    for i in range(n):
        cost[i][i] = 0
    for _ in range(m):
        a, b, c = map(int, input().split())
        cost[a - 1][b - 1] = c
        cost[b - 1][a - 1] = c

    for k in range(n):
        for i in range(n):
            for j in range(n):
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])

    res = [[f_inf] * n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            if cost[i][j] <= l:
                res[i][j] = 1

    for k in range(n):
        for i in range(n):
            for j in range(n):
                res[i][j] = min(res[i][j], res[i][k] + res[k][j])

    q = int(input())
    for _ in range(q):
        s, t = map(int, input().split())
        print(-1 if res[s - 1][t - 1] == f_inf else res[s - 1][t - 1] - 1) def resolve():
    n, m, l = map(int, input().split())
    cost = [[f_inf] * n for _ in range(n)]
    for i in range(n):
        cost[i][i] = 0
    for _ in range(m):
        a, b, c = map(int, input().split())
        cost[a - 1][b - 1] = c
        cost[b - 1][a - 1] = c

    for k in range(n):
        for i in range(n):
            for j in range(n):
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])

    res = [[f_inf] * n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            if cost[i][j] <= l:
                res[i][j] = 1

    for k in range(n):
        for i in range(n):
            for j in range(n):
                res[i][j] = min(res[i][j], res[i][k] + res[k][j])

    q = int(input())
    for _ in range(q):
        s, t = map(int, input().split())
        print(-1 if res[s - 1][t - 1] == f_inf else res[s - 1][t - 1] - 1) resolve f_inf = float('inf') float('inf') f_inf mod = 10 ** 9 + 7 10 ** 9 + 7 mod
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m, l = map(int, input().split())
    cost = [[f_inf] * n for _ in range(n)]
    for i in range(n):
        cost[i][i] = 0
    for _ in range(m):
        a, b, c = map(int, input().split())
        cost[a - 1][b - 1] = c
        cost[b - 1][a - 1] = c

    for k in range(n):
        for i in range(n):
            for j in range(n):
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])

    res = [[f_inf] * n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            if cost[i][j] <= l:
                res[i][j] = 1

    for k in range(n):
        for i in range(n):
            for j in range(n):
                res[i][j] = min(res[i][j], res[i][k] + res[k][j])

    q = int(input())
    for _ in range(q):
        s, t = map(int, input().split())
        print(-1 if res[s - 1][t - 1] == f_inf else res[s - 1][t - 1] - 1)


if __name__ == '__main__':
    resolve()
