#include <bits/stdc++.h>
using namespace std;
int dist[5051][5051];
int n, m;
struct D {
  int c, k, p;
  D() {}
  void in() { scanf("%d%d%d", &c, &k, &p); }
};
vector<D> store[5051];
vector<int> nxt[5051];
vector<int> ord[5051];
int q[5051], top, tail;
void DF(int u, int val) {
  top = tail = 0;
  q[top++] = u;
  dist[u][u] = 0;
  while (top > tail) {
    int v = q[tail++];
    for (int i = 0; i < nxt[v].size(); i++) {
      int tar = nxt[v][i];
      if (dist[u][tar] == -1) {
        dist[u][tar] = dist[u][v] + 1;
        q[top++] = tar;
      }
    }
  }
}
multiset<pair<long long, long long> > S;
pair<int, pair<int, int> > V[5001];
bool ok(long long cursum, int tar) {
  if (S.size() == 0) return false;
  pair<long long, long long> Z = *S.begin();
  return (cursum - Z.second >= tar);
}
void solve() {
  int x, r, price;
  scanf("%d%d%d", &x, &r, &price);
  S.clear();
  int h = 0;
  for (int i = 1; i <= n; i++)
    if (dist[i][x] != -1 && store[i].size() > 0) {
      for (int j = 0; j <= store[i].size() - 1; j++) {
        D DAT = store[i][j];
        h++;
        V[h] = make_pair(dist[i][x], make_pair(DAT.p, DAT.k));
      }
    }
  sort(V + 1, V + h + 1);
  long long tot = 0;
  long long totprice = 0;
  for (int i = 1; i <= h; i++) {
    tot += V[i].second.second;
    totprice += (long long)V[i].second.first * V[i].second.second;
    V[i].second.first *= -1;
    pair<long long, long long> Y;
    Y.first = (long long)V[i].second.first;
    Y.second = (long long)V[i].second.second;
    S.insert(Y);
    while (ok(tot, r)) {
      pair<long long, long long> Z = *S.begin();
      S.erase(S.begin());
      tot -= Z.second;
      totprice += Z.first * Z.second;
    }
    if (tot >= r) {
      long long realprice = totprice + (tot - r) * ((*(S.begin())).first);
      if (realprice <= price) {
        printf("%d\n", V[i].first);
        return;
      }
    }
  }
  printf("-1\n");
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int s, t;
    scanf("%d%d", &s, &t);
    nxt[s].push_back(t);
    nxt[t].push_back(s);
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) dist[i][j] = -1;
  for (int i = 1; i <= n; i++) {
    DF(i, 0);
  }
  int q;
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    D W;
    W.in();
    store[W.c].push_back(W);
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    solve();
  }
}
