#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int SIZE = 1e6 + 10;
vector<int> e[SIZE];
vector<pair<int, int> > store[SIZE];
int used[SIZE], tt;
int bfs[SIZE], dis[SIZE];
int can(int st, int V, long long C) {
  multiset<pair<int, int> > now;
  tt++;
  bfs[0] = st;
  used[st] = tt;
  dis[st] = 0;
  int rr = 1;
  for (int i = 0; i < (rr); ++i) {
    int x = bfs[i];
    for (int j = 0; j < (((int)(store[x]).size())); ++j) {
      pair<int, int> gg = store[x][j];
      if (V > 0) {
        int mi = min(V, gg.second);
        gg.second -= mi;
        V -= mi;
        now.insert(make_pair(gg.first, mi));
        C -= (long long)gg.first * mi;
      }
      while (gg.second && gg.first < now.rbegin()->first) {
        pair<int, int> you = *now.rbegin();
        now.erase(now.find(you));
        int mi = min(gg.second, you.second);
        now.insert(make_pair(gg.first, mi));
        gg.second -= mi;
        you.second -= mi;
        C += mi * (long long)(you.first - gg.first);
        if (you.second) now.insert(you);
      }
      if (V == 0 && C >= 0) return dis[x];
    }
    for (int j = 0; j < (((int)(e[x]).size())); ++j) {
      int y = e[x][j];
      if (used[y] != tt) {
        used[y] = tt;
        bfs[rr++] = y;
        dis[y] = dis[x] + 1;
      }
    }
  }
  return -1;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (m); ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--;
    y--;
    e[x].push_back(y);
    e[y].push_back(x);
  }
  int(w);
  scanf("%d", &w);
  for (int i = 0; i < (w); ++i) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    x--;
    store[x].push_back(make_pair(z, y));
  }
  int(q);
  scanf("%d", &q);
  for (int kk = 0; kk < (q); ++kk) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    x--;
    printf("%d\n", can(x, y, z));
  }
  return 0;
}
