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 long long INF = 1e17;
const long long maxn = 100015;
const long long maxm = 1000005;
long long g[105][105];
long long num[maxn];
long long id[maxn];
long long cnt;
void floyed(long long n) {
  for (long long k = 1; k <= n; k++) {
    for (long long i = 1; i <= n; i++) {
      for (long long j = 1; j <= n; j++) {
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
};
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
struct Edge {
  long long to, next, cap, flow;
} edge[maxm];
long long tol, head[maxn];
void init() {
  tol = 2;
  memset(head, -1, sizeof(head));
}
void addedge(long long u, long long v, long long w, long long rw = 0) {
  edge[tol].to = v;
  edge[tol].cap = w;
  edge[tol].flow = 0;
  edge[tol].next = head[u];
  head[u] = tol++;
  edge[tol].to = u;
  edge[tol].cap = rw;
  edge[tol].flow = 0;
  edge[tol].next = head[v];
  head[v] = tol++;
}
long long Q[maxn];
long long dep[maxn], cur[maxn], sta[maxn];
bool bfs(long long s, long long t, long long n) {
  long long front = 0, tail = 0;
  memset(dep, -1, sizeof(dep[0]) * (n + 1));
  dep[s] = 0;
  Q[tail++] = s;
  while (front < tail) {
    long long u = Q[front++];
    for (long long i = head[u]; i != -1; i = edge[i].next) {
      long long v = edge[i].to;
      if (edge[i].cap > edge[i].flow && dep[v] == -1) {
        dep[v] = dep[u] + 1;
        if (v == t) {
          return true;
        }
        Q[tail++] = v;
      }
    }
  }
  return false;
}
long long dinic(long long s, long long t, long long n) {
  long long maxflow = 0;
  while (bfs(s, t, n)) {
    for (long long i = 0; i < n; i++) {
      cur[i] = head[i];
    }
    long long u = s, tail = 0;
    while (cur[s] != -1) {
      if (u == t) {
        long long tp = INF;
        for (long long i = tail - 1; i >= 0; i--) {
          tp = min(tp, edge[sta[i]].cap - edge[sta[i]].flow);
        }
        maxflow += tp;
        for (long long i = tail - 1; i >= 0; i--) {
          edge[sta[i]].flow += tp;
          edge[sta[i] ^ 1].flow -= tp;
          if (edge[sta[i]].cap - edge[sta[i]].flow == 0) {
            tail = i;
          }
        }
        u = edge[sta[tail] ^ 1].to;
      } else if (cur[u] != -1 && edge[cur[u]].cap > edge[cur[u]].flow &&
                 dep[u] + 1 == dep[edge[cur[u]].to]) {
        sta[tail++] = cur[u];
        u = edge[cur[u]].to;
      } else {
        while (u != s && cur[u] == -1) {
          u = edge[sta[--tail] ^ 1].to;
        }
        cur[u] = edge[cur[u]].next;
      }
    }
  }
  return maxflow;
}
long long fuckacm[100005];
long long ps[105];
long long shipos[maxn], atk[maxn], f[maxn], p[maxn], baspos[maxn], d[maxn],
    gold[maxn], val[maxn], D[maxn];
bool svis[maxn];
vector<pair<long long, long long> > v1[105];
long long e[maxn][2];
bool cmp(long long x, long long y) { return atk[x] < atk[y]; }
long long ans = 0;
signed main() {
  long long n, m, u, v, s, b, k;
  n = read(), m = read();
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) {
      if (i == j)
        g[i][j] = 0;
      else
        g[i][j] = g[j][i] = INF;
    }
  }
  for (long long i = 1; i <= m; i++) {
    u = read(), v = read();
    g[u][v] = g[v][u] = 1;
  }
  floyed(n);
  s = read(), b = read(), k = read();
  for (long long i = 1; i <= s; i++) {
    shipos[i] = read(), atk[i] = read(), f[i] = read(), p[i] = read();
    id[i] = i;
  }
  for (long long i = 1; i <= b; i++) {
    baspos[i] = read(), d[i] = read(), gold[i] = read();
    v1[baspos[i]].emplace_back(pair<long long, long long>(d[i], gold[i]));
  }
  sort(id + 1, id + 1 + s, cmp);
  for (long long i = 1; i <= n; i++) {
    sort(v1[i].begin(), v1[i].end());
    ps[i] = 0;
    for (long long j = 1; j < v1[i].size(); j++) {
      v1[i][j].second = max(v1[i][j].second, v1[i][j - 1].second);
    }
  }
  for (long long I = 1; I <= s; I++) {
    long long i = id[I];
    long long ma = -INF;
    for (long long j = 1; j <= n; j++) {
      if (g[shipos[i]][j] <= f[i]) {
        if (v1[j].empty()) continue;
        while (ps[j] < v1[j].size() - 1 && v1[j][ps[j] + 1].first <= atk[i])
          ps[j]++;
        if (v1[j][ps[j]].first <= atk[i]) ma = max(ma, v1[j][ps[j]].second);
      }
    }
    val[i] = ma - p[i];
    if (val[i] > 0) ans += val[i];
  }
  for (long long i = 1; i <= k; i++) {
    e[i][0] = read(), e[i][1] = read();
    D[e[i][0]]++, D[e[i][1]]++;
  }
  long long S = 2015 + 1, T = S + 1;
  init();
  for (long long i = 1; i <= s; i++) {
    if (D[i]) id[i] = ++cnt;
  }
  for (long long i = 1; i <= s; i++) {
    if (D[i]) {
      if (val[i] > 0)
        addedge(S, id[i], val[i]);
      else
        addedge(id[i], T, -val[i]);
    }
  }
  for (long long i = 1; i <= k; i++) {
    addedge(id[e[i][0]], id[e[i][1]], INF);
  }
  ans -= dinic(S, T, T + 1);
  cout << ans;
  return 0;
}