#include <bits/stdc++.h>
using namespace std;
const int inf = 1e6;
struct lopata {
  int nod, nr, p;
  const bool operator<(const lopata& that) const { return p < that.p; };
};
class graph {
 public:
  int n, m, w;
  vector<vector<int>> g, d;
  vector<lopata> lopeti;
  graph(int n = 0, int m = 0, int w = 0) : n(n), m(m), w(w) {
    g.resize(n);
    d.resize(n, vector<int>(n, inf));
  }
  void add(int x, int y) {
    g[x].push_back(y);
    g[y].push_back(x);
  }
  void bfs(int nod) {
    queue<int> q;
    d[nod][nod] = 0;
    q.push(nod);
    while (!q.empty()) {
      auto who = q.front();
      q.pop();
      for (auto i : g[who]) {
        if (d[nod][i] != inf) {
          continue;
        }
        d[nod][i] = d[nod][who] + 1;
        q.push(i);
      }
    }
  }
  bool can(int node, int need, int cmax, int dist) {
    long long sum = 0;
    int have = 0;
    for (auto i : lopeti) {
      int town = i.nod;
      if (d[node][town] > dist) {
        continue;
      }
      int pot_lua = min(i.nr, need - have);
      pot_lua = min(pot_lua, cmax / i.p);
      if (pot_lua <= 0) {
        continue;
      }
      have += pot_lua;
      sum += 1LL * pot_lua * i.p;
    }
    return (have == need && sum <= cmax);
  }
  void bfall() {
    for (int i = 0; i < n; ++i) {
      bfs(i);
    }
  }
};
int32_t main() {
  int n, m, w;
  ios::sync_with_stdio(0);
  cin >> n >> m;
  graph g(n, m, 0);
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    g.add(x, y);
  }
  cin >> w;
  g.w = w;
  for (int i = 0; i < w; ++i) {
    int nod, nr, p;
    cin >> nod >> nr >> p;
    nod--;
    g.lopeti.push_back(lopata{nod, nr, p});
  }
  sort(g.lopeti.begin(), g.lopeti.end());
  int q;
  cin >> q;
  g.bfall();
  for (; q > 0; --q) {
    int to, need, cmax;
    cin >> to >> need >> cmax;
    to--;
    int st = 0, dr = n, ans = -1;
    while (st <= dr) {
      int mi = (st + dr) >> 1;
      if (g.can(to, need, cmax, mi)) {
        ans = mi, dr = mi - 1;
      } else {
        st = mi + 1;
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
