#include <bits/stdc++.h>
using namespace std;
struct store {
  long long k, p, c;
  store() {}
  store(long long k, long long p, long long c) : k(k), p(p), c(c) {}
};
bool operator<(const store& a, const store& b) { return a.p < b.p; }
bool is_fit(vector<store>& stores,
            vector<pair<long long, long long>>& distances, long long ind,
            long long r, long long a, vector<long long>& distC) {
  int i;
  for (i = 0; i < stores.size() && r > 0 && a >= 0; ++i) {
    if (distC[stores[i].c] <= distances[ind].first) {
      r -= stores[i].k;
      a -= stores[i].p * stores[i].k;
    }
  }
  --i;
  if (r <= 0)
    if ((a += abs(r) * stores[i].p) >= 0) return true;
  return false;
}
int main() {
  long long n, m;
  cin >> n >> m;
  vector<vector<long long>> cities(n);
  for (int i = 0; i < m; ++i) {
    int e, v;
    cin >> e >> v;
    --e;
    --v;
    cities[e].push_back(v);
    cities[v].push_back(e);
  }
  long long w;
  cin >> w;
  vector<store> stores(w);
  for (int i = 0; i < w; ++i) {
    int c, k, p;
    cin >> c >> k >> p;
    --c;
    stores[i] = store(k, p, c);
  }
  sort(stores.begin(), stores.end());
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    long long g, r, a;
    cin >> g >> r >> a;
    --g;
    vector<char> visited(n);
    vector<pair<long long, long long>> distances;
    vector<long long> distC(n, 999999999);
    queue<pair<long long, long long>> que;
    que.push(make_pair(g, 0));
    int max_dist = 0;
    while (!que.empty()) {
      auto ind = que.front();
      max_dist = max_dist < ind.second ? ind.second : max_dist;
      distances.emplace_back(ind.second, ind.first);
      distC[ind.first] = ind.second;
      que.pop();
      visited[ind.first] = 1;
      for (int j = 0; j < cities[ind.first].size(); ++j) {
        if (!visited[cities[ind.first][j]]) {
          que.push(make_pair(cities[ind.first][j], ind.second + 1));
          visited[cities[ind.first][j]] = 1;
        }
      }
    }
    long long l = 0, right = distances.size();
    while (l < right) {
      long long mid = l + (right - l) / 2;
      if (is_fit(stores, distances, mid, r, a, distC)) {
        right = mid;
      } else {
        l = mid + 1;
      }
    }
    if (l == right) {
      if (l == distances.size()) {
        cout << -1 << endl;
      } else {
        cout << distances[l].first << endl;
      }
    } else {
      cout << -1 << endl;
    }
  }
  return 0;
}
