#include <bits/stdc++.h>
using namespace std;
const int M = 5005;
int n, m, head[M], cnt, w, Q, dis[M];
struct store {
  int pos, num, pri;
  bool friend operator<(store a, store b) { return a.pri < b.pri; }
} s[M];
struct edge {
  int v, next;
} e[M << 1];
void add(int u, int v) {
  e[++cnt].v = v;
  e[cnt].next = head[u];
  head[u] = cnt;
}
struct node {
  int ID, dis;
};
queue<node> q;
void bfs(int x) {
  memset(dis, -1, sizeof(dis));
  q.push((node){x, 0});
  dis[x] = 0;
  while (!q.empty()) {
    node s = q.front();
    q.pop();
    int ID = s.ID, d = s.dis;
    for (int i = head[ID]; i != 0; i = e[i].next) {
      int to = e[i].v;
      if (dis[to] != -1) continue;
      q.push((node){to, d + 1});
      dis[to] = d + 1;
    }
  }
}
bool check(int tot, long long lim, int ans) {
  for (int i = 1; i <= w; i++) {
    int p = s[i].pos;
    if (0 <= dis[p] && dis[p] <= ans) {
      if (tot >= s[i].num)
        tot -= s[i].num, lim -= 1ll * s[i].num * s[i].pri;
      else
        lim -= 1ll * tot * s[i].pri, tot = 0;
      if (!tot) break;
    }
  }
  if (tot || lim < 0) return false;
  return true;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int x, y, i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    add(x, y);
    add(y, x);
  }
  scanf("%d", &w);
  for (int i = 1; i <= w; i++) scanf("%d%d%d", &s[i].pos, &s[i].num, &s[i].pri);
  sort(s + 1, s + 1 + w);
  scanf("%d", &Q);
  for (int to, tot, lim, i = 1; i <= Q; i++) {
    scanf("%d%d%d", &to, &tot, &lim);
    bfs(to);
    int l = 0, r = n, ans = -1;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (check(tot, lim, mid)) {
        ans = mid;
        r = mid - 1;
      } else
        l = mid + 1;
    }
    printf("%d\n", ans);
  }
  return 0;
}
