#include <bits/stdc++.h>
using namespace std;
long long n, m, x, t, q, w, l, k, y, z, sp[5002];
vector<int> adj[5002];
vector<pair<pair<long long, long long>, int> > st;
void bfs(int v) {
  for (int i = 0; i <= n; ++i) sp[i] = -1;
  queue<int> q;
  q.push(v);
  sp[v] = 0;
  while (!q.empty()) {
    int u = q.front(), r;
    q.pop();
    for (int i = 0; i < adj[u].size(); ++i) {
      r = adj[u][i];
      if (sp[r] == -1) sp[r] = sp[u] + 1, q.push(r);
    }
  }
}
bool check(int x, long long y, long long z) {
  vector<pair<long long, long long> > p;
  for (int i = 0; i < w; ++i) {
    int u = st[i].second;
    if (sp[u] > x || sp[u] == -1) continue;
    p.push_back(st[i].first);
  }
  int i = 0;
  while (i < p.size() && y >= p[i].second)
    y -= p[i].second, z -= p[i].first * p[i].second, ++i;
  if (i < p.size()) z -= y * p[i].first, y = 0;
  return !y && z >= 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  cin >> w;
  for (int i = 0; i < w; ++i) {
    cin >> x >> y >> z;
    st.push_back({{z, y}, (int)x});
  }
  sort(st.begin(), st.end());
  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> x >> y >> z;
    bfs(x);
    k = 0;
    for (int i = 4096; i > 0; i /= 2)
      if (!check(i + k, y, z)) k += i;
    if (check(0, y, z))
      cout << 0 << endl;
    else if (k > 5000)
      cout << -1 << endl;
    else
      cout << k + 1 << endl;
  }
}
