#include <bits/stdc++.h>
using namespace std;
long long int sum, max_lev;
vector<pair<long long int, long long int>> level[5010];
vector<long long int> adj[5010];
vector<pair<long long int, long long int>> store[5010];
vector<pair<pair<long long int, long long int>, long long int>> v;
long long int vis[5010];
void bfs(long long int s, long long int lev) {
  queue<pair<long long int, long long int>> q;
  q.push(make_pair(s, lev));
  vis[s] = 1;
  while (!q.empty()) {
    s = q.front().first;
    lev = q.front().second;
    for (long long int i = 0; i < store[s].size(); i++) {
      level[lev].push_back(make_pair(store[s][i].first, store[s][i].second));
      sum += store[s][i].first;
    }
    q.pop();
    max_lev = max(lev, max_lev);
    for (long long int i = 0; i < adj[s].size(); i++) {
      if (vis[adj[s][i]] == 0) {
        vis[adj[s][i]] = 1;
        q.push(make_pair(adj[s][i], lev + 1));
      }
    }
  }
}
bool check(long long int mid, long long int max_cost, long long int tot) {
  long long int cost = 0, curr = 0, p, rem, i, j;
  for (i = 0; i < v.size(); i++) {
    if (v[i].second > mid) continue;
    p = v[i].first.first * v[i].first.second;
    if (cost + p > max_cost) {
      rem = max_cost - cost;
      p = rem / v[i].first.first;
      curr += p;
      break;
    }
    curr += v[i].first.second;
    cost += p;
  }
  if (curr >= tot) return true;
  return false;
}
long long int bs(long long int low, long long int high, long long int max_cost,
                 long long int tot) {
  long long int ans = -1;
  while (low <= high) {
    long long int mid = (low + high) / 2;
    if (check(mid, max_cost, tot)) {
      high = mid - 1;
      ans = mid;
    } else {
      low = mid + 1;
    }
  }
  return ans;
}
int main() {
  long long int n, m, a, b, i, w, c, k, p, q, g, r, j;
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  cin >> w;
  for (i = 1; i <= w; i++) {
    cin >> c >> k >> p;
    store[c].push_back(make_pair(k, p));
  }
  cin >> q;
  while (q--) {
    sum = max_lev = 0;
    cin >> g >> r >> a;
    for (i = 0; i <= n; i++) level[i].clear();
    v.clear();
    memset(vis, 0, sizeof(vis));
    bfs(g, 0);
    if (sum < r) {
      cout << "-1\n";
      continue;
    }
    for (i = 0; i <= max_lev; i++) {
      for (j = 0; j < level[i].size(); j++) {
        v.push_back(
            make_pair(make_pair(level[i][j].second, level[i][j].first), i));
      }
    }
    sort(v.begin(), v.end());
    cout << bs(0, max_lev, a, r) << "\n";
  }
  return 0;
}
