#include <bits/stdc++.h>
using namespace std;
void OF() {
  freopen(
      "f"
      ".inp",
      "r", stdin);
  freopen(
      "f"
      ".out",
      "w", stdout);
}
const long long maxn = 5e3 + 7;
long long n, nstr, minP[maxn][maxn] = {{0}};
vector<long long> g[maxn], bfs[maxn];
vector<pair<long long, long long> > str[maxn];
void initG() {
  long long m;
  cin >> n >> m;
  long long u, v;
  while (m--) {
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
}
void initStr() {
  long long a, b, c;
  cin >> nstr;
  for (long long i = 1; i <= nstr; ++i) {
    cin >> a >> b >> c;
    str[a].emplace_back(c, b);
  }
}
void initBfs(long long r, vector<long long> &x) {
  vector<bool> ck(n + 1, 0);
  x.push_back(r);
  ck[r] = 1;
  for (long long i = 0; i <= x.size() - 1; ++i) {
    long long u = x[i];
    for (long long &v : g[u])
      if (!ck[v]) {
        ck[v] = 1, minP[r][v] = minP[r][u] + 1;
        x.push_back(v);
      }
  }
}
long long b, t, r;
void mg(pair<long long, long long> s,
        priority_queue<pair<long long, long long> > &q, long long const &need,
        long long const &tt) {
  long long tmp = min(need - b, s.second);
  q.push({s.first, tmp});
  b += tmp;
  t += tmp * s.first;
}
long long sol(long long pos, long long need, long long tt) {
  long long i = 0;
  priority_queue<pair<long long, long long> > q;
  b = 0, t = 0, r = pos;
  for (; i < bfs[pos].size() && (b < need || t > tt); ++i) {
    for (pair<long long, long long> j : str[bfs[pos][i]]) {
      while (q.size() && j.first < q.top().first &&
             (b - q.top().second) + j.second >= need) {
        b -= q.top().second, t -= q.top().second * q.top().first;
        q.pop();
      }
      if (q.empty() || j.first >= q.top().first) {
        mg(j, q, need, tt);
      } else {
        pair<long long, long long> tmp = q.top();
        q.pop();
        b -= tmp.second;
        t -= tmp.first * tmp.second;
        if (tmp > j) swap(tmp, j);
        mg(tmp, q, need, tt);
        mg(j, q, need, tt);
      }
    }
  }
  if (b < need || t > tt) return -1;
  return minP[pos][bfs[pos][i - 1]];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  initG();
  initStr();
  for (long long i = 1; i <= n; ++i) initBfs(i, bfs[i]);
  long long tcs, pos, need, mn;
  cin >> tcs;
  while (tcs--) {
    cin >> pos >> need >> mn;
    cout << sol(pos, need, mn) << '\n';
  }
}
