#include <bits/stdc++.h>
using namespace std;
void getre() {
  int x = 0;
  printf("%d\n", 1 / x);
}
void gettle() {
  int res = 1;
  while (1) res <<= 1;
  printf("%d\n", res);
}
template <typename T, typename S>
inline bool upmin(T &a, const S &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T, typename S>
inline bool upmax(T &a, const S &b) {
  return a < b ? a = b, 1 : 0;
}
template <typename N, typename PN>
inline N flo(N a, PN b) {
  return a >= 0 ? a / b : -((-a - 1) / b) - 1;
}
template <typename N, typename PN>
inline N cei(N a, PN b) {
  return a > 0 ? (a - 1) / b + 1 : -(-a / b);
}
template <typename N>
N gcd(N a, N b) {
  return b ? gcd(b, a % b) : a;
}
template <typename N>
inline int sgn(N a) {
  return a > 0 ? 1 : (a < 0 ? -1 : 0);
}
inline void gn(long long &x) {
  int sg = 1;
  char c;
  while (((c = getchar()) < '0' || c > '9') && c != '-')
    ;
  c == '-' ? (sg = -1, x = 0) : (x = c - '0');
  while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
  x *= sg;
}
inline void gn(int &x) {
  long long t;
  gn(t);
  x = t;
}
inline void gn(unsigned long long &x) {
  long long t;
  gn(t);
  x = t;
}
inline void gn(double &x) {
  double t;
  scanf("%lf", &t);
  x = t;
}
inline void gn(long double &x) {
  double t;
  scanf("%lf", &t);
  x = t;
}
inline void gs(char *s) { scanf("%s", s); }
inline void gc(char &c) {
  while ((c = getchar()) > 126 || c < 33)
    ;
}
inline void pc(char c) { putchar(c); }
inline long long sqr(long long a) { return a * a; }
inline double sqrf(double a) { return a * a; }
const int inf = 0x3f3f3f3f;
const double pi = 3.14159265358979323846264338327950288L;
const double eps = 1e-6;
int n, m;
struct edge {
  int v, next;
} e[11111];
int etot = 0;
int g[5555];
void ae(int u, int v) {
  e[etot].v = v;
  e[etot].next = g[u];
  g[u] = etot++;
  e[etot].v = u;
  e[etot].next = g[v];
  g[v] = etot++;
}
int k;
struct node {
  int pos, cnt, pri;
  void read() {
    gn(pos);
    gn(cnt);
    gn(pri);
  }
} a[5555];
int cmppri(const node &a, const node &b) { return a.pri < b.pri; }
struct queq {
  int pos, cnt, mon, id;
  void read() {
    gn(pos);
    gn(cnt);
    gn(mon);
  }
} que[1555];
vector<int> qpos[5555];
int q;
int ans[5555];
int dis[5555];
int ord[5555];
int cmpdis(int i, int j) { return dis[i] < dis[j]; }
void bfs(int rt) {
  static int qu[5555];
  static int vis[5555];
  int p = 0, q = 0;
  for (int i = (1), _ed = (n + 1); i < _ed; i++) vis[i] = 0, dis[i] = inf;
  qu[q++] = rt;
  vis[rt] = 1;
  dis[rt] = 0;
  while (p != q) {
    int u = qu[p++];
    for (int i = g[u]; ~i; i = e[i].next)
      if (!vis[e[i].v]) {
        vis[e[i].v] = 1;
        qu[q++] = e[i].v;
        dis[e[i].v] = dis[u] + 1;
      }
  }
  for (int i = (1), _ed = (n + 1); i < _ed; i++) ord[i] = i;
  sort(ord + 1, ord + 1 + n, cmpdis);
}
int ask(int id) {
  int cnt = que[id].cnt, mon = que[id].mon;
  int lef = 0, rig = n;
  while (lef <= rig) {
    int mid = lef + rig >> 1;
    long long cursu = 0;
    int curcnt = cnt;
    for (int i = (1), _ed = (k + 1); i < _ed; i++)
      if (dis[a[i].pos] <= mid) {
        int del = min(curcnt, a[i].cnt);
        cursu += 1ll * del * a[i].pri;
        if (cursu > mon) break;
        curcnt -= del;
        if (curcnt == 0) break;
      }
    if (cursu <= mon && curcnt == 0) {
      rig = mid - 1;
    } else
      lef = mid + 1;
  }
  return lef == n + 1 ? -1 : lef;
}
int main() {
  gn(n);
  gn(m);
  memset((g), (-1), sizeof(g));
  for (int i = (1), _ed = (m + 1); i < _ed; i++) {
    int u, v;
    gn(u);
    gn(v);
    ae(u, v);
  }
  gn(k);
  for (int i = (1), _ed = (k + 1); i < _ed; i++) {
    a[i].read();
  }
  sort(a + 1, a + 1 + k, cmppri);
  gn(q);
  for (int i = (1), _ed = (q + 1); i < _ed; i++) {
    que[i].read();
    que[i].id = i;
    qpos[que[i].pos].push_back(i);
  }
  for (int u = (1), _ed = (n + 1); u < _ed; u++)
    if (!qpos[u].empty()) {
      bfs(u);
      for (int i = (0), _ed = (((int)(qpos[u]).size())); i < _ed; i++) {
        int j = qpos[u][i];
        ans[j] = ask(j);
      }
    }
  for (int i = (1), _ed = (q + 1); i < _ed; i++) printf("%d\n", ans[i]);
  return 0;
}
