#include <bits/stdc++.h>
using namespace std;
const int maxn = 5010;
vector<int> adj[maxn];
int d[maxn], p[maxn], k[maxn], c[maxn], id[maxn];
bool cmp(int i, int j) { return p[i] < p[j]; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, i, j, w, q;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  cin >> w;
  for (i = 0; i < w; i++) {
    cin >> c[i] >> k[i] >> p[i];
    id[i] = i;
  }
  sort(id, id + w, cmp);
  cin >> q;
  for (int z = 0; z < q; z++) {
    int r, g, a;
    cin >> r >> g >> a;
    for (int l = 0; l < n + 10; l++) d[l] = INT_MAX;
    queue<int> Q;
    d[r] = 0;
    Q.push(r);
    while (!Q.empty()) {
      int u = Q.front();
      Q.pop();
      for (auto v : adj[u]) {
        if (d[v] < INT_MAX) continue;
        d[v] = d[u] + 1;
        Q.push(v);
      }
    }
    int l = 0, ri = n, ans = -1;
    while (l <= ri) {
      int mid = (l + ri) / 2;
      int help = g;
      long long int A = a;
      for (int j = 0; j < w; j++) {
        i = id[j];
        if (d[c[i]] > mid) continue;
        int buy = min(help, k[i]);
        help -= buy;
        A -= 1LL * buy * p[i];
      }
      if (A < 0 || help)
        l = mid + 1;
      else {
        ans = mid;
        ri = mid - 1;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
