#include <bits/stdc++.h>
using namespace std;
struct node {
  int v, next;
} edge[5005 << 1];
int head[5005], cnt;
int n, m, w;
struct Q {
  int num, price, id;
  bool operator<(const Q &a) const { return price < a.price; }
};
vector<Q> gg;
void add_edge(int u, int v) {
  edge[cnt].v = v, edge[cnt].next = head[u], head[u] = cnt++;
}
int s, d[5005];
long long r, cost;
bool vis[5005];
queue<int> q;
bool ok(int x) {
  long long tot = 0;
  long long sum = 0;
  for (int i = 0; i < w; i++)
    if (d[gg[i].id] <= x) {
      if (gg[i].num + sum <= r) {
        tot += 1LL * gg[i].num * gg[i].price;
        sum += gg[i].num;
      } else {
        tot += (r - sum) * gg[i].price;
        sum = r;
      }
    }
  return sum == r && tot <= cost;
}
void bfs() {
  for (int i = 1; i <= n; i++) d[i] = 1e9;
  d[s] = 0;
  memset(vis, 0, sizeof vis);
  vis[s] = 1;
  while (!q.empty()) q.pop();
  q.push(s);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; i + 1; i = edge[i].next) {
      int v = edge[i].v;
      if (vis[v]) continue;
      vis[v] = 1;
      d[v] = d[u] + 1;
      q.push(v);
    }
  }
  int l = 0, r = n;
  long long tmp;
  int Min;
  while (r - l > 1) {
    int mid = (l + r) >> 1;
    if (ok(mid))
      r = mid;
    else
      l = mid;
  }
  if (ok(l))
    printf("%d\n", l);
  else if (ok(r))
    printf("%d\n", r);
  else
    printf("-1\n");
}
int main() {
  cin >> n >> m;
  memset(head, -1, sizeof head);
  cnt = 0;
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add_edge(u, v);
    add_edge(v, u);
  }
  cin >> w;
  gg.clear();
  for (int i = 0; i < w; i++) {
    int c, k, p;
    scanf("%d%d%d", &c, &k, &p);
    gg.push_back((Q){k, p, c});
  }
  sort(gg.begin(), gg.end());
  int q;
  cin >> q;
  while (q--) {
    scanf("%d%lld%lld", &s, &r, &cost);
    bfs();
  }
  return 0;
}
