#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
const ld EPS = 1e-12L;
const ld PI = 3.1415926535897932385L;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ull x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

const ll MAX_V = 5010;
const ll MAX_E = 100010;

struct edge{
    ll from, to, cost;
    edge(ll f, ll t, ll c): from(f), to(t), cost(c){}
};
typedef pair<pll, ll> P; // firstは最短距離、secondは頂点の番号

ll V;
vector<edge> G[MAX_V];
ll d[MAX_V];  // 補給
ll d2[MAX_V]; // 燃料消費
ll l;

ll ans[MAX_V][MAX_V];

void Dijkstra(ll s){
    // greater<P>を指定することでfirstが小さい順に取り出せるようにする
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d + V, INF);
    fill(d2, d2 + V, INF);
    d[s] = 0;
    d2[s] = 0;
    que.push(P(pll(0, 0), s));
    
    while(!que.empty()){
        P p = que.top(); que.pop();
        ll v = p.second;
        if(d[v] < p.first.first){
            continue;
        }else if(d[v] == p.first.first && d2[v] < p.first.second){
            continue;
        }
        ll sv = G[v].size();
        for(ll i = 0; i < sv; i++){
            edge e = G[v][i];
            ll nd = d[v];
            ll nd2 = d2[v] + e.cost;
            if(nd2 > l){
                nd++;
                nd2 = e.cost;
            }
            if(d[e.to] > nd){
                d[e.to] = nd;
                d2[e.to] = nd2;
                que.push(P(pll(d[e.to], d2[e.to]), e.to));
            }else if(d[e.to] == nd && d2[e.to] > nd2){
                d[e.to] = nd;
                d2[e.to] = nd2;
                que.push(P(pll(d[e.to], d2[e.to]), e.to));
            }
        }
    }
    
    rep(i, V+1){
        ans[s][i] = d[i];
    }
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n, m;
    cin >> n >> m >> l;
    V = n+1;
    vll a(m), b(m), c(m);
    rep(i, m){
        cin >> a[i] >> b[i] >> c[i];
        if(c[i] <= l){
            G[a[i]].emplace_back(a[i], b[i], c[i]);
            G[b[i]].emplace_back(b[i], a[i], c[i]);
        }
    }
    rep(i, n+1)rep(j, n+1) ans[i][j] = INF;
    repr(i, 1, n+1) Dijkstra(i);
    ll q;
    cin >> q;
    vll s(q), t(q);
    rep(i, q){
        cin >> s[i] >> t[i];
        if(ans[s[i]][t[i]] >= INF)
            cout << -1 << endl;
        else
            cout << ans[s[i]][t[i]] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 17280