#include <bits/stdc++.h>
using namespace std;
vector<int> gr[5005];
int d[5005];
int vis[5005];
int n;
int dis[5005][5005];
void bfs(int src) {
  memset(d, 0, sizeof d);
  memset(vis, 0, sizeof vis);
  queue<int> q;
  q.push(src);
  vis[src] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (long long i = 0; i < gr[u].size(); i++) {
      if (!vis[gr[u][i]]) {
        vis[gr[u][i]] = 1;
        q.push(gr[u][i]);
        d[gr[u][i]] = d[u] + 1;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i])
      dis[src][i] = 1e9 + 5;
    else
      dis[src][i] = d[i];
  }
}
vector<pair<int, pair<int, int> > > newv;
long long query(int mid, int x, long long y) {
  long long cost = 0;
  for (int i = 0; i < newv.size(); i++) {
    if (y == 0) break;
    if (dis[newv[i].second.first][x] <= mid) {
      if (newv[i].second.second >= y) {
        cost += (y * (long long)newv[i].first);
        y = 0;
      } else {
        cost += (newv[i].second.second * (long long)newv[i].first);
        y -= newv[i].second.second;
      }
    }
  }
  if (y > 0) return -1;
  return cost;
}
int main() {
  int m, x, y, z;
  scanf("%d %d", &n, &m);
  for (long long i = 0; i < m; i++) {
    scanf("%d %d", &x, &y);
    gr[x].push_back(y);
    gr[y].push_back(x);
  }
  int w;
  scanf("%d", &w);
  for (int i = 0; i < w; i++) {
    scanf("%d %d %d", &x, &y, &z);
    newv.push_back(make_pair(z, make_pair(x, y)));
  }
  sort(newv.begin(), newv.end());
  for (int i = 1; i <= n; i++) {
    bfs(i);
  }
  int q;
  scanf("%d", &q);
  long long y1, z1;
  while (q--) {
    scanf("%d %lld %lld", &x, &y1, &z1);
    int low = 0;
    int high = n;
    int mid;
    while (low < high) {
      mid = (low + high) / 2;
      long long ans = query(mid, x, y1);
      if (ans == -1) {
        low = mid + 1;
      } else {
        if (ans <= z1)
          high = mid;
        else
          low = mid + 1;
      }
    }
    long long ans = query(high, x, y1);
    if (ans == -1 || ans > z1) {
      printf("-1\n");
    } else
      printf("%d\n", high);
  }
  return 0;
}
