#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
 
using namespace std;

int binpow(int,int);
void dfs( vector< vector<int> >&, int , vector<int>& );
void bfs( vector< vector<int> >&, int , vector<int>& );

void initialize( vector< vector<int> > &d )
{
    rep(i,0,d.size())
    {
        rep(j,0,d[i].size())
        {
            d[i][j] = inf;
        }
        d[i][i] = 0;
    }
}

void floyd_warshall( vector< vector < pair<int,int> > > &v , vector< vector<int> > &d )
{
    rep(i,0,v.size())
    {
        rep(j,0,v[i].size())
        {
            d[i][v[i][j].ft] = min(v[i][j].sd,d[i][v[i][j].ft]);
            d[v[i][j].ft][i] = min(v[i][j].sd,d[v[i][j].ft][i]);
        }
    }

    rep(k,0,v.size())
    {
        rep(i,0,v.size())
        {
            rep(j,0,v.size())
            {
                d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
}

void solve()
{
    int n,m,l;
    cin>>n>>m>>l;

    vector< vector< pair<int,int> > > v(n);

    rep(i,0,m)
    {
        int a,b,x;
        cin>>a>>b>>x;
        a--;b--;
        v[a].pb(mp(b,x));
        v[b].pb(mp(a,x));
    }

    vector< vector<int> > d(n,vector<int>(n));
    vector< vector<int> > f(n,vector<int>(n));
    initialize(f);
    floyd_warshall(v,f);
    initialize(d);
    rep(i,0,f.size())
    {
        rep(j,0,f[i].size())
        {
            if ( i == j )continue;
            if ( f[i][j] <= l )
            {
                d[i][j] = min(d[i][j],1LL);
            }
        }
    }
    rep(k,0,v.size())
    {
        rep(i,0,v.size())
        {
            rep(j,0,v.size())
            {
                d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    // floyd_warshall(v,d);
    
    int q;
    cin>>q;

    while(q--)
    {
        int a,b;
        cin>>a>>b;
        a--;b--;

        if ( d[a][b] < inf )
        {
            cout<<d[a][b]-1<<endl;
        }
        else
        {
            cout<<"-1"<<endl;
        }
        
    }

}

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

void dfs ( vector< vector<int> > &v , int x , vector<int> &vis )
{
    vis[x] = 1;

    rep(i,0,v[x].size())
    {
        if( vis[v[x][i]] == 0 )
        {
            dfs(v,v[x][i],vis);
        }
    }
}

void bfs( vector< vector<int> > &v , int x , vector<int> &vis )
{
    queue<int> q;
    q.push(x);

    while( !q.empty() )
    {
        int p = q.front();
        q.pop();

        rep(i,0,v[p].size())
        {
            if ( vis[v[p][i]] == 0 )
            {
                vis[v[p][i]] = 1;
                q.push(v[p][i]);
            }
        }
    }
}

Measured memory_bytes: 4352