#include <bits/stdc++.h>
using i64 = int_fast64_t;
#define repeat(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define rep(i, n) repeat(i, 0, n)

namespace edamat {
template <class Info>
struct edge {
    int from, to;
    Info info;
    edge(int to, Info info) : to(to), info(info) {}
    edge(int from, int to, Info info) : from(from), to(to), info(info) {}
};

struct normal_edge {
    normal_edge() {}
};

//! graphは基底クラス！使うときはundirected_graphかdirected_graphを使う。
template <class Info>
class graph {
   protected:
    using edge_type = edge<Info>;
    ::std::size_t N;
    ::std::vector<::std::vector<edge_type>> edges;

   public:
    graph(::std::size_t N_) : N(N_), edges(N_) {}
    virtual void add_edge(int x, int y, Info info = static_cast<Info>(1)) = 0;
    const ::std::vector<edge_type> &delta(int v) const {
        assert(v < N);
        return edges[v];
    }
    const ::std::vector<edge_type> &operator[](int v) const {
        return this->delta(v);
    }
    ::std::size_t size() const noexcept { return N; }
    ::std::vector<Info> bfs(int);
    ::std::vector<Info> dijkstra(int);
    ::std::vector<Info> bellman_ford(int);
    ::std::vector<::std::vector<Info>> warshall_floyd(void);
};

template <class Info>
class undirected_graph : public graph<Info> {
   public:
    undirected_graph(::std::size_t N) : graph<Info>(N) {}
    void add_edge(int x, int y, Info info = static_cast<Info>(1)) {
        this->edges[x].push_back(edge<Info>(x, y, info));
        this->edges[y].push_back(edge<Info>(y, x, info));
    }
};

template <class Info>
class directed_graph : public graph<Info> {
   public:
    directed_graph(::std::size_t N) : graph<Info>(N) {}
    void add_edge(int x, int y, Info info = static_cast<Info>(1)) {
        this->edges[x].push_back(edge<Info>(x, y, info));
    }
    ::std::vector<int> topological_sort(void);
};

template <typename Info>
::std::vector<Info> graph<Info>::bfs(int s) {
    const auto INF = ::std::numeric_limits<Info>::max();
    ::std::vector<Info> dist(edges.size(), INF);
    ::std::vector<int> b(edges.size(), -1);  // 経路復元

    ::std::queue<Info> q;
    q.push(s);
    dist[s] = 0;
    while(!q.empty()) {
        Info v = q.front();
        q.pop();
        for(auto e : edges[v]) {
            if(dist[e.to] != INF) continue;
            dist[e.to] = dist[e.from] + e.info;
            b[e.to] = e.from;  // 経路復元
            q.push(e.to);
        }
    };
    return dist;
}

template <typename Info>
::std::vector<Info> graph<Info>::dijkstra(int s) {
    const auto INF = ::std::numeric_limits<Info>::max();
    ::std::vector<Info> dist(edges.size(), INF);
    ::std::vector<int> b(edges.size(), -1);  // 経路復元
    using Pi = ::std::pair<Info, int>;

    ::std::priority_queue<Pi, std::vector<Pi>, std::greater<Pi>> que;
    dist[s] = 0;
    que.emplace(dist[s], s);
    while(!que.empty()) {
        Info cost;
        int idx;
        ::std::tie(cost, idx) = que.top();
        que.pop();
        if(dist[idx] < cost) continue;
        for(auto &e : edges[idx]) {
            auto next_cost = cost + e.info;
            if(dist[e.to] <= next_cost) continue;
            dist[e.to] = next_cost;
            b[e.to] = idx;  // 経路復元
            que.emplace(dist[e.to], e.to);
        }
    }
    return dist;
};

template <typename Info>
::std::vector<Info> graph<Info>::bellman_ford(int s) {
    const auto INF = ::std::numeric_limits<Info>::max();
    ::std::vector<Info> dist(edges.size(), INF);
    ::std::vector<int> b(edges.size(), -1);  // 経路復元

    dist[s] = 0;
    for(int i = 0; i < edges.size() - 1; i++) {
        for(int idx = 0; idx < edges.size(); idx++) {
            for(auto &e : edges[idx]) {
                if(dist[e.from] == INF) continue;
                auto next_cost = dist[e.from] + e.info;
                if(dist[e.to] <= next_cost) continue;
                dist[e.to] = next_cost;
                b[e.to] = e.from;  // 経路復元
            }
        }
    }
    for(int idx = 0; idx < edges.size(); idx++) {
        for(auto &e : edges[idx]) {
            if(dist[e.from] == INF) continue;
            if(dist[e.from] + e.info < dist[e.to]) return ::std::vector<Info>();
        }
    }
    return dist;
}

template <typename Info>
::std::vector<::std::vector<Info>> graph<Info>::warshall_floyd() {  // nは頂点数
    const i64 INF = (i64)1e18;
    ::std::vector<::std::vector<Info>> dist(edges.size(), ::std::vector<Info>(edges.size(), INF));
    ::std::vector<::std::vector<int>> next(edges.size(), ::std::vector<int>(edges.size()));  // 経路復元
    rep(i, edges.size()) {
        dist[i][i] = 0;
        for(auto &e : edges[i]) {
            dist[e.from][e.to] = e.info;
        }
    }
    rep(i, edges.size()) rep(j, edges.size()) next[i][j] = j;
    rep(k, edges.size()) {
        rep(i, edges.size()) {
            rep(j, edges.size()) {
                if(dist[i][k] + dist[k][j] < dist[i][j]) {
                    dist[i][j] = dist[i][k] + dist[k][j];
                    next[i][j] = next[i][k];
                }
            }
        }
    }
    return dist;
}

template <typename Info>
::std::vector<int> directed_graph<Info>::topological_sort() {
    ::std::vector<int> h(this->size(), 0);
    for(int idx = 0; idx < this->size(); idx++) {
        for(auto &e : this->edges[idx]) {
            h[e.to]++;
        }
    }

    //入次数が0の頂点の集合
    ::std::stack<int> st;

    //入次数が0の頂点であればstに追加
    rep(i, this->size()) if(h[i] == 0) st.push(i);

    //ソートされた後のグラフ
    ::std::vector<int> ret;
    // stがなくなるまでループ
    while(st.size()) {
        // stの集合のから一つ取り出す
        int i = st.top();
        st.pop();
        ret.emplace_back(i);
        for(auto &e : this->edges[i]) {
            //隣接する頂点の入次数をマイナス1
            h[e.to]--;
            //これによって入次数が0になればstに追加
            if(h[e.to] == 0) st.push(e.to);
        }
    }
    return ret;
}

}  // namespace edamat

void solve() {
    int n, m, l;
    scanf("%d %d %d", &n, &m, &l);
    edamat::undirected_graph<i64> g(n);
    rep(i, m) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        a--, b--;
        g.add_edge(a, b, c);
    }
    auto dist = g.warshall_floyd();
    edamat::undirected_graph<i64> gg(n);
    rep(i, n) {
        repeat(j, i + 1, n) {
            if(dist[i][j] <= l) {
                gg.add_edge(i, j, 1);
            }
        }
    }
    auto d = gg.warshall_floyd();
    int Q;
    scanf("%d", &Q);
    while(Q--) {
        int s, t;
        scanf("%d %d", &s, &t);
        s--, t--;
        if(d[s][t] > 300)
            printf("-1\n");
        else
            printf("%d\n", d[s][t] - 1);
    }
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 6948