//--------PREPROCESSOR--------PREPROCESSOR--------PREPROCESSOR--------PREPROCESSOR--------PREPROCESSOR--------PREPROCESSOR--------PREPROCESSOR
    
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define REDL(a ,n) vll a(n);for(ll i=0;i<n;i++) cin>>a[i];
#define REPR(i, n) for(int i=0;i<n;i++ )
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(X)  X.begin() ,  X.end()
#define reset(X) memset(X, 0, sizeof(X))
#define endl '\n'
#define  int  long long

//------------------------------_WARNINGG---------------









//-----------------------------TEMPLATES------------------TEMPLATES---------------------------TEMPLATES---------------------------------
//-----------------------------TEMPLATES------------------TEMPLATES---------------------------TEMPLATES---------------------------------
    
//--------------TYPEDEF--------------TYPEDEF--------------TYPEDEF--------------TYPEDEF--------------TYPEDEF--------------TYPEDEF--------------TYPEDEF----------------------------TYPEDEF
//--------------TYPEDEF--------------TYPEDEF--------------TYPEDEF--------------TYPEDEF--------------TYPEDEF--------------TYPEDEF--------------TYPEDEF----------------------------TYPEDEF
    
typedef  long long ll;
typedef double ld;
typedef pair<ll,ll> pll;
typedef pair<ll,ll> pii;
typedef vector<ll> vll;
typedef vector<int> vi;    
    
//--------------CONSTANTS--------------CONSTANTS--------------CONSTANTS--------------CONSTANTS--------------CONSTANTS--------------CONSTANTS--------------CONSTANTS
//--------------CONSTANTS--------------CONSTANTS--------------CONSTANTS--------------CONSTANTS--------------CONSTANTS--------------CONSTANTS--------------CONSTANTS
    
const int INF=1e18+10;
const ll mod=1000000007;
const ld PI=acos(-1);    
    
    
    
    
    
//------------------IGNOREABLE_CONTENT------------------IGNOREABLE_CONTENT------------------IGNOREABLE_CONTENT------------------IGNOREABLE_CONTENT
    
    
    
// To find GCD of a and b
ll gcd(ll a, ll b);
    
    
// To compute x raised to power y under modulo m
    // To compute x^y under modulo m
int power(int x,  int y, int p) 
{ 
    int res = 1;      // Initialize result 
    
    x = x % p;  // Update x if it is more than or  
                // equal to p 
    
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
    
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p;   
    } 
    return res; 
}
// Function to find modular inverse of a under modulo m
// Assumption: m is prime
ll modInverse(ll a, ll m=mod)
{
    ll g =1;
    if (g != 1)
        cout << "Inverse doesn't exist";
    else
    {
        // If a and m are relatively prime, then modulo inverse
        // is a^(m-2) mode m
        return power(a, m-2, m);
    }
}
    
    
// Function to return gcd of a and b
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b%a, a);
}
void coordinate_compress(vector<int>& a)
{
    set<int> b;
    for(auto i:a)
        b.insert(i);
    map<int,int> da;
    int counter=0;
    for(auto i:b)
        da[i]=counter++;
    for(auto &i:a)
        i=da[i]; 
}
//----------------WORK__________________________________

//----------------------MAIN______________________________MAIN__________________MAINco
signed main()
{
    
    
    auto start = high_resolution_clock::now();

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    cout.tie(0);
  //  #define REERERE 1        
    #ifdef REERERE
        freopen ("INPUT.txt" , "r" , stdin);
        // freopen ("OUTPUT.txt" , "w" , stdout);
    #endif
//-----------------------------------------------------------------------------------------------------------
    int n,m,l;
    cin>>n>>m>>l;

    int dist[n+1][n+1];
    reset(dist);
    for(int i=0;i<n+1;i++)
        for(int j=0;j<n+1;j++)
            dist[i][j]=INF;
    for(int i=0;i<m;i++)
    {
        int a, b, c;
        cin>>a>>b>>c;
        dist[a][b]=c;
        dist[b][a]=c;
    }

    for(int k=1;k<=n;k++)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
                dist[i][j]=min(dist[i][j], dist[i][k]+dist[k][j]);
        }
    }
    int dist2[n+1][n+1];
    for(int i=0;i<n+1;i++)
        for(int j=0;j<n+1;j++)
            dist2[i][j]=INF;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            if(dist[i][j]<=l)
                dist2[i][j]=1;
     for(int k=1;k<=n;k++)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
                dist2[i][j]=min(dist2[i][j], dist2[i][k]+dist2[k][j]);
        }
    }   
    int q;
    cin>>q;
    for(int i=0;i<q;i++)
    {
        int s, t;
        cin>>s>>t;
        if(dist2[s][t]==INF)
            cout<<-1<<endl;
        else
        {
            cout<<dist2[s][t]-1<<endl;
        }
        
    }
//----------------------------------------------------------------------------------------------------------

    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop - start);
    
    //  cerr <<finishl<<"Time in microseconds:" <<duration.count() <<finishl<<"Time in seconds:"<<duration.count()/(1000000.0)<< finishl;
}
    

Measured memory_bytes: 1920