#include <bits/stdc++.h>
using namespace std;
const int inf = 0x20202020;
const long long mod = 1000000007;
const double eps = 1e-9;
const double pi = acos(-1);
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
const int N = 5000;
int n, m;
vector<int> g[N + 5];
int dep[N + 5];
struct node {
  int city, num, price;
  node() {}
  node(int _c, int _n, int _p) : city(_c), num(_n), price(_p) {}
  bool operator<(const node &tmp) const { return price < tmp.price; }
};
vector<node> store;
void input() {
  scanf("%d %d", &n, &m);
  for (int i = (0), i_end_ = (n); i < i_end_; ++i) g[i].clear();
  for (int i = (0), i_end_ = (m); i < i_end_; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    --u;
    --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int w;
  scanf("%d", &w);
  store.clear();
  for (int i = (0), i_end_ = (w); i < i_end_; ++i) {
    int city, num, price;
    scanf("%d %d %d", &city, &num, &price);
    --city;
    store.push_back(node(city, num, price));
  }
}
int que[N + 5];
void bfs(int s) {
  int L = 0, H = 0;
  for (int i = (0), i_end_ = (n); i < i_end_; ++i) dep[i] = inf;
  dep[s] = 0;
  que[H++] = s;
  while (L < H) {
    int u = que[L++];
    for (int i = (0), i_end_ = (((int)(g[u]).size())); i < i_end_; ++i) {
      int v = g[u][i];
      if (dep[v] == inf) {
        dep[v] = dep[u] + 1;
        que[H++] = v;
      }
    }
  }
}
int city, need, money;
bool chk(int lim) {
  long long num = 0, price = 0;
  for (int i = (0), i_end_ = (((int)(store).size())); i < i_end_; ++i) {
    if (dep[store[i].city] > lim) continue;
    long long add = min(need - num, (long long)store[i].num);
    num += add;
    price += add * store[i].price;
    if (price > money) return false;
    if (num == need) return true;
  }
  return false;
}
void solve() {
  scanf("%d %d %d", &city, &need, &money);
  --city;
  bfs(city);
  int L = 0, R = n, res = -1;
  while (L <= R) {
    int mid = L + (R - L) / 2;
    if (chk(mid)) {
      R = mid - 1;
      res = mid;
    } else
      L = mid + 1;
  }
  printf("%d\n", res);
}
int main() {
  input();
  sort((store).begin(), (store).end());
  int q;
  scanf("%d", &q);
  while (q--) solve();
  return 0;
}
