from math import isinf


class WarshallFloyd(object):

    def __init__(self, adj):
        """
        ワーシャル・フロイド法によって全頂点間の最短距離を O(|V|^3) で計算する。

        :param adj: 隣接行列 adj[i][j] でi番目の頂点からj番目の頂点へのコストを示す パスがなければINF
        """
        self._dist = adj  # 各頂点間の最短距離 初期値として隣接行列をそのまま用い、[i, i]要素を0に初期化する
        for i in range(len(adj)):
            self._dist[i][i] = 0

        self._solve()

    def _solve(self):
        v_len = len(self._dist)
        for i in range(v_len):  # 経由する頂点
            for j in range(v_len):  # 開始頂点
                for k in range(v_len):  # 終端
                    self._dist[j][k] = min(self._dist[j][k], self._dist[j][i] + self._dist[i][k])

    def distance(self, start, goal):
        return self._dist[start][goal]

    def path(self, start, goal):
        pass


N, M, L = map(int, input().split())
adj = [[float('inf') for _ in range(N)] for _ in range(N)]
for A, B, C in [tuple(map(int, input().split())) for _ in range(M)]:
    adj[A - 1][B - 1] = C
    adj[B - 1][A - 1] = C

wf = WarshallFloyd(adj)

adj2 = [[float('inf') for _ in range(N)] for _ in range(N)]
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        if wf.distance(i, j) <= L:
            adj2[i][j] = 1
wf2 = WarshallFloyd(adj2)

