#include<bits/stdc++.h>
        #define ll  long long
        #define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
        #define rep(i,a,b)  for(ll i=a;i<b;i++)
        #define pb push_back
        #define Max(x,y,z) max(x,max(y,z))
        #define f first
        #define s second
        #define sz(x)       (ll)x.size()
        #define pi 3.1415926536
        #define mod 1000000007
        #define MOD 998244353
        #define maxi 100000000000000000
        using namespace std;
       const int N=1e5+5;
       ll n;
       /*vector<ll> adj[205];
       ll lvl[205];
       ll col[205];
       bool vis[205];
       bool flag=1;*/
      /* bool dfs(ll x)
       {   vis[x]=1;
           for(auto y:adj[x])
           {
               if(!vis[y])
               {
                   if(col[y]==-1)
                   {
                       col[y]=1-col[x];
                        return flag=(flag && dfs(y));
                   }
               }
               else if(col[y]==col[x])
                    return 0;

           }
           return flag;
       }*/
       /*ll dp[N][25],dp2[N][25];
       ll logcal[N];*/
/*       void update(ll x,ll value,ll pos)
{
    while(pos<=n)
    {
        bit[x][pos]+=value;
        pos+=(pos)&(-pos);
    }
}
ll query(ll x,ll pos)
{  ll ans=0;
    while(pos>0)
    {
        ans+=bit[x][pos];
        pos-=(pos)&(-pos);
    }
    return ans;
}*/
    /*
    bool vis[N];
    ll cnt=0;
    void dfs(ll x)
    {
        vis[x]=1;
        cnt++;
        for(auto y:adj[x])
            if(!vis[y]) dfs(y);
    }*/
      /* ll dfs(ll x,bool vis[],bool rec[])
    {   //cout<<x<<" ";
        vis[x]=1;
        rec[x]=1;
        for(auto y:adj[x])
            if(!vis[y] && dfs(y,vis,rec)) return true;
            else if(rec[y]) return true;
        rec[x]=false;
        return false;
    }*/
        /*bool isprime(ll x)
        {
            for(ll i=2;(i*i)<=x;i++)
            {
                if(x%i==0) return 0;
            }
            return 1;
        }*/
        /*vector<ll> _lps(string &t)
        {   ll n=t.size();
            vector<ll> lps(n+1,0);
            ll i=1,len=0;
            while(i<n)
            {
                if(t[i]==t[len])
                {
                    len++;
                    lps[i]=len;
                    i++;
                }
                else
                {
                    if(len!=0)
                        len=lps[len-1];
                    else
                        lps[i++]=0;
                }
            }
            return lps;
        }
        ll KMP(string &s,string &t)
        {
            ll n=s.size();
            ll m=t.size();
            vector<ll> lps=_lps(t);
            ll i=max(0LL,n-m),j=0;
            while(i<n)
            {
                if(s[i]==t[j])
                {
                    i++;
                    j++;
                }
                else
                    if(j!=0) j=lps[j-1];
                    else i++;
            }
            return j;

        }*/
        void solve()
        {
                    ll m,y,z,h,b,c,d,e,k1,k2,p,x,k,a,q;
                    cin>>n>>m>>k;
                    ll dis[n+1][n+1];
                    rep(i,0,n+1)
                    {
                        rep(j,0,n+1)
                            if(i==j) dis[i][j]=0;
                            else dis[i][j]=maxi;
                    }
                    rep(i,0,m)
                    {
                        cin>>x>>y>>z;
                        dis[x][y]=z;
                        dis[y][x]=z;
                    }
                    for(ll k=1;k<=n;k++)
                    {
                        for(ll i=1;i<=n;i++)
                        {

                            for(ll j=1;j<=n;j++)
                                dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
                        }
                    }
                    ll dis2[n+1][n+1];
                        for(ll i=1;i<=n;i++)
                        {

                            for(ll j=1;j<=n;j++)
                                {dis2[i][j]=(dis[i][j]<=k) ? 1:maxi;
                                if(i==j) dis2[i][j]=0;}
                        }
                    for(ll k=1;k<=n;k++)
{
                        for(ll i=1;i<=n;i++)
                        {

                            for(ll j=1;j<=n;j++)
                                dis2[i][j]=min(dis2[i][j],dis2[i][k]+dis2[k][j]);
                        }
                    }
                    cin>>q;
                    while(q--)
                    {
                        cin>>x>>y;
                        if(dis2[x][y]>=maxi) cout<<"-1\n";
                        else
                        {
                            cout<<dis2[x][y]-1<<"\n";
                        }
                    }







}

                int main()
                {
                    speed_up
                    ll t=1;
                    //call();
                    //cin>>t;
                    while(t--)
                        solve();
                }


Measured memory_bytes: 1920