#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

ll g[303][303],g2[303][303];
int N,M,L;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    rep(i,303)rep(j,303)g[i][j] = 1e18,g2[i][j] = 1e18;
    rep(i,303)g[i][i] = 0,g2[i][i] = 0;
    cin >> N >> M >> L;
    rep(i,M){
        ll a,b,c;
        cin >> a >> b >> c;
        a--;b--;
        if(c>L)continue;
        g[a][b] = c;
        g[b][a] = c;
    }
    rep(k,N)rep(i,N)rep(j,N)g[i][j] = min(g[i][j],g[i][k]+g[k][j]);
    rep(i,N)rep(j,N){
        if(g[i][j]<=L)g2[i][j] = min(g2[i][j],1LL);
    }
    rep(k,N)rep(i,N)rep(j,N)g2[i][j] = min(g2[i][j],g2[i][k]+g2[k][j]);
    int Q;cin >> Q;
    vector<ll> ans;
    rep(i,Q){
        int s,t;
        cin >> s >> t;
        s--;t--;
        if(g2[s][t]>=1e18)ans.push_back(0);
        else ans.push_back(g2[s][t]);
    }
    for(auto x:ans)cout << x-1 << endl;
}