Q = int(input())
for s, t in [tuple(map(int, input().split())) for _ in range(Q)]:
    ans = wf2.distance(s - 1, t - 1) - 1
    if isinf(ans):
        print(-1)
    else:
        print(ans) from math import isinf class WarshallFloyd(object):

    def __init__(self, adj):
        """
        ワーシャル・フロイド法によって全頂点間の最短距離を O(|V|^3) で計算する。

        :param adj: 隣接行列 adj[i][j] でi番目の頂点からj番目の頂点へのコストを示す パスがなければINF
        """
        self._dist = adj  # 各頂点間の最短距離 初期値として隣接行列をそのまま用い、[i, i]要素を0に初期化する
        for i in range(len(adj)):
            self._dist[i][i] = 0

        self._solve()

    def _solve(self):
        v_len = len(self._dist)
        for i in range(v_len):  # 経由する頂点
            for j in range(v_len):  # 開始頂点
                for k in range(v_len):  # 終端
                    self._dist[j][k] = min(self._dist[j][k], self._dist[j][i] + self._dist[i][k])

    def distance(self, start, goal):
        return self._dist[start][goal]

    def path(self, start, goal):
        pass WarshallFloyd def __init__(self, adj):
        """
        ワーシャル・フロイド法によって全頂点間の最短距離を O(|V|^3) で計算する。

        :param adj: 隣接行列 adj[i][j] でi番目の頂点からj番目の頂点へのコストを示す パスがなければINF
        """
        self._dist = adj  # 各頂点間の最短距離 初期値として隣接行列をそのまま用い、[i, i]要素を0に初期化する
        for i in range(len(adj)):
            self._dist[i][i] = 0

        self._solve()

     __init__ """
        ワーシャル・フロイド法によって全頂点間の最短距離を O(|V|^3) で計算する。

        :param adj: 隣接行列 adj[i][j] でi番目の頂点からj番目の頂点へのコストを示す パスがなければINF
        """ self._dist = adj self._dist self _dist adj for i in range(len(adj)):
            self._dist[i][i] = 0

         i range(len(adj)) range len(adj) len adj self._dist[i][i] = 0 self._dist[i][i] self._dist[i] self._dist self _dist i i 0 self._solve() self._solve self _solve self self adj adj def _solve(self):
        v_len = len(self._dist)
        for i in range(v_len):  # 経由する頂点
            for j in range(v_len):  # 開始頂点
                for k in range(v_len):  # 終端
                    self._dist[j][k] = min(self._dist[j][k], self._dist[j][i] + self._dist[i][k])

     _solve v_len = len(self._dist) v_len len(self._dist) len self._dist self _dist for i in range(v_len):  # 経由する頂点
            for j in range(v_len):  # 開始頂点
                for k in range(v_len):  # 終端
                    self._dist[j][k] = min(self._dist[j][k], self._dist[j][i] + self._dist[i][k])

     i range(v_len) range v_len for j in range(v_len):  # 開始頂点
                for k in range(v_len):  # 終端
                    self._dist[j][k] = min(self._dist[j][k], self._dist[j][i] + self._dist[i][k])

     j range(v_len) range v_len for k in range(v_len):  # 終端
                    self._dist[j][k] = min(self._dist[j][k], self._dist[j][i] + self._dist[i][k])

     k range(v_len) range v_len self._dist[j][k] = min(self._dist[j][k], self._dist[j][i] + self._dist[i][k]) self._dist[j][k] self._dist[j] self._dist self _dist j k min(self._dist[j][k], self._dist[j][i] + self._dist[i][k]) min self._dist[j][k] self._dist[j] self._dist self _dist j k self._dist[j][i] + self._dist[i][k] self._dist[j][i] self._dist[j] self._dist self _dist j i self._dist[i][k] self._dist[i] self._dist self _dist i k self self def distance(self, start, goal):
        return self._dist[start][goal]

     distance return self._dist[start][goal] self._dist[start][goal] self._dist[start] self._dist self _dist start goal self self start start goal goal def path(self, start, goal):
        pass path self self start start goal goal object N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L [float('inf') for _ in range(N)] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [float('inf') for _ in range(N)] adj = [[float('inf') for _ in range(N)] for _ in range(N)] adj [[float('inf') for _ in range(N)] for _ in range(N)] for A, B, C in [tuple(map(int, input().split())) for _ in range(M)]:
    adj[A - 1][B - 1] = C
    adj[B - 1][A - 1] = C A B C [tuple(map(int, input().split())) for _ in range(M)] adj[A - 1][B - 1] = C adj[A - 1][B - 1] [A - 1] adj A - 1 A 1 B - 1 B 1 C adj[B - 1][A - 1] = C adj[B - 1][A - 1] [B - 1] adj B - 1 B 1 A - 1 A 1 C wf = WarshallFloyd(adj) wf WarshallFloyd(adj) WarshallFloyd adj [float('inf') for _ in range(N)] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [float('inf') for _ in range(N)] adj2 = [[float('inf') for _ in range(N)] for _ in range(N)] adj2 [[float('inf') for _ in range(N)] for _ in range(N)] for i in range(N):
    for j in range(N):
        if i == j:
            continue
        if wf.distance(i, j) <= L:
            adj2[i][j] = 1 i range(N) range N for j in range(N):
        if i == j:
            continue
        if wf.distance(i, j) <= L:
            adj2[i][j] = 1 j range(N) range N if i == j:
            continue
         i == j i j continue if wf.distance(i, j) <= L:
            adj2[i][j] = 1 wf.distance(i, j) <= L wf.distance(i, j) wf.distance wf distance i j L adj2[i][j] = 1 adj2[i][j] [i] adj2 i j 1 wf2 = WarshallFloyd(adj2) wf2 WarshallFloyd(adj2) WarshallFloyd adj2 Q = int(input()) Q int(input()) int input() input for s, t in [tuple(map(int, input().split())) for _ in range(Q)]:
    ans = wf2.distance(s - 1, t - 1) - 1
    if isinf(ans):
        print(-1)
    else:
        print(ans) s t [tuple(map(int, input().split())) for _ in range(Q)] ans = wf2.distance(s - 1, t - 1) - 1 ans wf2.distance(s - 1, t - 1) - 1 wf2.distance(s - 1, t - 1) wf2.distance wf2 distance s - 1 s 1 t - 1 t 1 1 if isinf(ans):
        print(-1)
    else:
        print(ans) isinf(ans) isinf ans print(-1) print -1 print(ans) print ans wf2 = WarshallFloyd(adj2) WarshallFloyd(adj2) wf2 N, M, L = map(int, input().split()) map(int, input().split()) N wf = WarshallFloyd(adj) WarshallFloyd(adj) wf M, L = map(int, input().split()) map(int, input().split()) M L = map(int, input().split()) map(int, input().split()) L Q = int(input()) int(input()) Q ans = wf2.distance(s - 1, t - 1) - 1 wf2.distance(s - 1, t - 1) - 1 ans adj2 = [[float('inf') for _ in range(N)] for _ in range(N)] [[float('inf') for _ in range(N)] for _ in range(N)] adj2 adj = [[float('inf') for _ in range(N)] for _ in range(N)] [[float('inf') for _ in range(N)] for _ in range(N)] adj class WarshallFloyd(object):

    def __init__(self, adj):
        """
        ワーシャル・フロイド法によって全頂点間の最短距離を O(|V|^3) で計算する。

        :param adj: 隣接行列 adj[i][j] でi番目の頂点からj番目の頂点へのコストを示す パスがなければINF
        """
        self._dist = adj  # 各頂点間の最短距離 初期値として隣接行列をそのまま用い、[i, i]要素を0に初期化する
        for i in range(len(adj)):
            self._dist[i][i] = 0

        self._solve()

    def _solve(self):
        v_len = len(self._dist)
        for i in range(v_len):  # 経由する頂点
            for j in range(v_len):  # 開始頂点
                for k in range(v_len):  # 終端
                    self._dist[j][k] = min(self._dist[j][k], self._dist[j][i] + self._dist[i][k])

    def distance(self, start, goal):
        return self._dist[start][goal]

    def path(self, start, goal):
        pass class WarshallFloyd(object):

    def __init__(self, adj):
        """
        ワーシャル・フロイド法によって全頂点間の最短距離を O(|V|^3) で計算する。

        :param adj: 隣接行列 adj[i][j] でi番目の頂点からj番目の頂点へのコストを示す パスがなければINF
        """
        self._dist = adj  # 各頂点間の最短距離 初期値として隣接行列をそのまま用い、[i, i]要素を0に初期化する
        for i in range(len(adj)):
            self._dist[i][i] = 0

        self._solve()

    def _solve(self):
        v_len = len(self._dist)
        for i in range(v_len):  # 経由する頂点
            for j in range(v_len):  # 開始頂点
                for k in range(v_len):  # 終端
                    self._dist[j][k] = min(self._dist[j][k], self._dist[j][i] + self._dist[i][k])

    def distance(self, start, goal):
        return self._dist[start][goal]

    def path(self, start, goal):
        pass WarshallFloyd
