#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double PI = 3.1415926535897932384626433832795028L;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

template<typename T, typename I, typename J, typename F, typename G, typename ID, typename AB>
std::vector<T> dijkstra(I begin_adj, I end_adj, J begin_cost, int s, F f, G g, ID id, AB ab) {
    int n = end_adj - begin_adj;
    std::vector<T> ret(n, ab());
    using P = std::pair<T, int>;
    auto c = [&](P a, P b) -> bool { return g(a.first, b.first); };
    std::priority_queue<P, std::vector<P>, decltype(c)> pq(c);
    ret[s] = id();
    pq.push({ret[s], s});
    while (!pq.empty()) {
        P p = pq.top();
        pq.pop();
        int v = p.second;
        if (g(p.first, ret[v])) { continue; }
        for (int i = 0; i < (begin_adj + v)->size(); i++) {
            int u = (*(begin_adj + v))[i];
            T dist_u = f(ret[v], (*(begin_cost + v))[i]);
            if (g(ret[u], dist_u)) { ret[u] = dist_u, pq.push({ret[u], u}); }
        }
    }
    return ret;
}

template<typename T, typename I, typename J>
std::vector<T> basic_dijkstra(I begin_adj, I end_adj, J begin_cost, int s) {
    auto id = []() -> T { return 0; };
    auto ab = []() -> T { return std::numeric_limits<T>::max(); };
    auto f = [&](T a, T b) -> T { return a == ab() ? ab() : a + b; };
    return dijkstra<T>(begin_adj, end_adj, begin_cost, s, f, std::greater<T>(), id, ab);
}

int N, M, L;
int A[110000], B[110000], C[110000];
int Q;
int s[110000], t[110000];
vint adj[330], cost[330];
signed main() {
    cin >> N >> M >> L;
    rep(i, M) {
        cin >> A[i] >> B[i] >> C[i];
        if (C[i] > L) { continue; }
        adj[A[i]].push_back(B[i]);
        adj[B[i]].push_back(A[i]);
        cost[A[i]].push_back(C[i]);
        cost[B[i]].push_back(C[i]);
    }
    vector<vpint> ans;
    auto id = []() -> pint { return {0, 0}; };
    auto ab = []() -> pint { return {LLONG_MAX, 0}; };
    auto f = [](pint a, int b) -> pint {
        if (a.second + b <= L) { return {a.first, a.second + b}; }
        else { return {a.first + 1, b}; }
    };
    for (int i = 0; i <= N; i++) {
        ans.push_back(dijkstra<pint>(adj, adj + N + 1, cost, i, f, greater<pint>(), id, ab));
    }
    cin >> Q;
    rep(i, Q) {
        cin >> s[i] >> t[i];
        cout << (ans[s[i]][t[i]] == ab() ? -1 : ans[s[i]][t[i]].first) << endl;
    }
}


Measured memory_bytes: 8240