#include<bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define lli long long int
#define F first
#define S second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define MAX1 998244353
#define MAX2 1000000007
#define MAX3 1000000000000000000
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define input(data,n,command) for(lli i=0;i<n;i++){lli tmp;cin>>tmp;data.pb(tmp);command}
#define sort(a) sort(a.begin(),a.end());
#define display(a) for(lli i = 0 ;i<a.size();i++){cout<<a[i]<<" ";} cout<<endl;
#define rep(i,n,p) for(lli i = 0;i<n;i= i +p)
#define endl "\n"

//Written By GHATAK...
/*--------------------------------------------------------------------*/
//vector<pair<lli,lli>>adj[300010];
lli fuel[350][350];
lli refill[350][350];

int main()
{
    ios
    lli T=1;
    //cin>>T;
    while(T--)
    {
        //start from here
        lli n,m,l;
        cin>>n>>m>>l;
        for(lli i = 0;i<350;i++)
        {
            for(lli j = 0;j<350;j++)
            {
                fuel[i][j] = MAX3;
                refill[i][j] = MAX3;
            }
        }


        for(lli i = 0;i<m;i++)
        {
            lli a,b,c;
            cin>>a>>b>>c;
            if(c <= l)
            {
                fuel[a][b] = c;
                fuel[b][a] = c;
            }
        }

        for(lli i = 1;i<=n;i++)
        {
            for(lli j = 1;j<=n;j++)
            {
                if(i != j)
                {
                    for(lli k = 1;k<=n;k++)
                    {
                        if((i == k)||(j == k))
                        {
                            continue;
                        }
                        if(fuel[i][j] == MAX3 || fuel[i][k] == MAX3)
                        {
                            continue;
                        }
                        if(fuel[i][j] + fuel[i][k] <= l)
                        {
                            fuel[j][k] = min(fuel[j][k],fuel[i][j] + fuel[i][k]);
                        }
                    }
                }
            }
        }

        for(lli i = 1;i<=n;i++)
        {
            for(lli j = 1;j<=n;j++)
            {
                if(i != j)
                {
                    if(fuel[i][j] != MAX3)
                    {
                        refill[i][j] = 1;
                    }
                }
            }
        }

        for(lli i = 1;i<=n;i++)
        {
            for(lli j =1;j<=n;j++)
            {
                if(i != j)
                {
                    for(lli k = 1;k<=n;k++)
                    {
                        if((i == k)||(j == k))
                        {
                            continue;
                        }
                        if((refill[i][j] == MAX3)||(refill[i][k] == MAX3))
                        {
                            continue;
                        }
                        refill[j][k] = min(refill[j][k],refill[i][j] + refill[i][k]);
                    }
                }
            }
        }
        lli q;
        cin>>q;
        while(q--)
        {
            lli a,b;
            cin>>a>>b;
            if(refill[a][b] == MAX3)
            {
                cout<<"-1"<<endl;
            }
            else
            {
                cout<<refill[a][b]-1<<endl;
            }
        }
    }
    return 0;
}
/*-----------------------------------------------------------------------*/
/*
--->  reverse(vec.begin(),vec().end());
*/

Measured memory_bytes: 2560