#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
int n, m, w, q;
int dis[N][N], a, g, r, c[N], k[N], p[N], t[N];
vector<int> G[N];
struct Path {
  int u, c;
  Path(int u = 0, int c = 0) : u(u), c(c) {}
  bool operator<(const Path& p) const { return c > p.c; }
};
void dijkstra() {
  for (int s = 1; s <= n; s++) {
    memset(dis[s], 0x3f, sizeof(int) * (n + 1));
    dis[s][s] = 0;
    queue<Path> Q;
    Q.push(Path(s, dis[s][s]));
    while (!Q.empty()) {
      int u = Q.front().u;
      int c = Q.front().c;
      Q.pop();
      if (dis[s][u] < c) continue;
      for (auto v : G[u]) {
        if (dis[s][v] > dis[s][u] + 1) {
          dis[s][v] = dis[s][u] + 1;
          Q.push(Path(v, dis[s][v]));
        }
      }
    }
  }
}
bool check(int dist) {
  vector<pair<int, int> > v;
  for (int i = 0; i < w; i++) {
    int cur = t[i];
    if (dis[g][c[cur]] <= dist) {
      v.emplace_back(p[cur], k[cur]);
    }
  }
  int rest = a, count = 0;
  for (int i = 0; i < v.size(); i++) {
    int temp = min(v[i].second, rest / v[i].first);
    rest -= 1LL * temp * v[i].first;
    count += temp;
    if (count >= r) return true;
    if (rest <= 0) break;
  }
  return false;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0, u, v; i < m; i++) {
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dijkstra();
  scanf("%d", &w);
  for (int i = 0; i < w; i++) {
    scanf("%d%d%d", &c[i], &k[i], &p[i]);
    t[i] = i;
  }
  sort(t, t + w, [&](int x, int y) { return p[x] < p[y]; });
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d%d", &g, &r, &a);
    int l = 0, r = n, ans = -1;
    while (l <= r) {
      int mid = (l + r) / 2;
      if (check(mid)) {
        r = mid - 1;
        ans = mid;
      } else {
        l = mid + 1;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
