#include <bits/stdc++.h>
using namespace std;
int n, i, j, m, Q, first[10001], Next[20001], to[20001], size;
int c[10001], k[10001], p[10001];
int d[10001], s[10001], sfzd[5001];
int t1, t2, tt;
struct A {
  int jz, sl, wz;
} b[5001];
bool cmp(A x, A y) { return x.jz < y.jz; }
void insert(int x, int y) {
  Next[++size] = first[x];
  first[x] = size;
  to[size] = y;
}
void bfs(int x) {
  int tou = 0, wei = 1;
  memset(sfzd, 0, sizeof(sfzd));
  memset(s, 63, sizeof(s));
  d[1] = x;
  sfzd[x] = 1;
  s[x] = 0;
  while (tou < wei) {
    tou++;
    int u = d[tou];
    for (int i = first[u]; i; i = Next[i]) {
      int v = to[i];
      if (!sfzd[v]) {
        d[++wei] = v;
        s[v] = s[u] + 1;
        sfzd[v] = 1;
      }
    }
  }
}
bool check(int y) {
  int sum = 0;
  long long cost = 0;
  for (int i = 1; i <= m && sum < t2; i++)
    if (s[b[i].wz] <= y) {
      if (sum + b[i].sl <= t2) {
        sum += b[i].sl;
        cost += 1ll * b[i].sl * b[i].jz * 1ll;
      } else {
        cost += (1ll * t2 - sum * 1ll) * b[i].jz * 1ll;
        sum = t2;
      }
      if (cost > tt) return false;
    }
  if (sum < t2) return false;
  return true;
}
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &t1, &t2);
    insert(t1, t2);
    insert(t2, t1);
  }
  scanf("%d", &m);
  for (i = 1; i <= m; i++) scanf("%d%d%d", &b[i].wz, &b[i].sl, &b[i].jz);
  sort(b + 1, b + m + 1, cmp);
  scanf("%d", &Q);
  while (Q--) {
    scanf("%d%d%d", &t1, &t2, &tt);
    int l = -1, r = n;
    bfs(t1);
    while (r - l > 1) {
      int mid = (l + r) >> 1;
      if (check(mid))
        r = mid;
      else
        l = mid;
    }
    if (check(r))
      printf("%d\n", r);
    else
      printf("-1\n");
  }
}
