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;
vector<int> cand;
vector<int> prime(1000005);
vector<long long> primes;
void SieveOfEratosthenes(int n) {
  for (long long p = 2; p * p <= n; p++) {
    if (prime[p] == 0) {
      for (int i = p * p; i <= n; i += p)
        if (prime[i] == 0) prime[i] = p;
    }
  }
}
long long power(long long x, long long y) {
  long long res = 1ll;
  x = x % 1000000007;
  if (x == 0ll) return 0;
  while (y > 0ll) {
    if (y & 1ll) res = (res * x) % 1000000007;
    y = y >> 1ll;
    x = (x * x) % 1000000007;
  }
  return res;
}
long long add(long long x, long long y) {
  x += y;
  while (x >= 1000000007) x -= 1000000007;
  while (x < 0) x += 1000000007;
  return x;
}
long long mul(long long x, long long y) { return (x * 1ll * y) % 1000000007; }
long long binpow(long long x, long long y) {
  long long z = 1ll;
  while (y) {
    if (y & 1) z = mul(z, x);
    x = mul(x, x);
    y >>= 1ll;
  }
  return z;
}
long long inv(long long x) { return binpow(x, 1000000007 - 2); }
long long divide(long long x, long long y) { return mul(x, inv(y)); }
long long fact[2000006];
void precalc() {
  fact[0] = 1;
  for (long long i = 1; i < 2000006; i++) fact[i] = mul(fact[i - 1], i);
}
long long C(long long n, long long k) {
  if (n == 0) return 1;
  return divide(fact[n], mul(fact[k], fact[n - k]));
}
long long sub(long long A, long long B) {
  return (A - B + 1000000007) % 1000000007;
}
long long maxival(long long v, long long tl, long long tr, long long l,
                  long long r, long long segtree[]) {
  if (l > r) return LLONG_MAX;
  if (l == tl && r == tr) return segtree[v];
  long long tm = (tl + tr) / 2;
  auto x1 = maxival(2 * v, tl, tm, l, min(r, tm), segtree);
  auto x2 = maxival(2 * v + 1, tm + 1, tr, max(l, tm + 1), r, segtree);
  return min(x1, x2);
}
long long updateval(long long v, long long tl, long long tr, long long pos,
                    long long newval, long long segtree[]) {
  if (tl == tr) {
    segtree[v] = newval;
    return newval;
  } else {
    long long tm = (tl + tr) / 2;
    long long x;
    if (pos <= tm)
      x = updateval(2 * v, tl, tm, pos, newval, segtree);
    else
      x = updateval(2 * v + 1, tm + 1, tr, pos, newval, segtree);
    segtree[v] = min(segtree[2 * v], segtree[2 * v + 1]);
    return segtree[v];
  }
}
vector<long long> adj[1005];
vector<vector<long long>> capacity(1005, vector<long long>(1005, 0));
vector<long long> used(1005, 0);
vector<long long> mt(1005, 0);
long long s, b;
bool dfs(long long x) {
  if (used[x]) return false;
  used[x] = 1;
  for (long long y = 0; y < b; y++) {
    if (!capacity[x][y]) continue;
    if (mt[y] == -1 || dfs(mt[y])) {
      mt[y] = x;
      return true;
    }
  }
  return false;
}
long long kuhn() {
  for (long long i = 0; i < b; i++) mt[i] = -1;
  long long res = 0;
  for (long long i = 0; i < s; i++) {
    if (dfs(i)) {
      res++;
      for (int j = 0; j < s; j++) used[j] = 0;
    }
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(5);
  int t = 1;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    vector<vector<long long>> dis(n, vector<long long>(n, INT_MAX));
    long long i, j, kk;
    for (i = 1; i <= m; i++) {
      long long u, v;
      cin >> u >> v;
      u--;
      v--;
      dis[u][v] = 1;
      dis[v][u] = 1;
    }
    long long k, h;
    cin >> s >> b >> k >> h;
    vector<vector<long long>> ships(s, vector<long long>(3, 0));
    for (i = 1; i <= s; i++) {
      long long x, a, f;
      cin >> x >> a >> f;
      x--;
      ships[i - 1] = {x, a, f};
    }
    vector<vector<long long>> bases(b, vector<long long>(2, 0));
    for (i = 1; i <= b; i++) {
      long long x, d;
      cin >> x >> d;
      x--;
      bases[i - 1] = {x, d};
    }
    for (i = 0; i < n; i++) {
      dis[i][i] = 0;
      for (j = 0; j < n; j++) {
        for (kk = 0; kk < n; kk++) {
          if (dis[j][i] + dis[i][kk] < dis[j][kk])
            dis[j][kk] = dis[j][i] + dis[i][kk];
        }
      }
    }
    for (i = 0; i < s; i++) {
      for (j = 0; j < b; j++) {
        if (dis[ships[i][0]][bases[j][0]] > ships[i][2]) continue;
        if (ships[i][1] < bases[j][1]) continue;
        adj[i].push_back(j);
        capacity[i][j]++;
      }
    }
    long long ans = kuhn();
    cout << min(ans * k, s * h) << "\n";
  }
  return 0;
}