#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  register char c = getchar();
  x = 0;
  for (; c < '0' || c > '9'; c = getchar())
    ;
  for (; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + c - '0';
}
int n, d[5005][5005], x[5005], y[5005], z[5005], id[5005], pr = 0;
long long a[5005], c[5005];
vector<int> e[5005];
vector<pair<int, int> > f[5005];
queue<int> q;
inline bool cmp(int x, int y) { return z[x] < z[y]; }
bool check(int x, int r, long long aa, int t) {
  int i;
  for (i = 1; i <= pr; ++i) a[i] = 0;
  for (i = 1; i <= n; ++i)
    if (d[x][i] <= t)
      for (auto p : f[i]) a[p.first] += p.second;
  for (i = 1; i <= pr; ++i) {
    if (r > a[i]) {
      r -= a[i];
      aa -= c[i] * a[i];
      if (aa <= 0) return 0;
    } else {
      aa -= c[i] * r;
      r = 0;
      break;
    }
  }
  if (aa < 0 || r > 0)
    return 0;
  else
    return 1;
}
int main() {
  int m, i, j, k, l, r, h;
  read(n);
  read(m);
  while (m--) {
    read(i);
    read(j);
    e[i].push_back(j);
    e[j].push_back(i);
  }
  for (i = 1; i <= n; ++i) {
    for (j = 1; j <= n; ++j) d[i][j] = 1e9;
    d[i][i] = 0;
    q.push(i);
    while (!q.empty()) {
      h = q.front();
      q.pop();
      for (auto v : e[h])
        if (d[i][v] > d[i][h] + 1) {
          d[i][v] = d[i][h] + 1;
          q.push(v);
        }
    }
  }
  read(m);
  for (i = 1; i <= m; ++i) {
    read(x[i]);
    read(y[i]);
    read(z[i]);
    id[i] = i;
  }
  sort(id + 1, id + 1 + m, cmp);
  z[0] = -1;
  for (i = 1; i <= m; ++i) {
    if (z[id[i]] != z[id[i - 1]]) c[++pr] = z[id[i]];
    f[x[id[i]]].push_back(make_pair(pr, y[id[i]]));
  }
  read(m);
  while (m--) {
    read(i);
    read(j);
    read(k);
    l = 0;
    r = n;
    while (l <= r) {
      h = (l + r) / 2;
      if (check(i, j, (long long)k, h))
        r = h - 1;
      else
        l = h + 1;
    }
    if (l > n)
      printf("-1\n");
    else
      printf("%d\n", r + 1);
  }
}
