#include <bits/stdc++.h>
inline int RD() {
  char cr;
  int res;
  while ((cr = getchar()) < '0' || cr > '9')
    ;
  res = cr - '0';
  while ((cr = getchar()) >= '0' && cr <= '9') res = res * 10 + cr - '0';
  return res;
}
int head[5005], next[5005 * 5], eg[5005 * 5], egtot;
int fst[5005], nxt[5005];
int num[5005], prc[5005];
int dis[5005];
int q[5005];
int odr[5005];
int used[5005], timetip;
int n, m, store;
bool cmpodr(int a, int b) { return prc[a] < prc[b]; }
void addEdge(int p1, int p2) {
  eg[++egtot] = p2;
  next[egtot] = head[p1];
  head[p1] = egtot;
}
bool query(int ct, int need, int pay, int d) {
  if (d > n) return 1;
  int l, r, p;
  q[l = r = 1] = ct;
  for (int i = 1; i <= n; i++) dis[i] = 30000007;
  dis[ct] = 0;
  while (l <= r) {
    p = q[l++];
    if (dis[p] == d) continue;
    for (int e = head[p]; e; e = next[e])
      if (dis[eg[e]] == 30000007) {
        dis[eg[e]] = dis[p] + 1;
        q[++r] = eg[e];
      }
    if (r == n) break;
  }
  ++timetip;
  for (int i = 1; i <= n; i++)
    if (dis[i] < 30000007) {
      for (int j = fst[i]; j; j = nxt[j]) used[j] = timetip;
    }
  int getnum = 0, getprc = 0;
  for (int i = 1; i <= store; i++) {
    if (used[odr[i]] != timetip) continue;
    int has = num[odr[i]];
    int price = prc[odr[i]];
    if (getnum + has <= need) {
      getnum += has;
      if ((long long)getprc + (long long)has * price > pay) return 0;
      getprc += has * price;
    } else if (getnum < need) {
      if ((long long)getprc + (long long)(need - getnum) * price > pay)
        return 0;
      getprc += (need - getnum) * price;
      getnum = need;
    } else
      break;
  }
  return getnum == need && getprc <= pay;
}
int solve(int ct, int need, int pay) {
  int l = -1, r = n + 1, mid;
  while (l < r - 1) {
    mid = (l + r) >> 1;
    if (query(ct, need, pay, mid))
      r = mid;
    else
      l = mid;
  }
  if (r > n)
    return -1;
  else
    return r;
}
int main() {
  n = RD();
  m = RD();
  for (int i = 1, p1, p2; i <= m; i++) {
    p1 = RD();
    p2 = RD();
    addEdge(p1, p2);
    addEdge(p2, p1);
  }
  store = RD();
  for (int i = 1, ci, ki, pi; i <= store; i++) {
    ci = RD();
    ki = RD();
    pi = RD();
    nxt[i] = fst[ci];
    fst[ci] = i;
    num[i] = ki;
    prc[i] = pi;
  }
  for (int i = 1; i <= store; i++) odr[i] = i;
  std::sort(odr + 1, odr + 1 + store, cmpodr);
  int ques = RD();
  while (ques--) {
    int ct, need, pay;
    ct = RD();
    need = RD();
    pay = RD();
    int ans = solve(ct, need, pay);
    printf("%d\n", ans);
  }
}
