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;
int dis[110][110], nV, nE, n, m;
struct MaxFlow {
  vector<int> G[220100];
  struct Edge {
    int b, e;
    long long f;
  } E[221000];
  int EC, PV[220100], Q[220100], Level[220100], n, source, sink;
  long long flow, INF = 1e16;
  void init(int N, int S, int T) {
    source = S, sink = T, flow = EC = 0;
    n = N;
    for (int i = 0; i <= n; i++) G[i].clear();
  }
  void Add_Edge(int a, int b, long long f) {
    G[a].push_back(EC);
    G[b].push_back(EC + 1);
    E[EC++] = {a, b, f};
    E[EC++] = {b, a, 0};
  }
  long long BlockFlow(int a, long long f) {
    if (a == sink) return f;
    for (int &i = PV[a]; i >= 0; i--) {
      int t = G[a][i];
      if (E[t].f && Level[E[t].e] == Level[a] + 1) {
        long long ff = BlockFlow(E[t].e, min(E[t].f, f));
        if (ff) {
          E[t].f -= ff;
          E[t ^ 1].f += ff;
          return ff;
        }
      }
    }
    return 0ll;
  }
  bool GetLevel() {
    int head = 0, tail = 0, i;
    for (i = 1; i <= n; i++) Level[i] = -1;
    Q[++tail] = source;
    Level[source] = 0;
    while (head < tail) {
      int x = Q[++head];
      for (auto &t : G[x]) {
        if (E[t].f && Level[E[t].e] == -1) {
          Level[E[t].e] = Level[x] + 1;
          Q[++tail] = E[t].e;
        }
      }
    }
    return Level[sink] != -1;
  }
  void Dinic() {
    int i;
    long long t;
    flow = 0;
    while (GetLevel()) {
      for (i = 1; i <= n; i++) PV[i] = G[i].size() - 1;
      while (t = BlockFlow(source, INF)) {
        flow += t;
      }
    }
  }
} G1;
struct AA {
  int x, a, f, cost;
} A[110000];
struct BB {
  int d, k;
  bool operator<(const BB &p) const { return d < p.d; }
};
vector<BB> U[110];
vector<int> MX[110];
pair<int, int> Ed[1010];
int K, chk[101000];
long long WW[101000];
int main() {
  int i, j, k;
  scanf("%d%d", &nV, &nE);
  for (i = 1; i <= nV; i++)
    for (j = 1; j <= nV; j++)
      if (i != j) dis[i][j] = 1e9;
  for (i = 0; i < nE; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    dis[a][b] = dis[b][a] = 1;
  }
  for (k = 1; k <= nV; k++)
    for (i = 1; i <= nV; i++)
      for (j = 1; j <= nV; j++)
        dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
  scanf("%d%d%d", &n, &m, &K);
  for (i = 1; i <= n; i++) {
    scanf("%d%d%d%d", &A[i].x, &A[i].a, &A[i].f, &A[i].cost);
  }
  for (i = 1; i <= m; i++) {
    int x, d, k;
    scanf("%d%d%d", &x, &d, &k);
    U[x].push_back({d, k});
  }
  for (i = 1; i <= nV; i++) {
    int sz = U[i].size();
    if (!sz) continue;
    MX[i].resize(sz);
    sort(U[i].begin(), U[i].end());
    for (j = 0; j < sz; j++) {
      MX[i][j] = U[i][j].k;
      if (j) MX[i][j] = max(MX[i][j], MX[i][j - 1]);
    }
  }
  for (i = 1; i <= n; i++) {
    long long z = -1e16;
    for (j = 1; j <= nV; j++) {
      if (U[j].empty() || A[i].f < dis[A[i].x][j]) continue;
      BB tp = {A[i].a + 1, 0};
      int pv = lower_bound(U[j].begin(), U[j].end(), tp) - U[j].begin();
      if (!pv) continue;
      z = max(z, 0ll + MX[j][pv - 1] - A[i].cost);
    }
    WW[i] = z;
  }
  for (i = 0; i < K; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    Ed[i] = {a, b};
    chk[a] = chk[b] = 1;
  }
  long long sum = 0;
  G1.init(n + 2, n + 1, n + 2);
  long long BS = 1e10, tt = 0;
  for (i = 1; i <= n; i++) {
    if (!chk[i]) {
      sum += max(WW[i], 0ll);
    } else {
      tt += BS;
      G1.Add_Edge(G1.source, i, BS);
      G1.Add_Edge(i, G1.sink, BS - WW[i]);
    }
  }
  for (i = 0; i < K; i++) {
    G1.Add_Edge(Ed[i].first, Ed[i].second, G1.INF);
  }
  G1.Dinic();
  printf("%lld\n", sum + tt - G1.flow);
}