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>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx")
using namespace std;
using Int = long long;
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &a) {
  return os << "(" << a.first << ", " << a.second << ")";
};
template <class T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cerr << *i << " ";
  cerr << endl;
}
template <class T>
void chmin(T &t, const T &f) {
  if (t > f) t = f;
}
template <class T>
void chmax(T &t, const T &f) {
  if (t < f) t = f;
}
namespace BM {
const int LIM_N0 = 1010;
const int LIM_N1 = 1010;
const int LIM_M = 1000010;
int n0, n1, m, ptr[LIM_N0], nxt[LIM_M], zu[LIM_M];
int to[LIM_N0], fr[LIM_N1], used[LIM_N0], tof;
int lev[LIM_N0], que[LIM_N0], *qb, *qe;
void init(int _n0, int _n1) {
  n0 = _n0;
  n1 = _n1;
  m = 0;
  fill(ptr, ptr + n0, -1);
}
void ae(int u, int v) {
  nxt[m] = ptr[u];
  ptr[u] = m;
  zu[m] = v;
  ++m;
}
int augment(int u) {
  used[u] = tof;
  for (int i = ptr[u]; ~i; i = nxt[i]) {
    const int v = zu[i];
    const int w = fr[v];
    if (!~w || (used[w] != tof && lev[u] < lev[w] && augment(w))) {
      to[u] = v;
      fr[v] = u;
      return 1;
    }
  }
  return 0;
}
int solve() {
  fill(to, to + n0, -1);
  fill(fr, fr + n1, -1);
  fill(used, used + n0, -1);
  for (tof = 0;;) {
    qb = qe = que;
    fill(lev, lev + n0, -1);
    for (int u = 0; u < n0; ++u)
      if (!~to[u]) lev[ *qe++ = u] = 0;
    for (; qb != qe;) {
      const int u = *qb++;
      for (int i = ptr[u]; ~i; i = nxt[i]) {
        const int w = fr[zu[i]];
        if (~w && !~lev[w]) lev[ *qe++ = w] = lev[u] + 1;
      }
    }
    int f = 0;
    for (int u = 0; u < n0; ++u)
      if (!~to[u]) f += augment(u);
    if (!f) return tof;
    tof += f;
  }
}
}  // namespace BM
constexpr int INF = 1001001001;
int N, M;
int U[10010], V[10010];
int S, B;
Int K, H;
int X[1010], A[1010], F[1010];
int Y[1010], D[1010];
int dist[110][110];
int main() {
  for (; ~scanf("%d%d", &N, &M);) {
    for (int i = 0; i < M; ++i) {
      scanf("%d%d", &U[i], &V[i]);
      --U[i];
      --V[i];
    }
    scanf("%d%d%lld%lld", &S, &B, &K, &H);
    for (int s = 0; s < S; ++s) {
      scanf("%d%d%d", &X[s], &A[s], &F[s]);
      --X[s];
    }
    for (int b = 0; b < B; ++b) {
      scanf("%d%d", &Y[b], &D[b]);
      --Y[b];
    }
    for (int u = 0; u < N; ++u)
      for (int v = 0; v < N; ++v) {
        dist[u][v] = (u == v) ? 0 : INF;
      }
    for (int i = 0; i < M; ++i) {
      chmin(dist[U[i]][V[i]], 1);
      chmin(dist[V[i]][U[i]], 1);
    }
    for (int w = 0; w < N; ++w)
      for (int u = 0; u < N; ++u)
        for (int v = 0; v < N; ++v) {
          chmin(dist[u][v], dist[u][w] + dist[w][v]);
        }
    BM::init(S, B);
    for (int s = 0; s < S; ++s)
      for (int b = 0; b < B; ++b) {
        if (A[s] >= D[b] && F[s] >= dist[X[s]][Y[b]]) {
          BM::ae(s, b);
        }
      }
    const Int res = BM::solve();
    cerr << "res = " << res << endl;
    Int ans = H * S;
    for (Int z = 0; z <= S; ++z) {
      const Int score = K * min(res, S - z) + H * z;
      chmin(ans, score);
    }
    printf("%lld\n", ans);
  }
  return 0;
}