#include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long int
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;

    vector<pair<ll,ll> > v[311];

    ll ans[311][311],ans2[311][311];

    class triple
    {
    public:
        ll a,b,c;
    };

    class comp
    {
    public:
        bool operator()(triple i,triple j)
        {
            if(i.b!=j.b)
                return i.b>j.b;
            return i.c<j.c;
        }
    };

    void djik(ll s,ll l)
    {
        priority_queue<triple,vector<triple>,comp> pq;
        pq.push({s,0,l});
        triple x;
        ans[s][s]=0,ans2[s][s]=l;
        ll i;
        while(!pq.empty())
        {
            x=pq.top();
            pq.pop();
            i=x.a;
            //cout<<s<<" "<<i<<endl;
            //cout<<s<<" "<<i<<" "<<x.b<<" "<<x.c<<endl;
            if(x.b!=ans[s][i] || x.c!=ans2[s][i])
                continue;
            //cout<<s<<" "<<i<<" "<<x.b<<" "<<x.c<<endl;
            for(ll j=0;j<v[i].size();++j)
            {
                //cout<<v[i][j].f<<" "<<v[i][j].s<<endl;
                if(v[i][j].s<=x.c)
                {
                    //cout<<"HAI"<<endl;
                    if(ans[s][v[i][j].f]>x.b)
                    {
                        ans[s][v[i][j].f]=x.b;
                        ans2[s][v[i][j].f]=x.c-v[i][j].s;
                        pq.push({v[i][j].f,ans[s][v[i][j].f],ans2[s][v[i][j].f]});
                    }
                    else if(ans[s][v[i][j].f]==x.b && ans2[s][v[i][j].f]<x.c-v[i][j].s)
                    {
                        ans2[s][v[i][j].f]=x.c-v[i][j].s;
                        pq.push({v[i][j].f,ans[s][v[i][j].f],ans2[s][v[i][j].f]});
                    }
                }
                else
                {
                    if(ans[s][v[i][j].f]>x.b+1 && l>=v[i][j].s)
                    {
                        ans[s][v[i][j].f]=x.b+1;
                        ans2[s][v[i][j].f]=l-v[i][j].s;
                        pq.push({v[i][j].f,ans[s][v[i][j].f],ans2[s][v[i][j].f]});
                    }
                    else if(ans[s][v[i][j].f]==x.b+1 && ans2[s][v[i][j].f]<l-v[i][j].s && l>=v[i][j].s)
                    {
                        ans2[s][v[i][j].f]=l-v[i][j].s;
                        pq.push({v[i][j].f,ans[s][v[i][j].f],ans2[s][v[i][j].f]});
                    }
                }
            }
        }
    }

    signed main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            ll n,m,l,a,b,i,j,c,q;
            cin>>n>>m>>l;
            for(i=1;i<=n;++i)
                for(j=1;j<=n;++j)
                    ans[i][j]=1e9;
            for(i=1;i<=m;++i)
            {
                cin>>a>>b>>c;
                v[a].pb({b,c});
                v[b].pb({a,c});
            }
            for(i=1;i<=n;++i)
                djik(i,l);
            for(i=1;i<=n;++i)
                for(j=1;j<=n;++j)
                    if(ans[i][j]==1e9)
                        ans[i][j]=-1;
            cin>>q;
            while(q--)
            {
                cin>>a>>b;
                cout<<ans[a][b]<<endl;
            }
        }
        return 0;
    }


Measured memory_bytes: 4352