#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;


int main(){
  int n,m,l;
  cin >> n >> m >> l;
  vector<vector<ll>> d(310, vector<ll>(310,longinf));
  rep(i,m){
    int a,b,c; cin >> a >> b >> c; a--; b--;
    d[a][b] = c;
    d[b][a] = c;
  }
  rep(k,n)rep(i,n)rep(j,n) d[i][j] = min(d[i][j], d[i][k]+d[k][j]);

  vector<vector<ll>> gas(n, vector<ll>(n,longinf));
  rep(i,n) gas[i][i] = 0;
  rep(i,n)rep(j,n)if(d[i][j]<=l) gas[i][j] = 1;
  rep(k,n)rep(i,n)rep(j,n) gas[i][j] = min(gas[i][j], gas[i][k]+gas[k][j]);

  int q; cin >> q;
  while(q--){
    int s,t; cin >> s >> t; s--; t--;
    ll ans = gas[s][t] - 1;
    if(ans>=longinf-1) ans = -1;
    cout << ans << endl;
  }
  return 0;
}
