#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

LL dist[300][300] = {{0}};
LL dist2[300][300] = {{0}};
const LL INF = 1e12;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL n,m,l;
    cin>>n>>m>>l;

    REP(i,300)REP(j,300){
        if(i == j){
            dist[i][j] = 0;
        }
        else{
            dist[i][j] = INF;
        }
    }
    REP(i,m){
        LL a,b,c;
        cin>>a>>b>>c;
        if(c > l)continue;
        dist[a-1][b-1] = c;
        dist[b-1][a-1] = c;
    }

    REP(k,n)REP(i,n)REP(j,n)dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);

    REP(i,300)REP(j,300){
        if(i == j){
            dist2[i][j] = 0;
        }
        else{
            dist2[i][j] = INF;
        }
    }

    REP(i,n)FOR(j,i+1,n)if(dist[i][j] <= l){
        dist2[i][j] = 1;
        dist2[j][i] = 1;
    }
    REP(k,n)REP(i,n)REP(j,n)dist2[i][j] = min(dist2[i][j], dist2[i][k] + dist2[k][j]);

    VVL reachable_towns(n);
    REP(i,n)FOR(j,i+1,n)if(dist[i][j] <= l){
        reachable_towns[i].PB(j);
        reachable_towns[j].PB(i);
    }

    LL q;
    cin>>q;
    REP(i,q){
        LL s,t;
        cin>>s>>t;
        s--;
        t--;
        if(dist[s][t] == INF){
            PUTS(-1);
            continue;
        }
        PUTS(dist2[s][t]-1);

        //LL ans = 0;
        //VL closed(n,0);
        //VL next_towns = reachable_towns[s];
        //REP(i,next_towns.size())closed[next_towns[i]] = 1;
        //closed[s]=1;
        //UNTIL(find(ALL(next_towns), t) != next_towns.end()){
        //    VL tmp_towns;
        //    EACH(itr, next_towns){
        //        EACH(itr2, reachable_towns[*itr]){
        //            if(!closed[*itr2]){
        //                closed[*itr2] = 1;
        //                tmp_towns.PB(*itr2);
        //            }
        //        }
        //    }
        //    next_towns = tmp_towns;
        //    ans++;
        //}
        //PUTS(ans);
    }
}

Measured memory_bytes: 3072