#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll bit[800010];
ll u;
void bitinit(ll n){
    ll y=1;
    rep(i,0,69){
        
        if(y>=n){
            u=y;
            break;
        }
        y*=2;
    }
    fill(bit,bit+u+10,0);
}
void add(ll n,ll x){
    ll i=n;
    bit[i]+=x;
    bit[i]%=mod;
    while(i<u){
        i+=i&(-i);
        bit[i]+=x;
        bit[i]%=mod;
    }
}
ll sum(ll n){
    ll i=n;
    ll ret=0;
    while(i>0){
        ret+=bit[i];
        i-=i&(-i);
        ret%=mod;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    ll n,m,l;cin>>n>>m>>l;
    vector<pll> v[n+1];
    rep(i,0,m){
        ll a,b,c;cin>>a>>b>>c;
        if(c>l)continue;
        v[a].push_back({b,c});
        v[b].push_back({a,c});
    }
    ll d[n+1][n+1];
    rep(i,0,n+1)rep(j,0,n+1)d[i][j]=-1;
    rep(i,1,n+1){
        priority_queue<ppll,vector<ppll>,greater<ppll>> q;
        q.push({{0,0},i});
        bool used[n+1];
        fill(used,used+n+1,false);
        ll dd[n+1][301];
        rep(j,0,n+1){
            rep(k,0,301)dd[j][k]=inf;
        }
        dd[i][0]=0;
        d[i][i]=0;
        while(q.size()>0){
            ppll p=q.top();
            q.pop();
            ll now=p.second;
            ll dis1=p.first.first;
            ll dis2=p.first.second;
            if(used[now])continue;
            used[now]=true;
            d[i][now]=dis1;
            //if(i==5)cout<<now<<" "<<dis1<<" "<<dis2<<endl;
            rep(j,0,v[now].size()){
                ll ne=v[now][j].first;
                ll co=v[now][j].second;
                if(used[ne])continue;
                
                if(dis2+co>l){
                    if(dd[ne][dis1+1]>co){
                        q.push({{dis1+1,co},ne});
                        dd[ne][dis1+1]=co;
                    }
                    
                }
                else{
                    if(dd[ne][dis1]>dis2+co){
                        dd[ne][dis1]=dis2+co;
                        q.push({{dis1,dis2+co},ne});
                    }
                }
            }
        }
        
    }
   // cout<<d[5][4]<<" "<<d[5][3]<<" "<<d[5][2]<<endl;
    ll q;cin>>q;
    rep(i,0,q){
        ll s,t;cin>>s>>t;
        cout<<d[s][t]<<endl;
    }
}


Measured memory_bytes: 4352