#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 1;
const int N = 5003;
vector<int> adj[N];
vector<pair<int, int> > stores[N];
bool done[N];
int dist[N];
void clear(int n) {
  for (int i = 1; i <= n; ++i) done[i] = 0;
}
void modify(multiset<pair<int, int> >& tiendas, const int& to,
            long long& rpta) {
  for (pair<int, int> p : stores[to]) {
    auto it = tiendas.rbegin();
    pair<int, int> q = *it;
    int left = p.second;
    while (!tiendas.empty() && q.first > p.first) {
      if (q.second >= left) {
        tiendas.erase(tiendas.find(q));
        rpta -= ((long long)q.first * q.second);
        if (q.second != left) {
          tiendas.insert({q.first, q.second - left});
          rpta += ((long long)q.first * (q.second - left));
        }
        left = 0;
        break;
      } else {
        tiendas.erase(tiendas.find(q));
        left -= q.second;
        rpta -= ((long long)q.first * q.second);
      }
      if (!tiendas.empty()) {
        it = tiendas.rbegin();
        q = *it;
      }
    }
    if (p.second != left) {
      tiendas.insert({p.first, p.second - left});
      rpta += ((long long)p.first * (p.second - left));
    }
  }
  return;
}
int bfs(int source, int prod, long long price) {
  multiset<pair<int, int> > tiendas;
  tiendas.insert({INF, prod});
  long long rpta = (long long)INF * prod;
  queue<int> Q;
  Q.push(source);
  dist[source] = 0;
  done[source] = 1;
  modify(tiendas, source, rpta);
  if (rpta <= price) return dist[source];
  while (!Q.empty()) {
    int from = Q.front();
    Q.pop();
    for (int to : adj[from]) {
      if (done[to]) continue;
      dist[to] = dist[from] + 1;
      done[to] = 1;
      Q.push(to);
      modify(tiendas, to, rpta);
      if (rpta <= price) return dist[to];
    }
  }
  return -1;
}
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  int w;
  cin >> w;
  for (int i = 0; i < w; ++i) {
    int c, k, p;
    cin >> c >> k >> p;
    stores[c].push_back({p, k});
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    clear(n);
    int g, r, a;
    cin >> g >> r >> a;
    cout << bfs(g, r, a) << '\n';
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  solve();
  return 0;
}
