#include <bits/stdc++.h>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){

  ll n,m,l;cin>>n>>m>>l;
  vector<LP> v[n];

  UnionFind tree(n);

  REP(i,m){
    ll a,b,c;cin>>a>>b>>c;
    a--;
    b--;
    LP lp;
    lp.first = b;
    lp.second = c;
    v[a].pb(lp);
    lp.first = a;
    v[b].pb(lp);

    tree.unite(a,b);
  }

  vector<ll> oneV[n];

  //仕込み
  REP(i,n){
    queue<ll> q;
    ll gas[n];
    REP(j,n){
      gas[j] = -100;
    }
    gas[i] = l;
    q.push(i);
    while(!q.empty()){
      ll start = q.front();
      ll myGas = gas[start];
      q.pop();
      REP(j,v[start].size()){
        LP lp = v[start][j];
        ll next = lp.first;
        ll nowGas = myGas - lp.second;
        if(nowGas>=0 && nowGas > gas[next]){
          gas[next] = nowGas;
          q.push(next);
        }
      }
    }
    REP(j,n){
      if(gas[j] >= 0 && j != i){
        oneV[i].pb(j);
      }
    }
  }

  ll q;cin>>q;
  REP(i,q){
    ll s,t;cin>>s>>t;
    s--;t--;

    if(tree.same(s,t) == false){
      cout<<-1<<endl;
    }else{
      queue<ll> q;
      q.push(s);
      ll cost[n];
      REP(i,n){
        cost[i] = INF;
      }
      cost[s] = -1;
      while(!q.empty()){
        ll now = q.front();
        q.pop();
        ll nowCost = cost[now];
        REP(j,oneV[now].size()){
          if(cost[oneV[now][j]] > nowCost + 1){
            cost[oneV[now][j]] = nowCost + 1;
            q.push(oneV[now][j]);
            if(oneV[now][j] == t){
              break;
            }
          }
        }
        if(cost[t] != INF){
          break;
        }
      }
      if(cost[t] == INF){
        cout<<-1<<endl;
      }else{
        cout<<cost[t]<<endl;
      }
    }
  }


  return 0;
}

Measured memory_bytes: 4096