#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:128000000")
using namespace std;
void solve();
void precalc();
int TESTNUM = 0;
int main() {
  string s = "";
  cin.tie(0);
  cout.sync_with_stdio(0);
  cout.precision(10);
  cout << fixed;
  precalc();
  int t = 1;
  while (t--) {
    ++TESTNUM;
    solve();
  }
  return 0;
}
template <typename T>
T binpow(T q, T w, T mod) {
  if (!w) return 1 % mod;
  if (w & 1) return q * 1LL * binpow(q, w - 1, mod) % mod;
  return binpow(q * 1LL * q % mod, w / 2, mod);
}
void precalc() {}
template <typename T>
T gcd(T q, T w) {
  while (w) {
    q %= w;
    swap(q, w);
  }
  return q;
}
template <typename T>
T lcm(T q, T w) {
  return q / gcd(q, w) * w;
}
inline int nxt() {
  int x;
  cin >> x;
  return x;
}
struct shop {
  int city;
  long long numItems;
  long long cost;
};
int n;
const int maxN = 5005;
vector<int> e[maxN];
vector<int> bfsd[maxN];
vector<int> bfs(int v) {
  vector<int> d(n, -1);
  d[v] = 0;
  deque<int> bfsQueue;
  bfsQueue.push_back(v);
  while (!bfsQueue.empty()) {
    int v = bfsQueue.front();
    bfsQueue.pop_front();
    for (int u : e[v])
      if (d[u] == -1) {
        d[u] = d[v] + 1;
        bfsQueue.push_back(u);
      }
  }
  return d;
}
int deliverTo;
long long needAmount;
long long maxCost;
vector<shop> shops;
bool can(int d) {
  long long need = needAmount;
  long long cost = 0;
  for (int i = 0; i < shops.size(); i++)
    if (bfsd[deliverTo][shops[i].city] != -1 &&
        bfsd[deliverTo][shops[i].city] <= d) {
      long long take = min(need, shops[i].numItems);
      cost += take * (long long)shops[i].cost;
      need -= take;
      if (need == 0) break;
      if (cost > maxCost) return false;
    }
  if (need != 0) return false;
  return cost <= maxCost;
}
void solve() {
  int m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    e[u].push_back(v);
    e[v].push_back(u);
  }
  int nShops;
  cin >> nShops;
  shops.resize(nShops);
  for (int i = 0; i < nShops; i++) {
    cin >> shops[i].city >> shops[i].numItems >> shops[i].cost;
    shops[i].city--;
  }
  sort(shops.begin(), shops.end(),
       [](const shop& a, const shop& b) { return a.cost < b.cost; });
  for (int i = 0; i < n; i++) bfsd[i] = bfs(i);
  int nq;
  cin >> nq;
  for (int i = 0; i < nq; i++) {
    cin >> deliverTo >> needAmount >> maxCost;
    deliverTo--;
    if (can(0)) {
      cout << 0 << "\n";
      continue;
    }
    if (!can(n)) {
      cout << -1 << "\n";
      continue;
    }
    int low = 0, high = n;
    while (low + 1 != high) {
      int m = (low + high) / 2;
      if (can(m))
        high = m;
      else
        low = m;
    }
    cout << high << "\n";
  }
}
