#include <bits/stdc++.h>
using namespace std;
const int N = 5000 + 5;
const long long oo = 1e16;
vector<int> adj[N];
pair<pair<int, int>, int> inf[N];
int n, m, w, d[N];
long long cost(int k, int dist) {
  long long res = 0;
  for (int i = 0; i < w && k > 0; i++) {
    int u = inf[i].second;
    int x = inf[i].first.first;
    int y = inf[i].first.second;
    if (d[u] <= dist && d[u] != -1)
      if (y <= k) {
        k -= y;
        res += 1LL * y * x;
      } else {
        res += 1LL * k * x;
        k = 0;
      }
  }
  if (k == 0)
    return res;
  else
    return oo;
}
void dfs(int u, int dist) {
  d[u] = dist;
  for (int j = 0; j < adj[u].size(); j++) {
    int v = adj[u][j];
    if (d[v] == -1) dfs(v, dist + 1);
  }
}
int main() {
  scanf("%d %d", &n, &m);
  int u, v;
  for (int z = 0; z < m; z++) {
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  int q, c, k, p;
  scanf("%d", &w);
  for (int z = 0; z < w; z++) {
    scanf("%d %d %d", &c, &k, &p);
    inf[z] = make_pair(make_pair(p, k), c);
  }
  sort(inf, inf + w);
  scanf("%d", &q);
  while (q--) {
    scanf("%d %d %d", &c, &k, &p);
    queue<int> q;
    q.push(c);
    memset(d, -1, sizeof d);
    d[c] = 0;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int j = 0; j < adj[u].size(); j++) {
        int v = adj[u][j];
        if (d[v] == -1) {
          d[v] = d[u] + 1;
          q.push(v);
        }
      }
    }
    int l = 0, r = n - 1;
    while (l < r) {
      int mid = (l + r) / 2;
      if (cost(k, mid) <= 1LL * p)
        r = mid;
      else
        l = mid + 1;
    }
    if (cost(k, l) > 1LL * p)
      printf("-1\n");
    else
      printf("%d\n", l);
  }
  return 0;
}
