#include <bits/stdc++.h>
using namespace std;
struct store {
  long long quant;
  long long price;
  long long city;
};
bool cmp(store a, store b) { return a.price < b.price; }
int n, m, w, q;
long long x, y, z;
vector<int> graph[5050];
vector<store> stores;
bool visited[5050];
int dist[5050];
void bfs(int ini) {
  for (int i = 0; i < 5050; i++) {
    visited[i] = false;
    dist[i] = 100000000;
  }
  queue<int> fila;
  dist[ini] = 0;
  fila.push(ini);
  while (!fila.empty()) {
    int u = fila.front();
    visited[u] = true;
    fila.pop();
    for (int v : graph[u]) {
      if (!visited[v] && dist[v] > dist[u] + 1) {
        dist[v] = dist[u] + 1;
        fila.push(v);
      }
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%lld %lld", &x, &y);
    graph[x].push_back(y);
    graph[y].push_back(x);
  }
  scanf("%d", &w);
  for (int i = 0; i < w; i++) {
    scanf("%lld %lld %lld", &x, &y, &z);
    stores.push_back((store){y, z, x});
  }
  sort(stores.begin(), stores.end(), cmp);
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%lld %lld %lld", &x, &y, &z);
    int left = 0, right = 5050;
    bfs(x);
    while (left <= right) {
      int mid = (left + right) / 2;
      long long cost = 0, number = y;
      for (int j = 0; j < w; j++) {
        if (dist[stores[j].city] <= mid) {
          if (number >= stores[j].quant) {
            number -= stores[j].quant;
            cost += stores[j].price * stores[j].quant;
          } else {
            cost += stores[j].price * number;
            number = 0;
            break;
          }
        }
      }
      if (cost <= z && number == 0)
        right = mid - 1;
      else
        left = mid + 1;
    }
    printf("%d\n", left == 5051 ? -1 : left);
  }
  return 0;
}
