#include <bits/stdc++.h>
using namespace std;
const int maxn = 5100;
struct Store {
  int num;
  long long p;
  int dis;
  Store() {}
  Store(int a, long long b) : num(a), p(b) {}
  Store(int a, long long b, int d) : num(a), p(b), dis(d) {}
  bool operator<(const Store &A) const { return p < A.p; }
};
int n;
vector<int> G[maxn];
vector<Store> d[maxn];
vector<Store> Qs;
queue<pair<int, int> > Q;
void BFS(int to);
bool used[maxn];
bool Buy(int num, long long limit, int r) {
  for (int i = 0; i < Qs.size(); i++)
    if (Qs[i].dis <= r) {
      int buy = min(Qs[i].num, num);
      if ((long long)limit - buy * Qs[i].p >= 0) {
        limit -= buy * Qs[i].p;
        num -= buy;
      } else
        return false;
    }
  return num == 0;
}
int main() {
  int m;
  while (scanf("%d%d", &n, &m) == 2) {
    Qs.clear();
    for (int i = 0; i < n; i++) G[i].clear(), d[i].clear();
    for (int i = 0, a, b; i < m; i++) {
      scanf("%d%d", &a, &b);
      G[a].push_back(b);
      G[b].push_back(a);
    }
    int w;
    scanf("%d", &w);
    long long c;
    for (int i = 0, a, b; i < w; i++) {
      scanf("%d%d%I64d", &a, &b, &c);
      d[a].push_back(Store(b, c));
    }
    int QQ, ans = -1;
    scanf("%d", &QQ);
    for (int i = 0; i < QQ; i++) {
      int to, num;
      long long p;
      ans = -1;
      scanf("%d%d%I64d", &to, &num, &p);
      BFS(to);
      sort(Qs.begin(), Qs.end());
      int l = 0, r = n;
      while (l <= r) {
        int mid = (l + r) >> 1;
        if (Buy(num, p, mid)) {
          ans = mid;
          r = mid - 1;
        } else
          l = mid + 1;
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
void BFS(int to) {
  for (int i = 0; i <= n; i++) used[i] = 0;
  Qs.clear();
  while (!Q.empty()) Q.pop();
  for (int j = 0; j < d[to].size(); j++) Qs.push_back(d[to][j]);
  Q.push(make_pair(to, 0));
  used[to] = 1;
  while (!Q.empty()) {
    pair<int, int> x = Q.front();
    Q.pop();
    for (int j = 0; j < G[x.first].size(); j++) {
      int next = G[x.first][j];
      if (used[next]) continue;
      used[next] = 1;
      for (int k = 0; k < d[next].size(); k++)
        Qs.push_back(Store(d[next][k].num, d[next][k].p, x.second + 1));
      Q.push(make_pair(next, x.second + 1));
    }
  }
}
