#include <bits/stdc++.h>
using namespace std;
const int N = (int)5e3 + 5;
struct TSpecial {
  int city, k, p;
  TSpecial() {}
  TSpecial(int city, int k, int p) : city(city), k(k), p(p) {}
  bool operator<(const TSpecial& op) const {
    if (p != op.p) return p < op.p;
    if (k != op.k) return k < op.k;
    return city < op.city;
  }
} x[N];
int n, m, w, q;
int vis[N];
vector<int> g[N];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  scanf("%d", &w);
  for (int i = 1; i <= w; i++) scanf("%d %d %d", &x[i].city, &x[i].k, &x[i].p);
  sort(x + 1, x + 1 + w);
  scanf("%d", &q);
  while (q--) {
    int gg, r, a;
    scanf("%d %d %d", &gg, &r, &a);
    memset(vis, -1, sizeof vis);
    vis[gg] = 0;
    queue<int> q;
    q.push(gg);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int i = 0; i < g[u].size(); i++) {
        int v = g[u][i];
        if (vis[v] == -1) {
          vis[v] = vis[u] + 1;
          q.push(v);
        }
      }
    }
    vector<pair<int, int> > v;
    int left = 0, right = n + 1, mid, ans = -1;
    while (left <= right) {
      v.clear();
      mid = 2;
      mid = (left + right) >> 1;
      for (int i = 1; i <= w; i++)
        if (vis[x[i].city] <= mid && vis[x[i].city] != -1)
          v.push_back(make_pair(x[i].p, x[i].k));
      int has = 0;
      long long tmp = 0;
      bool ok = false;
      for (int i = 0; i < v.size(); i++) {
        int pp = v[i].first;
        int kk = v[i].second;
        int x = min(kk, r - has);
        tmp += 1LL * x * pp;
        has += x;
        if (has >= r && tmp <= a) {
          ok = true;
          break;
        }
      }
      if (ok) {
        ans = mid;
        right = mid - 1;
      } else
        left = mid + 1;
    }
    printf("%d\n", ans);
  }
  return 0;
}
