Problem: Thanks to the Doctor's help, the rebels managed to steal enough gold to launch a full-scale attack on the Empire! However, Darth Vader is looking for revenge and wants to take back his gold.

The rebels have hidden the gold in various bases throughout the galaxy. Darth Vader and the Empire are looking to send out their spaceships to attack these bases.

The galaxy can be represented as an undirected graph with n planets (nodes) and m wormholes (edges), each connecting two planets.

A total of s empire spaceships and b rebel bases are located at different planets in the galaxy.

Each spaceship is given a location x, denoting the index of the planet on which it is located, an attacking strength a, and a certain amount of fuel f.

Each base is given a location x, and a defensive strength d.

A spaceship can attack a base if both of these conditions hold: 

  * the spaceship's attacking strength is greater or equal than the defensive strength of the base 
  * the spaceship's fuel is greater or equal to the shortest distance, computed as the number of wormholes, between the spaceship's planet and the base's planet 



Vader is very particular about his attacking formations. He requires that each spaceship is to attack at most one base and that each base is to be attacked by at most one spaceship.

Vader knows that the rebels have hidden k gold in each base, so he will assign the spaceships to attack bases in such a way that maximizes the number of bases attacked.

Therefore, for each base that is attacked, the rebels lose k gold.

However, the rebels have the ability to create any number of dummy bases. With the Doctor's help, these bases would exist beyond space and time, so all spaceship can reach them and attack them. Moreover, a dummy base is designed to seem irresistible: that is, it will always be attacked by some spaceship.

Of course, dummy bases do not contain any gold, but creating such a dummy base costs h gold.

What is the minimum gold the rebels can lose if they create an optimal number of dummy bases?

Input

The first line contains two integers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ 10000), the number of nodes and the number of edges, respectively.

The next m lines contain two integers u and v (1 ≤ u, v ≤ n) denoting an undirected edge between the two nodes.

The next line contains four integers s, b, k and h (1 ≤ s, b ≤ 1000, 0 ≤ k, h ≤ 10^9), the number of spaceships, the number of bases, the cost of having a base attacked, and the cost of creating a dummy base, respectively.

The next s lines contain three integers x, a, f (1 ≤ x ≤ n, 0 ≤ a, f ≤ 10^9), denoting the location, attack, and fuel of the spaceship.

The next b lines contain two integers x, d (1 ≤ x ≤ n, 0 ≤ d ≤ 10^9), denoting the location and defence of the base.

Output

Print a single integer, the minimum cost in terms of gold.

Example

Input


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


Output


12

Note

One way to minimize the cost is to build 4 dummy bases, for a total cost of 4 × 3 = 12.

One empire spaceship will be assigned to attack each of these dummy bases, resulting in zero actual bases attacked.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 10;
const int maxs = 1e5 + 10;
const int maxn = 2e3 + 10;
const int maxm = 6e3 + 10;
const long long INF = 1e14 + 10;
const long long INF_CAP = INF;
struct spaceship {
  int x, a, f, p;
} sp[maxs];
struct base {
  int d, g;
  bool operator<(const base& b) const { return d < b.d; }
};
long long best_goal[maxs];
vector<base> ba[N];
vector<int> pre[N];
vector<int> g[maxs];
bool used[maxs];
int w[N][N], id[maxs];
struct Dinic {
  int n, m, s, t, pos;
  int d[maxn], head[maxn], que[maxn], ptr[maxn];
  int to[maxm], nxt[maxm];
  long long cap[maxm];
  void init() { memset(head, -1, sizeof head); }
  void addedge(int a, int b, long long c) {
    cap[m] = c;
    to[m] = b;
    nxt[m] = head[a];
    head[a] = m++;
    cap[m] = 0;
    to[m] = a;
    nxt[m] = head[b];
    head[b] = m++;
  }
  bool bfs() {
    pos = 0;
    memset(d, -1, sizeof d);
    que[pos++] = s;
    d[s] = 0;
    for (int i = 0; i < pos; i++) {
      int x = que[i];
      for (int u = head[x]; ~u; u = nxt[u]) {
        if (d[to[u]] == -1 && cap[u]) {
          d[to[u]] = d[x] + 1;
          que[pos++] = to[u];
          if (d[t] != -1) return true;
        }
      }
    }
    return d[t] != -1;
  }
  long long dfs(int o, long long mi) {
    if (o == t || mi == 0) return mi;
    long long res = 0;
    for (int& x = ptr[o]; ~x; x = nxt[x])
      if (d[to[x]] == d[o] + 1 && cap[x]) {
        long long tmp = dfs(to[x], min(mi, cap[x]));
        cap[x] -= tmp;
        cap[x ^ 1] += tmp;
        if (tmp > 0) return tmp;
      }
    return res;
  }
  long long maxflow(int s, int t) {
    this->s = s;
    this->t = t;
    long long res = 0;
    while (bfs()) {
      memcpy(ptr, head, sizeof head);
      res += dfs(s, INF_CAP);
    }
    return res;
  }
} D;
int main() {
  D.init();
  int n, m, s, b, k;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) fill(w[i] + 1, w[i] + 1 + n, n), w[i][i] = 0;
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    w[b][a] = w[a][b] = min(w[a][b], 1);
  }
  for (int d = 1; d <= n; d++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        w[i][j] = min(w[i][j], w[i][d] + w[d][j]);
      }
    }
  }
  scanf("%d%d%d", &s, &b, &k);
  for (int i = 1; i <= s; i++) {
    scanf("%d%d%d%d", &sp[i].x, &sp[i].a, &sp[i].f, &sp[i].p);
  }
  for (int i = 0; i < b; i++) {
    int x, d, g;
    scanf("%d%d%d", &x, &d, &g);
    ba[x].push_back(base{d, g});
  }
  for (int i = 1; i <= n; i++)
    if (ba[i].size()) {
      int sz = (int)ba[i].size();
      sort(ba[i].begin(), ba[i].end());
      pre[i].resize(sz);
      pre[i][0] = ba[i][0].g;
      for (int j = 1; j < sz; j++) pre[i][j] = max(pre[i][j - 1], ba[i][j].g);
    }
  for (int i = 1; i <= s; i++) {
    best_goal[i] = -INF_CAP;
    int x = sp[i].x;
    for (int j = 1; j <= n; j++) {
      if (w[x][j] <= sp[i].f) {
        int pos = upper_bound(ba[j].begin(), ba[j].end(), base{sp[i].a, 0}) -
                  ba[j].begin();
        --pos;
        if (pos >= 0) {
          best_goal[i] = max(best_goal[i], (long long)pre[j][pos] - sp[i].p);
        }
      }
    }
  }
  for (int i = 0; i < k; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    g[a].push_back(b);
    used[a] = used[b] = 1;
  }
  long long ans = 0;
  int cnt = 0;
  for (int i = 1; i <= s; i++) {
    if (!used[i]) {
      if (best_goal[i] > 0) ans += best_goal[i];
    } else {
      id[i] = ++cnt;
    }
  }
  int st = 0, ed = cnt + 1;
  cnt = 0;
  for (int i = 1; i <= s; i++) {
    if (used[i]) {
      if (best_goal[i] >= 0)
        ans += best_goal[i], D.addedge(st, id[i], best_goal[i]);
      else
        D.addedge(id[i], ed, -best_goal[i]);
      for (auto& u : g[i]) D.addedge(id[i], id[u], INF_CAP);
    }
  }
  ans -= D.maxflow(st, ed);
  printf("%lld\n", ans);
  return 0;
}