from math import isinf


class WarshallFloyd(object):

    def __init__(self, adj):
        """
        ワーシャル・フロイド法によって全頂点間の最短距離を O(|V|^3) で計算する。

        :param adj: 隣接行列 adj[i][j] でi番目の頂点からj番目の頂点へのコストを示す パスがなければINF
        """
        self._dist = adj  # 各頂点間の最短距離 初期値として隣接行列をそのまま用い、[i, i]要素を0に初期化する
        for i in range(len(adj)):
            self._dist[i][i] = 0

        self._solve()

    def _solve(self):
        v_len = len(self._dist)
        for i in range(v_len):  # 経由する頂点
            for j in range(v_len):  # 開始頂点
                for k in range(v_len):  # 終端
                    self._dist[j][k] = min(self._dist[j][k], self._dist[j][i] + self._dist[i][k])

    def distance(self, start, goal):
        return self._dist[start][goal]

    def path(self, start, goal):
        pass


N, M, L = map(int, input().split())
adj = [[float('inf') for _ in range(N)] for _ in range(N)]
for A, B, C in [tuple(map(int, input().split())) for _ in range(M)]:
    adj[A - 1][B - 1] = C
    adj[B - 1][A - 1] = C

wf = WarshallFloyd(adj)

adj2 = [[float('inf') for _ in range(N)] for _ in range(N)]
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        if wf.distance(i, j) <= L:
            adj2[i][j] = 1
wf2 = WarshallFloyd(adj2)

Q = int(input())
for s, t in [tuple(map(int, input().split())) for _ in range(Q)]:
    ans = wf2.distance(s - 1, t - 1) - 1
    if isinf(ans):
        print(-1)
    else:
        print(ans)
