#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define M1 1000000007
#define M2 998244353
#define ll long long
#define pll pair<ll,ll>
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPI(i,a,b) for(ll i=b-1;i>=a;i--)
#define F first
#define S second
#define PB push_back
#define DB pop_back
#define MP make_pair
#define MT make_tuple
#define G(a,b) get<a>(b)
#define V(a) vector<a>

#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define o_setll tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

ll modI(ll a, ll m);
ll gcd(ll a, ll b);
ll powM(ll x, unsigned ll y, unsigned ll m);
void pairsort(int a[], int b[], int n);
void pairsortll(ll a[],ll b[],ll n);
ll logint(ll x,ll y);
void Miden(ll **p1,ll n);
void Mmult(ll **p1,ll **p2,ll **ans,ll x,ll y,ll z,ll m);
void Mpow(ll **p1,ll **ans,ll n,ll y,ll m);
pll Egcd(ll x,ll y);


ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}

pll Egcd(ll x,ll y)
{
    if(x==0) return MP(0,1);
    pll t=Egcd(y%x,x);
    return MP(t.S-t.F*(y/x),t.F);
}

ll powM(ll x,ll y,ll m)
{
    if(y==0) return 1;
    ll p=powM(x,y/2,m)%m;
    p=(p*p)%m;
    return (y%2==0)?p:(x*p)%m;
}

ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}

void pairsort(int a[],int b[],int n)
{
    pair<int,int> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}

void pairsortll(ll a[],ll b[],ll n)
{
    pair<ll,ll> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}

ll logint(ll x,ll y)
{
    ll ans=0;
    ll a=1;
    for(ll i=0;i<=x;i++)
    {
        if(x<a)
        {
            return ans;
        }
        ans++;
        a*=y;
    }
    return -1;
}

void Miden(ll **p1,ll n)
{
    ll (*x)[n]=(ll(*)[n]) p1;
    REP(i,0,n)
    {
        REP(j,0,n)
        {
            x[i][j]=0;
        }
        x[i][i]=1;
    }
    return;
}

void Mmult(ll **p1,ll **p2,ll **ans,ll x,ll y,ll z,ll m)
{
    ll (*a)[y]=(ll (*)[y])p1;
    ll (*b)[z]=(ll (*)[z])p2;
    ll (*c)[z]=(ll (*)[z])ans;
    REP(i,0,x)
    {
        REP(j,0,z)
        {
            c[i][j]=0;
            REP(k,0,y)
            {
                c[i][j]+=a[i][k]*b[k][j];
                c[i][j]%=m;
            }
        }
    }
    return;
}

void Mpow(ll **p1,ll **ans,ll n,ll y,ll m)
{
    if(y==0)
    {
        Miden(ans,n);
        return;
    }
    ll t[n][n];
    Mpow(p1,(ll **)t,n,y/2,m);
    ll z[n][n];
    Mmult((ll **)t,(ll **)t,(ll **)z,n,n,n,m);
    if(y%2)
    {
        Mmult((ll **)z,p1,ans,n,n,n,m);
    }
    else
    {
        Miden((ll **)t,n);
        Mmult((ll **)z,(ll **)t,ans,n,n,n,m);
    }
    return;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    /*
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    */

    ll ntc=1;
    //cin>>ntc;
    REP(tc,1,ntc+1)
    {
        //cout<<"Case #"<<tc<<": ";

        ll n,m,l;
        cin>>n>>m>>l;
        ll ad[n][n];
        REP(i,0,n) REP(j,0,n) ad[i][j]=(((ll)1)<<50);
        REP(i,0,m)
        {
            ll t1,t2,t3;
            cin>>t1>>t2>>t3;
            t1--;t2--;
            ad[t1][t2]=t3;
            ad[t2][t1]=t3;
        }
        ll dp1[n][n];
        ll dp2[n][n];
        ll f[n][n];
        REP(i,0,n)
        {
            priority_queue<pll> pr;
            REP(j,0,n) 
            {
                dp1[i][j]=(((ll)1)<<50);
                f[i][j]=0;
            }
            dp1[i][i]=0;
            dp2[i][i]=l;
            pr.push(MP(l,i));
            while(!pr.empty())
            {
                ll j=pr.top().S;
                pr.pop();
                if(f[i][j]==1) continue;
                f[i][j]=1;
                REP(k,0,n)
                {
                    if(ad[j][k]>l) continue;
                    if(ad[j][k]>dp2[i][j])
                    {
                        if((dp1[i][k]>dp1[i][j]+1)||((dp1[i][k]==dp1[i][j]+1)&&(dp2[i][k]<l-ad[j][k])))
                        {
                            dp1[i][k]=dp1[i][j]+1;
                            dp2[i][k]=l-ad[j][k];
                            pr.push(MP(dp2[i][k]-(l*dp1[i][k]),k));
                        }
                    }
                    else
                    {
                        if((dp1[i][k]>dp1[i][j])||((dp1[i][k]==dp1[i][j])&&(dp2[i][k]<dp2[i][j]-ad[j][k])))
                        {
                            dp1[i][k]=dp1[i][j];
                            dp2[i][k]=dp2[i][j]-ad[j][k];
                            pr.push(MP(dp2[i][k]-(l*dp1[i][k]),k));
                        }
                    }
                }
            }
        }
        ll q;
        cin>>q;
        REP(i,0,q)
        {
            ll t1,t2;
            cin>>t1>>t2;
            t1--;t2--;
            if(f[t1][t2]==0) cout<<-1<<'\n';
            else cout<<dp1[t1][t2]<<'\n';
        }

        cout<<'\n';
    }

    return 0;
}


Measured memory_bytes: 3328