#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF (1 << 29)
#define LLINF (1LL << 60)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;

string to_string(string s) { return s; }

template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

template <class S>
string to_string(unordered_set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x) + ",";
  return ret + "}";
}

template <class S, class T>
string to_string(map<S, T> m) {
  string ret = "{";
  for (pair<S, T> x : m) ret += to_string(x) + ",";
  return ret + "}";
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < (int)v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() { cerr << endl; }

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

struct Edge {
  int from, to;
  ll cost;
};

struct Node {
  int hokyu, nokori, v;
  Node(int _hokyu, int _nokori, int _v) {
    hokyu = _hokyu;
    nokori = _nokori;
    v = _v;
  }
};

string to_string(Node n) {
  return "{" + to_string(n.hokyu) + "," + to_string(n.nokori) + "," +
         to_string(n.v) + "}";
}

int main() {
  cin.tie(0);
  int N, M;
  ll L;
  cin >> N >> M >> L;
  vector<vector<Edge>> G(N);
  FOR(i, M) {
    int A, B, C;
    cin >> A >> B >> C;
    A--;
    B--;
    G[A].push_back((Edge){A, B, C});
    G[B].push_back((Edge){B, A, C});
  }
  auto c = [](const Node& l, const Node& r) {
    return l.hokyu == r.hokyu ? l.nokori < r.nokori : l.hokyu > r.hokyu;
  };
  vector<vector<int>> cnts(N, vector<int>(N, INF));
  FOR(i, N) {
    vector<Pi> dists(N, Pi(INF, INF));
    priority_queue<Node, vector<Node>, decltype(c)> q(c);
    vector<bool> used(N);
    q.push(Node(0, L, i));
    dists[i] = Pi(0, -L);
    while (!q.empty()) {
      Node p = q.top();
      q.pop();
      int v = p.v;
      if (dists[v] < Pi(p.hokyu, -p.nokori) || used[v]) continue;
      used[v] = 1;
      dists[v] = Pi(p.hokyu, -p.nokori);
      cnts[i][v] = p.hokyu;
      for (Edge e : G[v]) {
        Node nnode = Node(p.hokyu, p.nokori - e.cost, e.to);
        if (used[e.to] || e.cost > L) continue;
        if (nnode.nokori < 0) {
          nnode.nokori = L - e.cost;
          nnode.hokyu++;
        }
        if (dists[e.to] > Pi(nnode.hokyu, -nnode.nokori)) {
          q.push(nnode);
        }
      }
    }
  }
  int Q;
  cin >> Q;
  FOR(i, Q) {
    int s, t;
    cin >> s >> t;
    s--;
    t--;
    int ans = cnts[s][t];
    cout << (ans == INF ? -1 : ans) << endl;
  }
  return 0;
}

Measured memory_bytes: 4384