#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 1, -1, 0};
int dy[] = {1, 0, 0, -1};
long double PI = 3.14159265358979323846264338327950;
const int N = 5010, M = (N * (N - 1)) / 2;
int head[N];
int nxt[M], to[M], ne;
void init(int n) {
  memset(head, -1, sizeof head);
  ne = 0;
}
void addEdge(int f, int t) {
  nxt[ne] = head[f];
  to[ne] = t;
  head[f] = ne++;
}
void addBiEdge(int a, int b) {
  addEdge(a, b);
  addEdge(b, a);
}
struct stores {
  int loc;
  long long x, y;
  bool operator<(const stores& a) const { return y < a.y; }
} data[N];
int dist[N];
void bfs(int st) {
  memset(dist, 0x3f, sizeof dist);
  queue<int> q;
  q.push(st);
  dist[st] = 0;
  while (!q.empty()) {
    int Sz = (int)q.size();
    while (Sz--) {
      int cur = q.front();
      q.pop();
      for (int i = head[cur]; ~i; i = nxt[i]) {
        int nchild = to[i];
        if (dist[nchild] > dist[cur] + 1) {
          dist[nchild] = dist[cur] + 1;
          q.push(nchild);
        }
      }
    }
  }
}
int x;
long long g, r, a;
bool valid(int stps) {
  long long rr = r;
  long long aa = a;
  for (int i = 0; i < x && rr; i++) {
    if (dist[data[i].loc] > stps) continue;
    long long mn = min(rr, data[i].x);
    long long p = mn * data[i].y * 1LL;
    if (p > aa) break;
    aa -= p;
    rr -= mn;
  }
  return !rr;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  init(n);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    addBiEdge(--u, --v);
  }
  cin >> x;
  for (int i = 0; i < x; i++) {
    cin >> data[i].loc >> data[i].x >> data[i].y;
    data[i].loc--;
  }
  sort(data, data + x);
  int Q;
  cin >> Q;
  while (Q--) {
    cin >> g >> r >> a;
    g--;
    bfs(g);
    int st = 0, end = 1e5;
    while (st <= end) {
      int mid = (st + end) / 2;
      if (valid(mid))
        end = mid - 1;
      else
        st = mid + 1;
    }
    if (!valid(st))
      cout << "-1\n";
    else
      cout << st << "\n";
  }
  return 0;
}
