#include <bits/stdc++.h>
using namespace std;
const int maxn = 5050;
const int maxm = 5050;
const int maxw = 5050;
struct Edge {
  int to;
  Edge* nxt;
};
struct Store {
  int pos;
  int price;
  int num;
  bool operator<(const Store& b) const { return price < b.price; }
};
Edge pool[maxn * 3];
int pt = 0;
Edge* newEdge(int to) {
  Edge* t = &pool[pt++];
  t->to = to;
  return t;
}
int n;
int m;
int w;
int qn;
Edge* e[maxn] = {0};
Store s[maxw];
void addEdge(int f, int t) {
  Edge* a = newEdge(t);
  a->nxt = e[f];
  e[f] = a;
  Edge* b = newEdge(f);
  b->nxt = e[t];
  e[t] = b;
}
int dis[maxn][maxn] = {{0}};
bool cal[maxn] = {false};
queue<int> q;
void bfs(int pos) {
  dis[pos][pos] = 0;
  q.push(pos);
  while (!q.empty()) {
    int t = q.front();
    q.pop();
    for (Edge* it = e[t]; it != NULL; it = it->nxt) {
      if (t != it->to && (dis[pos][it->to] == 0 && pos != it->to)) {
        q.push(it->to);
        dis[pos][it->to] = dis[pos][t] + 1;
      }
    }
  }
}
int qpos, qnum, qprice;
bool ok(int t) {
  int r = qprice;
  int hn = 0;
  for (int i = 0; i < w; i++) {
    if (r < s[i].price) break;
    if (dis[qpos][s[i].pos] <= t &&
        (qpos == s[i].pos || dis[qpos][s[i].pos] != 0)) {
      int cn = min(s[i].num, r / s[i].price);
      hn += cn;
      r -= s[i].price * cn;
    }
  }
  if (hn >= qnum) return true;
  return false;
}
int findans(int l, int r) {
  if (l == r) {
    if (ok(l))
      return l;
    else
      return -1;
  }
  if (r == l + 1) {
    if (ok(l))
      return l;
    else if (ok(r))
      return r;
    else
      return -1;
  }
  int m = (l + r) >> 1;
  if (ok(m))
    return findans(l, m);
  else
    return findans(m + 1, r);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int f, t;
    scanf("%d%d", &f, &t);
    addEdge(f, t);
  }
  scanf("%d", &w);
  for (int i = 0; i < w; i++) {
    int pos, num, price;
    scanf("%d%d%d", &pos, &num, &price);
    s[i].pos = pos;
    s[i].num = num;
    s[i].price = price;
  }
  sort(s, s + w);
  scanf("%d", &qn);
  for (int i = 0; i < qn; i++) {
    scanf("%d%d%d", &qpos, &qnum, &qprice);
    if (!cal[qpos]) {
      bfs(qpos);
      cal[qpos] = true;
    }
    printf("%d\n", findans(0, n));
  }
  return 0;
}
