#include <bits/stdc++.h>
using namespace std;
template <class T>
int getBit(T x, int k) {
  return x >> k & 1;
}
template <class T>
T onBit(T x, int k) {
  return x(T(1) << k);
}
template <class T>
T offBit(T x, int k) {
  return x & (~(T(1) << k));
}
template <class T>
bool read(T &x) {
  x = 0;
  char c;
  bool nega = 0;
  while (!isdigit(c = getchar()) && c != '-' && c != EOF)
    ;
  if (c == EOF) return 0;
  if (c == '-') nega = 1, c = getchar();
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  if (nega) x = -x;
  return 1;
}
template <class T>
void wri(T x) {
  if (x / 10) wri(x / 10);
  putchar(x % 10 + '0');
}
template <class T>
void write(T x) {
  if (x < 0) putchar('-'), x = -x;
  wri(x);
}
template <class T>
void writeln(T x) {
  write(x);
  putchar('\n');
}
const int maxn = 5555;
struct node {
  int id, num, cost;
  node(int id, int num, int cost) : id(id), num(num), cost(cost) {}
  bool operator<(const node &p) const { return cost < p.cost; }
};
int n, m, w, q;
int dist[maxn][maxn];
vector<node> stores;
vector<int> adj[maxn];
void load() {
  read(n);
  read(m);
  while (m--) {
    int u, v;
    read(u);
    read(v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  read(w);
  for (int i = 1; i <= w; ++i) {
    int c, k, p;
    read(c);
    read(k);
    read(p);
    stores.push_back(node(c, k, p));
  }
}
void bfs(int u, int d[]) {
  queue<int> q;
  q.push(u);
  d[u] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int v : adj[u])
      if (d[v] >= 1000000007LL) {
        d[v] = d[u] + 1;
        q.push(v);
      }
  }
}
int ok(int u, int need, int maxdist) {
  long long cost = 0;
  for (int i = 0; i < w; ++i) {
    int v = stores[i].id, price = stores[i].cost, have = stores[i].num;
    if (dist[u][v] > maxdist) continue;
    have = min(have, need);
    cost += 1ll * have * price;
    need -= have;
  }
  return need > 0 ? 1000000007LL : min(cost, 1000000007LL);
}
void process() {
  memset(dist, 0x3f, sizeof dist);
  sort(stores.begin(), stores.end());
  for (int i = 1; i <= n; ++i) bfs(i, dist[i]);
  read(q);
  while (q--) {
    int u, need, have;
    read(u);
    read(need);
    read(have);
    int l = 0, r = n, ans = -1;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (ok(u, need, mid) <= have) {
        ans = mid;
        r = mid - 1;
      } else {
        l = mid + 1;
      }
    }
    writeln(ans);
  }
}
int main() {
  load();
  process();
  return 0;
}
