#include <bits/stdc++.h>
const int MAXN = 5111;
const int MAXM = 5111;
struct Store {
  int city, amount, price;
  Store(int city = 0, int amount = 0, int price = 0)
      : city(city), amount(amount), price(price) {}
};
std::vector<Store> store;
std::vector<int> edge[MAXN];
int dist[MAXN][MAXN];
void bfs(int n, int start, int dist[]) {
  for (int i = 1; i <= n; ++i) {
    dist[i] = INT_MAX;
  }
  std::queue<int> que;
  que.push(start);
  dist[start] = 0;
  while (!que.empty()) {
    int x = que.front();
    que.pop();
    for (auto to : edge[x]) {
      if (dist[to] > dist[x] + 1) {
        dist[to] = dist[x] + 1;
        que.push(to);
      }
    }
  }
}
int deliver(int city, int limit, int cc, int budget) {
  for (auto pp : store) {
    int time = dist[city][pp.city];
    int amount = pp.amount;
    int price = pp.price;
    if (time <= limit) {
      int cons = std::min(cc, amount);
      if (budget / price < cons) {
        return false;
      }
      budget -= price * cons;
      cc -= cons;
      if (cc == 0) {
        break;
      }
    }
  }
  return cc == 0;
}
int bin_search(int n, int city, int cc, int budget) {
  int l = 0, r = n;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (!deliver(city, mid, cc, budget)) {
      l = mid + 1;
    } else {
      r = mid;
    }
  }
  if (!deliver(city, l, cc, budget)) {
    return -1;
  }
  return l;
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    edge[x].push_back(y);
    edge[y].push_back(x);
  }
  int w;
  scanf("%d", &w);
  for (int i = 0; i < w; ++i) {
    int c, k, p;
    scanf("%d %d %d", &c, &k, &p);
    store.push_back({c, k, p});
  }
  for (int i = 1; i <= n; ++i) {
    bfs(n, i, dist[i]);
  }
  sort(store.begin(), store.end(), [](const Store &a, const Store &b) -> bool {
    return a.price < b.price;
  });
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    int g, r, a;
    scanf("%d %d %d", &g, &r, &a);
    int t = bin_search(n, g, r, a);
    printf("%d\n", t);
  }
  return 0;
}
