#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
auto compare = [](T x, T y) -> bool { return (x < y); };
const int MOD = 1000000007;
ll N, M, L;
ll cost[301][301];
void floyd() {
  for (int(k) = 0; (k) < (N); ++(k)) {
    for (int(i) = 0; (i) < (N); ++(i)) {
      for (int(j) = 0; (j) < (N); ++(j)) {
        cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
        cost[j][i] = cost[i][j];
      }
    }
  }
  for (int(i) = 0; (i) < (N); ++(i))
    for (int(j) = 0; (j) < (N); ++(j))
      cost[i][j] = ((cost[i][j] <= L) ? 1 : INT64_MAX / 2);
  for (int(k) = 0; (k) < (N); ++(k)) {
    for (int(i) = 0; (i) < (N); ++(i)) {
      for (int(j) = 0; (j) < (N); ++(j)) {
        cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
        cost[j][i] = cost[i][j];
      }
    }
  }
}
signed main() {
  cin >> N >> M >> L;
  ll A, B, C;
  for (int(i) = 0; (i) < (N); ++(i))
    for (int(j) = 0; (j) < (N); ++(j)) cost[i][j] = INT64_MAX / 2;
  for (int(i) = 0; (i) < (M); ++(i)) {
    cin >> A >> B >> C;
    A--;
    B--;
    cost[A][B] = cost[B][A] = C;
  }
  floyd();
  ll Q, s, t;
  cin >> Q;
  for (int(i) = 0; (i) < (Q); ++(i)) {
    cin >> s >> t;
    s--;
    t--;
    if (cost[s][t] == INT64_MAX / 2)
      cout << ("-1") << "\n";
    else
      cout << (cost[s][t] - 1) << "\n";
  }
  return 0;
}
