#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


const int MAX = 310;
const long long INF = 1LL<<50;

int N, M;
long long L;
long long G[MAX][MAX];

using pll = pair<long long, long long>;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    while (cin >> N >> M >> L) {
        for (int i = 0; i < MAX; ++i) {
            for (int j = 0; j < MAX; ++j) {
                G[i][j] = INF;
            }
            G[i][i] = 0;
        }

        for (int i = 0; i < M; ++i) {
            int a, b;
            long long c;
            cin >> a >> b >> c;
            --a, --b;
            G[a][b] = G[b][a] = c;
        }

        vector<vector<pll> > dist(N, vector<pll>(N, {INF, INF}));
        for (int s = 0; s < N; ++s) {
            dist[s][s] = {0, 0};
            priority_queue<pair<pll, int>,
                           vector<pair<pll, int> >,
                           greater<pair<pll, int> > > que;
            que.push(make_pair(pll(0, 0), s));
            while (!que.empty()) {
                auto p = que.top();
                que.pop();

                long long v = p.second;
                long long kaisuu = p.first.first;
                long long used = p.first.second;

                if (p.first > dist[s][v]) continue;

                //cout << s << ", " << v << ": " << p.first << endl;
                
                for (int nv = 0; nv < N; ++nv) {
                    if (nv == v) continue;
                    if (G[v][nv] > L) continue;
                    long long nused = used + G[v][nv];
                    pll np = {0, 0};
                    if (nused > L) {
                        if (G[v][nv] > L) continue;
                        np = {kaisuu + 1, G[v][nv]};
                    }
                    else {
                        np = {kaisuu, nused};
                    }

                    if (chmin(dist[s][nv], np)) {
                        que.push(make_pair(np, nv));
                    }
                }
            }
        }

        int Q; cin >> Q;
        while (Q--) {
            int a, b; cin >> a >> b; --a, --b;

            long long res = dist[a][b].first;
            if (res >= INF) cout << -1 << endl;
            else cout << res << endl;
        }
    }
}


















Measured memory_bytes: 2688