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

#define int long long
#define uint unsigned long long
#define double long double
#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) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end());
#define bit(n) (1LL << (n))
#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 double pi = 3.1415926535897932384626433832795028;
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 T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &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;

int N, M, L;
int A[110000], B[110000], C[110000];
int Q;
int s[110000], t[110000];

pint operator+(const pint &lhs, const pint &rhs) {
    if (lhs.second + rhs.second <= L) { return {lhs.first, lhs.second + rhs.second}; }
    else { return {lhs.first + 1, rhs.second}; }
}
template<typename T>
struct Dijkstra {
    struct edge {
        int to;
        T cost;
    };
    int n;
    T ZERO, INF;
    std::vector<std::vector<edge>> G;
    Dijkstra(int n, T INF = std::numeric_limits<T>::max(), T ZERO = T()) : n(n), INF(INF), ZERO(ZERO), G(n) {}
    void addEdge(int from, int to, T cost) { G[from].push_back({to, cost}); }
    std::vector<T> getDist(int s) {
        using P=std::pair<T, int>;
        std::priority_queue<P, std::vector<P>, std::greater<P>> pq;
        std::vector<T> d(n, INF);
        d[s] = ZERO;
        pq.push({ZERO, s});
        while (!pq.empty()) {
            P p = pq.top();
            pq.pop();
            int v = p.second;
            if (d[v] < p.first) { continue; }
            for (int i = 0; i < G[v].size(); i++) {
                edge e = G[v][i];
                if (d[v] == INF || d[e.to] <= d[v] + e.cost) { continue; }
                d[e.to] = d[v] + e.cost;
                pq.push({d[e.to], e.to});
            }
        }
        return d;
    }
};

signed main() {
    cin >> N >> M >> L;
    Dijkstra<pint> dij(N, {330, 0}, {0, 0});
    rep(i, M) {
        cin >> A[i] >> B[i] >> C[i];
        A[i]--, B[i]--;
        if (C[i] <= L) {
            dij.addEdge(A[i], B[i], {0, C[i]});
            dij.addEdge(B[i], A[i], {0, C[i]});
        }
    }

    int d[330][330];
    rep(i, N) {
        auto di = dij.getDist(i);
        rep(j, N) { d[i][j] = di[j].first; }
    }

    cin >> Q;
    rep(i, Q) {
        cin >> s[i] >> t[i];
        s[i]--, t[i]--;
        cout << (d[s[i]][t[i]] == 330 ? -1 : d[s[i]][t[i]]) << endl;
    }
}

Measured memory_bytes: 8448