#include <bits/stdc++.h>
using namespace std;
int fst[5050], nxt[50500], vv[50500], e;
int n, m, w, q;
int f[50500];
void init() {
  e = 0;
  memset(fst, -1, sizeof fst);
}
void add(int u, int v) {
  vv[e] = v, nxt[e] = fst[u], fst[u] = e++;
  vv[e] = u, nxt[e] = fst[v], fst[v] = e++;
}
struct node {
  int u, n, p;
} x[5050];
bool cmp(node a, node b) { return a.p < b.p; }
pair<int, int> g[5050];
bool check(int mid, int xx, long long yy) {
  int tmp = 0;
  for (int i = 0; i < w; i++) {
    if (f[x[i].u] == -1 || f[x[i].u] > mid) continue;
    int now = min(xx, x[i].n);
    if (yy < 1LL * now * x[i].p) return 0;
    yy -= 1LL * now * x[i].p;
    xx -= now;
    if (xx == 0) return yy >= 0;
  }
  return 0;
}
int main() {
  init();
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add(u, v);
  }
  scanf("%d", &w);
  for (int i = 0; i < w; i++) {
    scanf("%d%d%d", &x[i].u, &x[i].n, &x[i].p);
  }
  sort(x, x + w, cmp);
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int u, a, b;
    scanf("%d%d%d", &u, &a, &b);
    memset(f, -1, sizeof f);
    f[u] = 0;
    queue<int> que;
    que.push(u);
    while (!que.empty()) {
      int u = que.front();
      que.pop();
      for (int i = fst[u]; ~i; i = nxt[i]) {
        int v = vv[i];
        if (f[v] == -1) {
          f[v] = f[u] + 1;
          que.push(v);
        }
      }
    }
    int mid, l = 0, r = 0;
    for (int i = 1; i <= n; i++) {
      if (f[i] != -1) {
        r = max(r, f[i]);
      }
    }
    int ans = -1;
    while (l <= r) {
      mid = (l + r) >> 1;
      if (check(mid, a, b))
        ans = mid, r = mid - 1;
      else
        l = mid + 1;
    }
    printf("%d\n", ans);
  }
  return 0;
}
