#include <bits/stdc++.h>
using namespace std;
#define double long double
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define vout(v) for(int i=0;i<(int)v.size()-1;i++){cout<<v[i]<<" ";}cout<<v[v.size()-1]<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define debg(a) cerr<<#a<<" "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> V;
// const long long MOD=1000000007;
const long long INF = 1e18;
V d(1000);
struct edge {
    ll from;
    ll to;
    ll cost;
};
vector<edge> es(10000);

void bellman_ford(ll N, ll M, ll s){
    for (ll i = 0; i < N; i++) { d[i] = INF; }
    d[s] = 0;
    while(true){
        bool update = false;
        for (ll i = 0; i < M; i++) {
            edge e = es[i];
            if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                update = true;
            }
        }
        if (!update) break;
    }
}

void solve_old(long long N, long long M, long long L, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C, long long Q, std::vector<long long> s, std::vector<long long> t){
    for (ll i = 0; i < M; i++) {
        es[i].from = A[i]-1;
        es[i].to = B[i]-1;
        es[i].cost = C[i];
        es[i+M].from = B[i]-1;
        es[i+M].to = A[i]-1;
        es[i+M].cost = C[i];
    }
    for (ll i = 0; i < Q; i++)
    {
        bellman_ford(N, M*2, s[i]-1);
        cout << d[t[i]-1] << "\n";
    }
}

// ll dp[500][500] = {INF};
// vector<ll,vector<ll>> dp
vector<vector<ll>> dp(500, vector<ll>(500, INF));
vector<vector<ll>> dp_ano(500, vector<ll>(500, INF));
void warshall_floyd(ll N){
    for (ll k = 0; k < N; k++)
        for (ll i = 0; i < N; i++)
            for (ll j = 0; j < N; j++) dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
}

void solve(long long N, long long M, long long L, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C, long long Q, std::vector<long long> s, std::vector<long long> t){
    for (ll i = 0; i < N; i++) {
        dp[i][i]=0;
        dp_ano[i][i]=0;
    }
    for (ll i = 0; i < M; i++) {
        dp[A[i]-1][B[i]-1]=C[i];
        dp[B[i]-1][A[i]-1]=C[i];
    }
    warshall_floyd(N);
    for (ll i = 0; i < N; i++) {
        for (ll j = 0; j < N; j++) {
            if(i==j) continue;
            if(dp[i][j]<=L) dp_ano[i][j]=1;
        }
    }
    // warshall_floyd(N);
    for (ll k = 0; k < N; k++)
        for (ll i = 0; i < N; i++)
            for (ll j = 0; j < N; j++) dp_ano[i][j] = min(dp_ano[i][j], dp_ano[i][k] + dp_ano[k][j]);
    for (ll i = 0; i < Q; i++) {
        ll val=max(0LL,dp_ano[s[i]-1][t[i]-1]-1);
        if(dp_ano[s[i]-1][t[i]-1]==INF) val=-1;
        cout << val << "\n";
    }

    // for (ll i = 0; i < N; i++) {
    //     for (ll j = 0; j < N; j++) {
    //         if(dp[i][j]==INF) {cout << ". "; continue;}
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }

}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    long long L;
    scanf("%lld",&L);
    std::vector<long long> A(M);
    std::vector<long long> B(M);
    std::vector<long long> C(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
        scanf("%lld",&C[i]);
    }
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> s(Q);
    std::vector<long long> t(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&s[i]);
        scanf("%lld",&t[i]);
    }
    solve(N, M, L, std::move(A), std::move(B), std::move(C), Q, std::move(s), std::move(t));
    return 0;
}


Measured memory_bytes: 7040