#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5000;
vector<int> G[MAXN + 10];
vector<pair<int, int> > W[MAXN + 10];
struct point {
  int len, cnt, cost;
};
int c[MAXN + 10], k[MAXN + 10], p[MAXN + 10];
bool cmp(const point& a, const point& b) { return a.cost < b.cost; }
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int w;
  cin >> w;
  for (int i = 0; i < w; i++) {
    cin >> c[i] >> k[i] >> p[i];
    W[c[i]].push_back({k[i], p[i]});
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int v, cnt, val;
    cin >> v >> cnt >> val;
    queue<int> q;
    q.push(v);
    vector<int> used(MAXN + 10, 0), d(MAXN + 10, -1);
    d[v] = 0;
    used[v] = 1;
    vector<point> temp;
    int mx = 0;
    for (auto x : W[v]) temp.push_back({0, x.first, x.second});
    while (!q.empty()) {
      int cur = q.front();
      q.pop();
      for (int i = 0; i < (int)G[cur].size(); i++) {
        int u = G[cur][i];
        if (!used[u]) {
          for (auto x : W[u]) temp.push_back({d[cur] + 1, x.first, x.second});
          d[u] = d[cur] + 1;
          mx = max(mx, d[u]);
          used[u] = 1;
          q.push(u);
        }
      }
    }
    sort(temp.begin(), temp.end(), cmp);
    int l = -1, r = mx + 1, dist;
    while (r > l + 1) {
      dist = (l + r) / 2;
      long long cur = 0, sum = 0;
      for (int i = 0; i < (int)temp.size() && (sum > val || cur < cnt); i++) {
        if (temp[i].len > dist) continue;
        int delta = min(cnt - cur, (long long)temp[i].cnt);
        sum += 1LL * delta * temp[i].cost;
        cur += delta;
      }
      if (sum <= val && cur == cnt)
        r = dist;
      else
        l = dist;
    }
    if (r == mx + 1)
      cout << "-1\n";
    else
      cout << r << "\n";
  }
  return 0;
}
