A new trade empire is rising in Berland. Bulmart, an emerging trade giant, decided to dominate the market of ... shovels! And now almost every city in Berland has a Bulmart store, and some cities even have several of them! The only problem is, at the moment sales are ... let's say a little below estimates. Some people even say that shovels retail market is too small for such a big company to make a profit. But the company management believes in the future of that market and seeks new ways to increase income. 

There are n cities in Berland connected with m bi-directional roads. All roads have equal lengths. It can happen that it is impossible to reach a city from another city using only roads. There is no road which connects a city to itself. Any pair of cities can be connected by at most one road.

There are w Bulmart stores in Berland. Each of them is described by three numbers: 

  * ci — the number of city where the i-th store is located (a city can have no stores at all or have several of them), 
  * ki — the number of shovels in the i-th store, 
  * pi — the price of a single shovel in the i-th store (in burles). 



The latest idea of the Bulmart management is to create a program which will help customers get shovels as fast as possible for affordable budget. Formally, the program has to find the minimum amount of time needed to deliver rj shovels to the customer in the city gj for the total cost of no more than aj burles. The delivery time between any two adjacent cities is equal to 1. If shovels are delivered from several cities, the delivery time is equal to the arrival time of the last package. The delivery itself is free of charge.

The program needs to find answers to q such queries. Each query has to be processed independently from others, i.e. a query does not change number of shovels in stores for the next queries.

Input

The first line contains two integers n, m (1 ≤ n ≤ 5000, 0 ≤ m ≤ min(5000, n·(n - 1) / 2)). Each of the next m lines contains two integers xe and ye, meaning that the e-th road connects cities xe and ye (1 ≤ xe, ye ≤ n).

The next line contains a single integer w (1 ≤ w ≤ 5000) — the total number of Bulmart stores in Berland. Each of the next w lines contains three integers describing the i-th store: ci, ki, pi (1 ≤ ci ≤ n, 1 ≤ ki, pi ≤ 2·105).

The next line contains a single integer q (1 ≤ q ≤ 1000) — the number of queries. Each of the next q lines contains three integers describing the j-th query: gj, rj and aj (1 ≤ gj ≤ n, 1 ≤ rj, aj ≤ 109)

Output

Output q lines. On the j-th line, print an answer for the j-th query — the minimum amount of time needed to deliver rj shovels to the customer in city gj spending no more than aj burles. Print -1 if there is no solution for the j-th query.

Example

Input

6 4
4 2
5 4
1 2
3 2
2
4 1 2
3 2 3
6
1 2 6
2 3 7
3 1 2
4 3 8
5 2 5
6 1 10


Output

2
-1
2
2
3
-1
#include <bits/stdc++.h>
using namespace std;
inline void rd(int &res) {
  res = 0;
  char c;
  while (c = getchar(), c < 48)
    ;
  do res = (res << 1) + (res << 3) + (c ^ 48);
  while (c = getchar(), c >= 48);
}
void print(int x) {
  if (!x) return;
  print(x / 10);
  putchar((x % 10) ^ 48);
}
void sc(int x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  }
  print(x);
  if (!x) putchar('0');
  putchar('\n');
}
inline void Max(int &x, int y) {
  if (x < y) x = y;
}
inline void Min(int &x, int y) {
  if (x > y) x = y;
}
const int M = 5005;
int mark[M], n, m, nex[M << 1], to[M << 1], ec = 1, dis[M][M], head[M], c[M],
                                            num[M], Q[M];
long long co[M];
struct node {
  int id, num;
  long long v;
} A[M];
bool cmp(node a, node b) {
  if (a.v != b.v) return a.v < b.v;
  return a.num > b.num;
}
void ins(int a, int b) {
  nex[ec] = head[a];
  to[ec] = b;
  head[a] = ec++;
  nex[ec] = head[b];
  to[ec] = a;
  head[b] = ec++;
}
const int oo = 1e9;
void bfs(int st) {
  int i, j, k, l = 0, r = 0;
  Q[r++] = st;
  for (i = 1; i <= n; i++) dis[st][i] = oo;
  dis[st][st] = 0;
  while (l < r) {
    int x = Q[l++];
    for (i = head[x]; i; i = nex[i]) {
      int y = to[i];
      if (dis[st][y] > dis[st][x] + 1) {
        dis[st][y] = dis[st][x] + 1;
        Q[r++] = y;
      }
    }
  }
}
bool chk(int d, int st, int tot, long long cost) {
  int i, j, k, now = tot;
  long long p = cost;
  for (i = 1; i <= m; i++) {
    if (dis[st][A[i].id] <= d) {
      int a = min(A[i].num, now);
      if (p >= A[i].v * a) {
        p -= A[i].v * a;
        now -= a;
        if (now == 0) return true;
      } else
        return false;
    }
  }
  return false;
}
int main() {
  int i, j, a, b, k;
  rd(n);
  rd(m);
  for (i = 1; i <= m; i++) {
    rd(a);
    rd(b);
    ins(a, b);
  }
  rd(m);
  for (i = 1; i <= m; i++) {
    rd(A[i].id);
    rd(A[i].num);
    cin >> A[i].v;
  }
  sort(A + 1, A + 1 + m, cmp);
  int Q;
  rd(Q);
  for (i = 1; i <= Q; i++) {
    rd(c[i]);
    rd(num[i]);
    cin >> co[i];
    mark[c[i]] = 1;
  }
  for (i = 1; i <= n; i++) {
    if (!mark[i]) continue;
    bfs(i);
  }
  for (i = 1; i <= Q; i++) {
    int l = 0, r = n, res = -1;
    while (l <= r) {
      int mid = l + r >> 1;
      if (chk(mid, c[i], num[i], co[i])) {
        res = mid;
        r = mid - 1;
      } else
        l = mid + 1;
    }
    sc(res);
  }
  return 0;
}
