#include <bits/stdc++.h>
using namespace std;
struct store {
  int c, k, p;
  bool operator<(const store& R) const { return p < R.p; }
};
vector<vector<int> > graph;
vector<bool> mark;
vector<int> dist;
vector<store> stores;
void BFS(int v) {
  queue<int> Q;
  Q.push(v);
  dist[v] = 0;
  mark[v] = true;
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (auto w : graph[u]) {
      if (!mark[w]) {
        mark[w] = true;
        dist[w] = dist[u] + 1;
        Q.push(w);
      }
    }
  }
}
bool can(int v, int d, int need, int budget) {
  for (int i = 0; i < stores.size(); ++i) {
    if (!mark[stores[i].c] || dist[stores[i].c] > d) continue;
    if (need * (long long)stores[i].p > budget) {
      return false;
    }
    int give = min(need, stores[i].k);
    budget -= give * stores[i].p;
    need -= give;
    if (need == 0) {
      return true;
    }
  }
  return false;
}
int main() {
  int n, m, w, q;
  cin >> n >> m;
  graph = vector<vector<int> >(n + 1);
  mark = vector<bool>(n + 1, false);
  dist = vector<int>(n + 1, -1);
  for (int i = 0; i < m; ++i) {
    int v, u;
    cin >> v >> u;
    graph[v].push_back(u);
    graph[u].push_back(v);
  }
  cin >> w;
  stores = vector<store>(w);
  for (int i = 0; i < w; ++i) {
    int c, k, p;
    cin >> c >> k >> p;
    stores[i] = {c, k, p};
  }
  sort(stores.begin(), stores.end());
  cin >> q;
  while (q--) {
    int g, r, a;
    cin >> g >> r >> a;
    int tl = 0, tr = n;
    int ans = -1;
    fill(mark.begin(), mark.end(), false);
    fill(dist.begin(), dist.end(), -1);
    BFS(g);
    while (tl <= tr) {
      int m = (tl + tr) >> 1;
      if (can(g, m, r, a)) {
        ans = m;
        tr = m - 1;
      } else {
        tl = m + 1;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
