#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, w, Q, g, r, a;
int dis[5005][5005], re;
vector<int> adj[5005];
struct node {
  int c, k, p;
  bool operator<(node a) const { return p < a.p; }
} go[5005];
int bs(int lo, int up) {
  if (lo == up) return lo;
  int mid = (lo + up) / 2;
  long long buy = 0, spe = 0;
  for (int i = 0; i < w; i++) {
    if (dis[g][go[i].c] > mid || dis[g][go[i].c] < 0) continue;
    long long price = go[i].p, amount = go[i].k;
    if (buy + amount >= r) {
      spe += price * (r - buy);
      buy = r;
    } else {
      spe += price * amount;
      buy += amount;
    }
  }
  if (buy < r)
    return bs(mid + 1, up);
  else if (spe <= (long long)a)
    return bs(lo, mid);
  else
    return bs(mid + 1, up);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) adj[i].clear();
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &x, &y);
    x--;
    y--;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  scanf("%d", &w);
  for (int i = 0; i < w; i++) {
    scanf("%d%d%d", &go[i].c, &go[i].k, &go[i].p);
    go[i].c--;
  }
  sort(go, go + w);
  scanf("%d", &Q);
  memset(dis, -1, sizeof(dis));
  while (Q--) {
    scanf("%d%d%d", &g, &r, &a);
    g--;
    if (dis[g][g] == -1) {
      dis[g][g] = 0;
      queue<int> q;
      q.push(g);
      while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (int j = 0; j < ((int)(adj[u]).size()); j++) {
          int v = adj[u][j];
          if (dis[g][v] == -1) dis[g][v] = dis[g][u] + 1, q.push(v);
        }
      }
    }
    re = bs(0, n);
    if (re == n) re = -1;
    printf("%d\n", re);
  }
  return 0;
}
