#include <bits/stdc++.h>

using namespace std;

#define forn(a, e) for (int a = 0; a < (int)(e); a++)
#define forr(a, s, e) for (int a = s; a < (int)(e); a++)
#define fore(e, a) for (auto& e : a)

#ifdef LOCAL
#define logv(a) {cerr << #a << " = "; fore(e, a) {cerr << e << " ";} cerr << "\n";}
#define logvp(a) {cerr << #a << " = "; fore(e, a) {cerr << "(" << e.first << ", " << e.second << ") ";} cerr << "\n";}
#define logvv(a) {cerr << #a << " = \n"; fore(r, a) { fore(e, r) {cerr << e << " ";} cerr << "\n";} }
#define logvf(a, field) {cerr << #a"."#field << " = \n"; fore(e, a) { cerr << e.field << " ";} cerr << "\n"; }
#define logs(a) cerr << #a << " = " << (a) << "\n";
#define logss(a, b) cerr << #a << " = " << (a) << ", " << #b << " = " << (b) << "\n";
#define logp(a) cerr << #a << " = " << "(" << a.first << ", " << a.second << ")" << "\n";
#define cond(pred, stmt) if (pred) { stmt }
#else
#define logv(a)
#define logvp(a)
#define logvv(a)
#define logvf(a, field)
#define logs(a)
#define logss(a, b)
#define logp(a)
#define cond(pred, stmt)
#endif

using i64 = long long;
using iip = pair<i64, i64>;
using ivec = vector<int>;
using llvec = vector<i64>;
using svec = vector<string>;

template<typename T, typename Dim>
auto make_vec(T value, Dim dim) { return vector<T>(dim, value); }
template<typename T, typename Dim1, typename... Dim>
auto make_vec(T value, Dim1 dim1, Dim... dims) { return make_vec(make_vec(value, dims...), dim1); }

template<typename T>
bool uax(T& v, const T& newv) { if (v < newv) { v = newv; return true; } else return false; }
template<typename T>
bool uin(T& v, const T& newv) { if (v > newv) { v = newv; return true; } else return false; }

template<typename T>
istream& operator>>(istream& is, vector<T>& c) { for (auto& e : c) is >> e; return is; }

// template<typename ...T>
// istream& read(T&... args) { return (cin >> ... >> args); }

static mt19937 rande(123123);
template<typename T>
T rand_int(T from, T to) { uniform_int_distribution<T> distr(from, to); return distr(rande); }

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);


    i64 n, m, l;
    while (cin >> n >> m >> l) {
        auto w = make_vec(-1, n, n);
        forn(i, m) {
            int a, b, c;            
            cin >> a >> b >> c;
            if (c > l) {
                continue;
            }
            a--; b--;
            w[a][b] = c;
            w[b][a] = c;
        }

        vector<vector<pair<i64, i64>>> dp(n, vector<pair<i64, i64>>(n, {-1, -1}));
        forn(s, n) {
            dp[s][s] = {0, l};
            ivec used(n);            
            forn(x, n) {
                int v = -1;
                pair<i64, i64> cl = {-1, -1};
                forn(i, n) {
                    if (dp[s][i].first != -1 && !used[i]) {
                        if (cl.first == -1 || cl.first > dp[s][i].first) {
                            cl = dp[s][i];
                            v = i;
                        } else if (cl.first == dp[s][i].first) {
                            if (uax(cl.second, dp[s][i].second)) {
                                v = i;
                            }
                        }
                    }
                }

                if (v == -1) {
                    break;
                }
                used[v] = true;

                forn(i, n) {
                    if (w[v][i] != -1) {
                        auto ncl = cl;
                        if (cl.second >= w[v][i]) {
                            ncl.second -= w[v][i];
                        } else {
                            ncl.first++;
                            ncl.second = l - w[v][i];
                        }
                        if (dp[s][i].first == -1 || ncl.first < dp[s][i].first) {
                            dp[s][i] = ncl;
                        } else if (dp[s][i].first == ncl.first) {
                            uax(dp[s][i].second, ncl.second);
                        }
                    }
                }
            }
        }

        int q;
        cin >> q;
        while (q--) {
            int s, t;
            cin >> s >> t;
            s--; t--;
            cout << dp[s][t].first << endl;
        }
    }
}


Measured memory_bytes: 2432