#include <bits/stdc++.h>
using namespace std;
const int N = 5010 + 10, M = 200000 + 10;
const int inf = 0x3f3f3f3f;
inline int Max(int a, int b) { return a >= b ? a : b; }
inline long long Min(long long a, long long b) { return a >= b ? b : a; }
int head[N], ver[N << 1], Next[N << 1], tot;
void add(int x, int y) {
  ver[++tot] = y;
  Next[tot] = head[x];
  head[x] = tot;
}
int n, m, w;
int g;
long long r, a;
struct node {
  int c;
  long long k, p;
} b[N];
bool cmp(struct node &a, struct node &b) { return a.p < b.p; }
int dis[N];
bool vis[N];
bool check(int mid) {
  long long num = 0, tmp = a;
  for (int i = 1; i <= w; i++) {
    if (dis[b[i].c] <= mid) {
      long long x = tmp / (b[i].p);
      x = Min(x, b[i].k);
      num += x;
      if (num >= r) return true;
      tmp -= x * (b[i].p);
    }
  }
  return false;
}
int djs(int s) {
  for (int i = 1; i <= n; i++) dis[i] = inf, vis[i] = false;
  dis[s] = 0;
  vis[s] = true;
  queue<int> q;
  q.push(s);
  int L = 0, R = 0;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    R = max(R, dis[x]);
    for (int i = head[x]; i; i = Next[i]) {
      int y = ver[i];
      if (vis[y]) continue;
      dis[y] = dis[x] + 1;
      vis[y] = true;
      q.push(y);
    }
  }
  int res = -1;
  while (L <= R) {
    int mid = L + R >> 1;
    if (check(mid)) {
      R = mid - 1;
      res = mid;
    } else
      L = mid + 1;
  }
  return res;
}
void gan() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    add(x, y), add(y, x);
  }
  scanf("%d", &w);
  for (int i = 1; i <= w; i++) {
    scanf("%d %lld %lld", &b[i].c, &b[i].k, &b[i].p);
  }
  sort(b + 1, b + 1 + w, cmp);
  int q;
  scanf("%d", &q);
  while (q--) {
    scanf("%d %lld %lld", &g, &r, &a);
    printf("%d\n", djs(g));
  }
}
int main() {
  int T = 1;
  while (T--) {
    gan();
  }
}
