#include <bits/stdc++.h>
using namespace std;
void test() { cerr << "\n"; }
template <typename T, typename... Args>
void test(T x, Args... args) {
  cerr << x << " ";
  test(args...);
}
const int MAXN = (int)1e5 + 5;
const int MOD = (int)1e9 + 7;
vector<int> ve[5005];
struct node {
  int c, k, p;
};
vector<node> ths;
bool vis[5005];
queue<pair<int, int> > q;
int dis[5005];
int n, m;
void bfs(int s) {
  fill_n(vis + 1, n, 0);
  fill_n(dis + 1, n, 5005);
  q.push({s, 0});
  vis[s] = 1;
  while (!q.empty()) {
    int u = q.front().first, d = q.front().second;
    q.pop();
    dis[u] = d;
    for (auto v : ve[u]) {
      if (!vis[v]) {
        vis[v] = 1;
        q.push({v, d + 1});
      }
    }
  }
}
bool check(int num, int cost, int x) {
  long long tot = 0;
  for (auto th : ths) {
    if (dis[th.c] <= x) {
      int de = min(num, th.k);
      tot += 1ll * de * th.p;
      num -= de;
      if (!num) break;
      if (tot > cost) break;
    }
  }
  return num == 0 && cost >= tot;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    ve[u].push_back(v);
    ve[v].push_back(u);
  }
  int w;
  cin >> w;
  for (int i = 1; i <= w; i++) {
    int c, k, p;
    cin >> c >> k >> p;
    ths.push_back({c, k, p});
  }
  sort(ths.begin(), ths.end(),
       [](const node &a, const node &b) { return a.p < b.p; });
  int q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int ct, num, cost;
    cin >> ct >> num >> cost;
    int l = 0, r = n, ans = -1;
    bfs(ct);
    while (l <= r) {
      int mid = (l + r) / 2;
      if (check(num, cost, mid)) {
        ans = mid;
        r = mid - 1;
      } else
        l = mid + 1;
    }
    cout << ans << "\n";
  }
  return 0;
}
