#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
typedef long long ll;
const ll inf = 1e10;
int main(){
    ll n, m, l;
    cin >> n >> m >> l;
    vector<vector<ll> > d(n, vector<ll>(n, inf)), td(n, vector<ll>(n, inf));
    rep(i,m){
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        d[a][b] = d[b][a] = c;
    }
    rep(k,n)rep(i,n)rep(j,n)d[i][j] = min(d[i][j], d[k][j] + d[i][k]);
    
    rep(i,n)rep(j,n)if(d[i][j] <= l)td[i][j] = 1;
    rep(k,n)rep(i,n)rep(j,n)td[i][j] = min(td[i][j], td[k][j] + td[i][k]);
    ll q; cin >> q;
    rep(i,q){
        ll s, t;
        cin >> s >> t;
        s--; t--;
        cout << ((td[s][t] == inf)?-1:td[s][t]-1) << endl;
    }
    return 0;
}