#include <bits/stdc++.h>
using namespace std;
const int N = 5000 + 5;
vector<int> g[N];
int n, m;
int w;
int d[N];
struct T {
  int c, k, p;
  bool operator<(const T &x) const { return p < x.p; }
} shop[N];
bool ch(int h, int r, long long a) {
  for (int i = 1; i <= w; ++i) {
    if (d[shop[i].c] > h) continue;
    if (d[shop[i].c] == -1) continue;
    int d = min(r, shop[i].k);
    a -= 1ll * d * shop[i].p;
    r -= d;
  }
  return (r == 0 && a >= 0);
}
void bfs(int x) {
  deque<int> dq;
  fill(begin(d), end(d), -1);
  dq.push_back(x);
  d[x] = 0;
  while (dq.size()) {
    int u = dq.front();
    dq.pop_front();
    for (auto &v : g[u]) {
      if (d[v] == -1) d[v] = d[u] + 1, dq.push_back(v);
    }
  }
}
int solve(int g, int r, long long a) {
  bfs(g);
  int low = 0, high = n + 5, mid;
  if (!ch(high, r, a)) return -1;
  while (low <= high) {
    mid = (low + high) / 2;
    if (ch(mid, r, a))
      high = mid - 1;
    else
      low = mid + 1;
  }
  return low;
  return 0;
}
signed main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  cin >> w;
  for (int i = 1; i <= w; ++i) {
    cin >> shop[i].c >> shop[i].k >> shop[i].p;
  }
  sort(shop + 1, shop + 1 + w);
  int q;
  cin >> q;
  while (q--) {
    long long g, r, a;
    cin >> g >> r >> a;
    cout << solve(g, r, a) << '\n';
  }
}
