#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

typedef struct Edge {
    ll to, cost;
    Edge(){}
    Edge(ll to, ll cost):to(to),cost(cost){}
} Edge;

void solve() {
    ll n,m,l; cin>>n>>m>>l;
    vector<vector<Edge>> g(n);
    rep(i,m) {
        ll a,b,c; cin>>a>>b>>c;
        if (c>l) continue;
        --a,--b;
        g[a].emplace_back(b,c);
        g[b].emplace_back(a,c);
    }

    vector<vector<P>> ans(n);

    auto dijkstra = [&](int s) {
        vector<bool> vi(n,false);
        // P(cost, fuel)
        vector<P> dp(n,P(INF,l));
        dp[s] = P(0,0);
        rep(i,n) {
            P mini = P(INF,l);
            int node = 0;
            rep(j,n) {
                if (vi[j]) continue;
                if (mini > dp[j]) {
                    mini = dp[j];
                    node = j;
                }
            }
            vi[node] = true;
            for (auto &&nxt: g[node]) {
                P cost;
                if (nxt.cost+dp[node].second > l) {
                    cost.first = dp[node].first+1;
                    cost.second = nxt.cost;
                }
                else {
                    cost.first = dp[node].first;
                    cost.second = dp[node].second+nxt.cost;
                }
                if (dp[nxt.to] > cost) {
                    dp[nxt.to] = cost;
                }
            }
        }
        ans[s] = dp;
        return;
    };

    rep(i,n) {
        dijkstra(i);
    }

    int q; cin>>q;
    rep(i,q) {
        int s,t; cin>>s>>t;
        --s,--t;
        if (ans[s][t].first == INF) cout << -1 << '\n';
        else cout << ans[s][t].first << '\n';
    }

    return;
}

void solve2() {
    ll n,m,l; cin>>n>>m>>l;
    vector<vector<ll>> g(n, vector<ll>(n, LINF));
    rep(i,n) g[i][i] = 0;
    rep(i,m) {
        ll a,b,c; cin>>a>>b>>c;
        if (c>l) continue;
        --a,--b;
        g[a][b] = g[b][a] = c;
    }

    rep(k,n) rep(i,n) rep(j,n) chmin(g[i][j], g[i][k]+g[k][j]);
    vector<vector<ll>> dp(n, vector<ll>(n, LINF));
    rep(i,n) dp[i][i] = 0;
    rep(i,n) rep(j,n) if (g[i][j] <= l) dp[i][j] = 1;
    
    rep(k,n) rep(i,n) rep(j,n) chmin(dp[i][j],dp[i][k]+dp[k][j]);

    int q; cin>>q;
    rep(i,q) {
        int s,t; cin>>s>>t;
        --s,--t;
        if (dp[s][t] == LINF) cout << -1 << '\n';
        else cout << dp[s][t]-1 << '\n';
    }
}

int main(int argc, char const *argv[]) {
    // solve();
    solve2();
    return 0;
}


Measured memory_bytes: 1920