#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int next, to;
} a[1300005];
struct List {
  long long num, pri;
  int pos;
  bool operator<(const List& l) const { return pri < l.pri; }
};
int n, m, k, q, cnt, js, h[5005];
int que[5005];
multiset<List> ss;
int vis[5005];
int dis[5005][5005];
void Addedge(int x, int y) {
  a[++cnt].to = y;
  a[cnt].next = h[x];
  h[x] = cnt;
}
void Query(int st, long long ttn, long long ttp) {
  js++;
  que[1] = st;
  vis[st] = js;
  int l = 0, r = 1, now = 0;
  while (l < r) {
    now++;
    int x = que[++l];
    for (int i = h[x]; i; i = a[i].next) {
      int y = a[i].to;
      if (vis[y] == js) continue;
      if (dis[st][y] > dis[st][x] + 1) dis[st][y] = dis[st][x] + 1;
      que[++r] = y;
      vis[y] = js;
    }
  }
  l = 0, r = n;
  bool flag = 0;
  while (l < r) {
    int mid = (l + r) >> 1;
    long long nm = 0, sm = 0;
    for (multiset<List>::iterator ite = ss.begin(); ite != ss.end(); ite++)
      if (dis[st][ite->pos] <= mid) {
        if (nm + ite->num >= ttn) {
          sm += (ttn - nm) * (ite->pri);
          nm = ttn;
          break;
        }
        nm += ite->num;
        sm += (ite->num) * (ite->pri);
        if (sm > ttp) break;
      }
    if (sm <= ttp && nm >= ttn) {
      r = mid;
      flag = 1;
    } else
      l = mid + 1;
  }
  if (flag)
    printf("%d\n", l);
  else
    puts("-1");
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, x, y; i <= m; i++) {
    scanf("%d%d", &x, &y);
    Addedge(x, y);
    Addedge(y, x);
  }
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) dis[i][j] = dis[j][i] = 1 << 29;
  scanf("%d", &k);
  for (int i = 1, x; i <= k; i++) {
    List temp;
    scanf("%d%I64d%I64d", &temp.pos, &temp.num, &temp.pri);
    ss.insert(temp);
  }
  scanf("%d", &q);
  for (int i = 1, x; i <= q; i++) {
    long long y, z;
    scanf("%d%I64d%I64d", &x, &y, &z);
    Query(x, y, z);
  }
}
