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;
long long K, H;
struct MaxFlow {
  vector<int> G[10100];
  struct Edge {
    int b, e, f;
  } E[2210000];
  int EC, flow, PV[10100], Q[10100], Level[10100], n, source, sink, INF = 1e9;
  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, int f) {
    G[a].push_back(EC);
    G[b].push_back(EC + 1);
    E[EC++] = {a, b, f};
    E[EC++] = {b, a, 0};
  }
  int BlockFlow(int a, int 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) {
        int ff = BlockFlow(E[t].e, min(E[t].f, f));
        if (ff) {
          E[t].f -= ff;
          E[t ^ 1].f += ff;
          return ff;
        }
      }
    }
    return 0;
  }
  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, 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;
} A[1100];
struct BB {
  int x, d;
} B[1100];
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%lld%lld", &n, &m, &K, &H);
  G1.init(n + m + 2, n + m + 1, n + m + 2);
  for (i = 1; i <= n; i++) {
    scanf("%d%d%d", &A[i].x, &A[i].a, &A[i].f);
    G1.Add_Edge(G1.source, i, 1);
  }
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &B[i].x, &B[i].d);
    G1.Add_Edge(n + i, G1.sink, 1);
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (A[i].a >= B[j].d && dis[A[i].x][B[j].x] <= A[i].f) {
        G1.Add_Edge(i, n + j, 1);
      }
    }
  }
  G1.Dinic();
  long long res = 1e18;
  for (i = 0; i <= n; i++) {
    int f = min(n - i, G1.flow);
    res = min(res, f * K + i * H);
  }
  printf("%lld\n", res);
}