#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e18 + 3)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}
const int n_max = 303;
pair<int,int> dist[n_max][n_max];
bool vis[n_max];


struct hoge{
    int id;
    int ho;
    int l;
};


signed main(){
    int n,m,l;
    cin >> n >> m >> l;
    int G[n_max][n_max];
    REP(i,n) REP(j,n) G[i][j] = -1;
    REP(i,m){
        int a,b,c;
        cin >> a >> b >> c;
        a --;
        b --;
        G[a][b] = c;
        G[b][a] = c;
    }

    REP(i,n) REP(j,n) dist[i][j] = mp(INF,INF);
    REP(i,n-1){
        auto c = [](hoge l, hoge r) { if (l.ho != r.ho) return l.ho > r.ho; else return l.l > r.l; };
        std::priority_queue<hoge, std::vector<hoge>, decltype(c)> Q(c);
        Q.push( hoge{i,0,- l});
        REP(j,n) vis[j] = false;
        while(Q.size() != 0){
            hoge tmp = Q.top();
            Q.pop();
            if(vis[tmp.id]) continue;
            vis[tmp.id] = true;
            REP(j,n){
                if( G[tmp.id][j] == -1 or vis[j] ) continue;


                if( - tmp.l < G[tmp.id][j] and G[tmp.id][j] <= l){
                    if(dist[i][j] > mp(tmp.ho + 1,- l + G[tmp.id][j]) ){
                        Q.push( hoge{j,tmp.ho + 1, - l + G[tmp.id][j]});
                        dist[i][j] = mp(tmp.ho + 1, - l + G[tmp.id][j]);
                    }
                }
                else if( G[tmp.id][j] <= -tmp.l){
                    if( dist[i][j] > mp( tmp.ho, - (- tmp.l - G[tmp.id][j]) )){
                        Q.push( hoge{j,tmp.ho, - (- tmp.l - G[tmp.id][j]) });
                        dist[i][j] = mp(tmp.ho, - (- tmp.l - G[tmp.id][j] ));
                    }
                }
            }
        }
    }
    /*
    debug(dist[0][1].fi);
    debug(dist[0][1].se);
    debug(dist[0][2].fi);
    debug(dist[0][2].se);
    debug(dist[0][3].fi);
    debug(dist[0][3].se);
    debug(dist[0][4].fi);
    debug(dist[0][4].se);
    */

    int q;
    cin >> q;
    REP(i,q){
        int s,t;
        cin >> s >> t;
        s --;
        t --;
        if(s > t) swap(s,t);
        if(dist[s][t].fi != INF)cout << dist[s][t].fi << endl;
        else cout << - 1 << endl;
    }
}

Measured memory_bytes: 2688