#include <bits/stdc++.h>
using namespace std;
int N, M, W;
long long C[5001], K[5001], P[5001];
vector<pair<long long, long long>> stores[5001];
vector<int> adj[5001];
int dis[5001];
bool visited[5001];
multiset<pair<long long, long long>> mst;
long long tot, cnt;
int main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int X, Y;
    cin >> X >> Y;
    adj[X].push_back(Y);
    adj[Y].push_back(X);
  }
  cin >> W;
  for (int i = 0; i < W; i++) {
    cin >> C[i] >> K[i] >> P[i];
    stores[C[i]].push_back({P[i], K[i]});
  }
  int Q;
  cin >> Q;
  queue<int> q;
  while (Q--) {
    int G, R, A;
    int ans = 1001001001;
    cin >> G >> R >> A;
    for (int i = 1; i <= N; i++) {
      dis[i] = 1001001001;
      visited[i] = false;
    }
    tot = 0;
    cnt = 0;
    mst.clear();
    q.push(G);
    dis[G] = 0;
    visited[G] = true;
    while (!q.empty()) {
      int X = q.front();
      if (ans == 1001001001) {
        for (int i = 0; i < (int)stores[X].size(); i++) {
          cnt += stores[X][i].second;
          tot += stores[X][i].second * stores[X][i].first;
          mst.insert(stores[X][i]);
          if (cnt <= R)
            continue;
          else {
            while (cnt > R) {
              long long canDel = cnt - R;
              if (mst.rbegin()->second <= canDel) {
                cnt -= mst.rbegin()->second;
                tot -= mst.rbegin()->second * mst.rbegin()->first;
                mst.erase(mst.find(*mst.rbegin()));
              } else {
                cnt -= canDel;
                tot -= canDel * mst.rbegin()->first;
                int a = mst.rbegin()->first;
                int b = mst.rbegin()->second - canDel;
                mst.erase(mst.find(*mst.rbegin()));
                mst.insert({a, b});
              }
            }
          }
        }
        if (cnt == R && tot <= A) ans = dis[X];
      }
      q.pop();
      for (int Y : adj[X]) {
        if (!visited[Y]) {
          visited[Y] = true;
          dis[Y] = dis[X] + 1;
          q.push(Y);
        }
      }
    }
    if (ans == 1001001001)
      cout << -1 << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
