#include <bits/stdc++.h>
using namespace std;
const long long inf = 1000000007;
int N, M, W, Q, dist[5005][5005];
vector<pair<pair<int, int>, int> > store;
vector<int> adj[5005];
void bfs(int src) {
  queue<int> que;
  dist[src][src] = 0;
  que.push(src);
  while (!que.empty()) {
    int nd = que.front();
    que.pop();
    for (int i = 0; i < (adj[nd].size()); i++) {
      int ch = adj[nd][i];
      if (dist[src][nd] + 1 < dist[src][ch]) {
        dist[src][ch] = dist[src][nd] + 1;
        que.push(ch);
      }
    }
  }
}
long long cost(int src, int d, int tk) {
  long long cst = 0;
  for (int i = 0; i < (store.size()); i++)
    if (dist[src][store[i].second] <= d) {
      cst += (long long)store[i].first.first * min(store[i].first.second, tk);
      tk -= min(store[i].first.second, tk);
    }
  if (tk) return inf;
  return cst;
}
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < (M); i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  scanf("%d", &W);
  for (int i = 0; i < (W); i++) {
    int c, k, p;
    scanf("%d%d", &c, &k);
    scanf("%d", &p);
    store.push_back(make_pair(make_pair(p, k), c));
  }
  sort(store.begin(), store.end());
  memset(dist, 63, sizeof(dist));
  for (int i = (1); i < (N + 1); i++) bfs(i);
  scanf("%d", &Q);
  while (Q--) {
    int g, r, a;
    scanf("%d", &g);
    scanf("%d%d", &r, &a);
    if (cost(g, N, r) > a) {
      puts("-1");
      continue;
    }
    int lo = -1, hi = N - 1;
    while (lo + 1 < hi) {
      int mid = (lo + hi) >> 1;
      if (cost(g, mid, r) <= a)
        hi = mid;
      else
        lo = mid;
    }
    printf("%d\n", hi);
  }
  return 0;
}
