#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void chkmax(T& x, U y) {
  if (x < y) x = y;
}
template <typename T, typename U>
inline void chkmin(T& x, U y) {
  if (y < x) x = y;
}
int n, m, C;
long long ret;
set<int> S;
const int MAXN = 222222;
int cnt[MAXN], val[MAXN], cst[MAXN], q[MAXN], dis[MAXN];
vector<int> adj[MAXN], con[MAXN];
void process(int k) {
  int temp = cnt[k];
  if (C > 0) {
    int cur = min(C, temp);
    ret += (long long)cur * cst[k];
    S.insert(-cst[k]);
    val[cst[k]] += cur;
    C -= cur;
    temp -= cur;
  }
  if (C == 0) {
    while (!S.empty() && temp) {
      set<int>::iterator it = S.begin();
      int ccst = -(*it);
      if (cst[k] >= ccst) break;
      int cur = min(temp, val[ccst]);
      ret += (long long)cur * (cst[k] - ccst);
      val[ccst] -= cur;
      if (val[ccst] == 0) S.erase(it);
      S.insert(-cst[k]);
      val[cst[k]] += cur, temp -= cur;
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    adj[u].push_back(v), adj[v].push_back(u);
  }
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int u;
    scanf("%d%d%d", &u, &cnt[i], &cst[i]);
    con[u].push_back(i);
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int s, L;
    scanf("%d%d%d", &s, &C, &L);
    S.clear();
    for (int j = 1; j <= m; j++) val[cst[j]] = 0;
    for (int j = 1; j <= n; j++) dis[j] = -1;
    int h = 0, t = 0;
    q[t++] = s;
    dis[s] = 0;
    ret = 0;
    bool found = 0;
    while (h < t) {
      int u = q[h++];
      for (int j = 0; j < con[u].size(); j++) process(con[u][j]);
      if (!C && ret <= L) {
        printf("%d\n", dis[u]);
        found = 1;
        break;
      }
      for (int j = 0; j < adj[u].size(); j++) {
        int v = adj[u][j];
        if (!~dis[v]) {
          dis[v] = dis[u] + 1;
          q[t++] = v;
        }
      }
    }
    if (!found) puts("-1");
  }
  return 0;
}
