#include <bits/stdc++.h>
using namespace std;
const int maxn = 5010;
vector<int> v[maxn], vec[maxn];
class node {
 public:
  long long first, second;
  node() {}
  node(long long first, long long second) : first(first), second(second) {}
  inline friend bool operator<(const node &a, const node &b) {
    if (a.second == b.second) return a.first > b.first;
    return a.second < b.second;
  }
};
vector<node> p[maxn];
priority_queue<node> s;
int n, m, vis[maxn], target, cost, num;
void bfs() {
  queue<int> q;
  memset(vis, -1, sizeof vis);
  for (int i = 0; i < maxn; i++) vec[i].clear();
  q.push(target);
  vis[target] = 0;
  if (!p[target].empty()) {
    vec[0].push_back(target);
  }
  int maxi = 0;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    maxi = max(maxi, vis[x]);
    for (unsigned int i = 0; i < v[x].size(); i++) {
      int y = v[x][i];
      if (vis[y] == -1) {
        vis[y] = vis[x] + 1;
        q.push(y);
        if (!p[y].empty()) {
          vec[vis[y]].push_back(y);
        }
      }
    }
  }
  while (!s.empty()) s.pop();
  int cnt = 0;
  long long co = 0;
  for (int i = 0; i <= maxi; i++) {
    for (unsigned int j = 0; j < vec[i].size(); j++) {
      int u = vec[i][j];
      for (unsigned int k = 0; k < p[u].size(); k++) {
        node uu = p[u][k];
        cnt += uu.first;
        co += uu.first * uu.second;
        s.push(uu);
        while (cnt > num) {
          node it = s.top();
          s.pop();
          long long delta = min((long long)(cnt - num), it.first);
          it.first -= delta;
          if (it.first > 0) s.push(it);
          cnt -= delta;
          co -= it.second * delta;
        }
        if (cnt == num && co <= cost) {
          printf("%d\n", i);
          return;
        }
      }
    }
  }
  puts("-1");
}
int main() {
  scanf("%d%d", &n, &m);
  while (m--) {
    int x, y;
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  scanf("%d", &m);
  while (m--) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    p[x].push_back(node(y, z));
  }
  scanf("%d", &m);
  while (m--) {
    scanf("%d%d%d", &target, &num, &cost);
    bfs();
  }
  return 0;
}
