#include <bits/stdc++.h>
using namespace std;
vector<int> e[5015];
int dis[5015], n, m, q, w, s, r, a;
bool v[5015];
queue<int> qu;
struct store {
  int c, k, p;
  bool operator<(const store &x) const { return p < x.p; }
} st[5010];
int bfs(int s) {
  int t = 0;
  for (int i = 1; i <= n; i++) {
    v[i] = false;
    dis[i] = 1e9;
  }
  v[s] = true;
  dis[s] = 0;
  qu.push(s);
  while (!qu.empty()) {
    t = qu.front();
    qu.pop();
    for (int i = 0; i < e[t].size(); i++)
      if (!v[e[t][i]]) {
        dis[e[t][i]] = dis[t] + 1;
        v[e[t][i]] = true;
        qu.push(e[t][i]);
      }
  }
  return dis[t];
}
bool check(int len) {
  long long num = 0, price = 0;
  for (int i = 1; i <= w; i++)
    if (dis[st[i].c] <= len) {
      store t = st[i];
      if (num + t.k < r) {
        num += t.k;
        price += t.k * t.p;
      } else {
        price += (r - num) * t.p;
        num = r;
        break;
      }
    }
  if (num == r && price <= a) return true;
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    e[x].push_back(y);
    e[y].push_back(x);
  }
  cin >> w;
  for (int i = 1; i <= w; i++) cin >> st[i].c >> st[i].k >> st[i].p;
  sort(st + 1, st + 1 + w);
  cin >> q;
  for (int T = 1; T <= q; T++) {
    cin >> s >> r >> a;
    int len = bfs(s);
    int l = 0, r = len;
    if (!check(len)) {
      cout << -1 << endl;
      continue;
    }
    while (l + 1 < r) {
      int mid = (l + r) / 2;
      if (check(mid))
        r = mid;
      else
        l = mid;
    }
    if (check(l)) r = l;
    cout << r << endl;
  }
}
