#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
vector<int> mp[5135];
int w, cnt;
vector<pair<int, int> > store[5135];
map<int, int> idm;
int rid[5135];
bool vis[5135];
int dis[5135], cc[5135];
void calDis(int rt) {
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    dis[i] = (1 << 30);
    vis[i] = 0;
  }
  memset(cc, 0, sizeof cc);
  dis[rt] = 0;
  vis[rt] = 1;
  queue<int> q;
  q.push(rt);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int v : mp[x]) {
      if (dis[x] + 1 < dis[v]) assert(!vis[v]);
      dis[v] = min(dis[v], dis[x] + 1);
      if (!vis[v]) {
        q.push(v);
        vis[v] = 1;
      }
    }
  }
}
bool ck(int rt, int D, int total, int P) {
  for (int(i) = 1; (i) <= (int)(n); (i)++)
    if (dis[i] <= D) {
      for (auto p : store[i]) {
        cc[p.first] += p.second;
      }
    }
  int tt = total;
  long long pr = 0;
  for (int(i) = 1; (i) <= (int)(cnt); (i)++) {
    pr += (long long)rid[i] * min(cc[i], tt);
    tt -= min(tt, cc[i]);
    cc[i] = 0;
  }
  if (tt == 0 && pr <= P) return 1;
  return 0;
}
void fmain() {
  scanf("%d%d", &n, &m);
  for (int i = 0, u, v; i < m; i++) {
    scanf("%d%d", &u, &v);
    mp[u].push_back(v);
    mp[v].push_back(u);
  };
  scanf("%d", &w);
  for (int(i) = 1; (i) <= (int)(w); (i)++) {
    int c, k, p;
    scanf("%d%d%d", &c, &k, &p);
    store[c].push_back({p, k});
    idm[p];
  }
  for (auto &p : idm) {
    p.second = ++cnt;
    rid[cnt] = p.first;
  }
  for (int(i) = 1; (i) <= (int)(n); (i)++)
    for (auto &p : store[i]) p.first = idm[p.first];
  int q;
  scanf("%d", &q);
  for (int(i) = 1; (i) <= (int)(q); (i)++) {
    int g, r, a;
    scanf("%d%d%d", &g, &r, &a);
    calDis(g);
    int L = 0, R = 5000;
    while (L + 1 < R) {
      int mid = (L + R) / 2;
      if (ck(g, mid, r, a))
        R = mid;
      else
        L = mid + 1;
    }
    int Ans = -1;
    if (ck(g, L, r, a))
      Ans = L;
    else if (ck(g, R, r, a))
      Ans = R;
    printf("%d\n", Ans);
  }
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain();
  }
  return 0;
}
