#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define outa(x, n) rep(x_i,n) cout<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const ll INFL = (1L<<61);

int main() {
  ll n, m, L; cin >> n >> m >> L;
  vvl dist(n,vl(n,INFL));
  rep(i,n) dist[i][i] = 0;
  rep(i,m) {
    ll a, b, c; scanf("%lld %lld %lld", &a, &b, &c);
    a--; b--;
    dist[a][b] = dist[b][a] = c;
  }
  rep(k,n) rep(i,n) rep(j,n) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);

  vvl ans(n,vl(n,INFL));
  rep(i,n) rep(j,n) if (dist[i][j] <= L) ans[i][j] = 1;
  rep(i,n) ans[i][i] = 0;
  rep(k,n) rep(i,n) rep(j,n) ans[i][j] = min(ans[i][j], ans[i][k] + ans[k][j]);

  ll Q; cin >> Q;
  rep(i,Q) {
    ll s, t; scanf("%lld %lld", &s, &t);
    s--; t--;
    if (ans[s][t] == INFL) {
      cout << -1 << endl;
    } else {
      cout << ans[s][t] - 1 << endl;
    }
  }
  return 0;
}
