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 int MOD = (int)1e9 + 7;
const int FFTMOD = 119 << 23 | 1;
const int INF = (int)1e9 + 23111992;
const long long LINF = (long long)1e18 + 23111992;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
template <class T>
inline int chkmin(T& a, const T& val) {
  return val < a ? a = val, 1 : 0;
}
template <class T>
inline int chkmax(T& a, const T& val) {
  return a < val ? a = val, 1 : 0;
}
inline unsigned long long isqrt(unsigned long long k) {
  unsigned long long r = sqrt(k) + 1;
  while (r * r > k) r--;
  return r;
}
inline long long icbrt(long long k) {
  long long r = cbrt(k) + 1;
  while (r * r * r > k) r--;
  return r;
}
inline void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
inline void submod(int& a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }
inline int sign(long double x, long double y) { return sign(x - y); }
mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int mrand() { return abs((int)mt()); }
const long long foo = (long long)1e18;
namespace Maxflow {
const int maxv = 2e5 + 5;
const int maxe = 1e7 + 5;
int n, s, t, E;
int adj[maxe], nxt[maxe], lst[maxv], ptr[maxv], lev[maxv], que[maxv];
long long flw[maxe], cap[maxe];
void init(int nn, int ss, int tt) {
  n = nn, s = ss, t = tt, E = 0;
  fill_n(lst, n, -1);
}
void add(int u, int v, long long c1, long long c2) {
  adj[E] = v, flw[E] = 0, cap[E] = c1, nxt[E] = lst[u], lst[u] = E++;
  adj[E] = u, flw[E] = 0, cap[E] = c2, nxt[E] = lst[v], lst[v] = E++;
}
int bfs() {
  fill_n(lev, n, 0), lev[s] = 1;
  int qsize = 0;
  que[qsize++] = s;
  for (int i = 0; i < qsize; i++) {
    for (int u = que[i], e = lst[u]; ~e; e = nxt[e]) {
      int v = adj[e];
      if (flw[e] < cap[e] && !lev[v]) {
        lev[v] = lev[u] + 1;
        que[qsize++] = v;
      }
    }
  }
  return lev[t];
}
long long dfs(int u, long long bot) {
  if (u == t) return bot;
  for (int& e = ptr[u]; ~e; e = nxt[e]) {
    int v = adj[e];
    long long delta = 0;
    if (lev[v] == lev[u] + 1 && flw[e] < cap[e] &&
        (delta = dfs(v, min(bot, cap[e] - flw[e]))) > 0) {
      flw[e] += delta;
      flw[e ^ 1] -= delta;
      return delta;
    }
  }
  return 0;
}
long long maxflow(int ss = -1, int tt = -1) {
  if (~ss) s = ss;
  if (~tt) t = tt;
  fill_n(flw, E, 0);
  long long total = 0;
  while (bfs()) {
    for (int i = 0; i < n; i++) ptr[i] = lst[i];
    for (long long delta = dfs(s, foo); delta > 0; delta = dfs(s, foo))
      total += delta;
  }
  return total;
}
vector<pair<pair<int, int>, long long> > gomory_hu() {
  vector<pair<pair<int, int>, long long> > tree;
  vector<int> p(n);
  for (int u = 1; u < n; u++) {
    tree.push_back(make_pair(make_pair(p[u], u), maxflow(u, p[u])));
    for (int v = u + 1; v < n; ++v) {
      if (lev[v] && p[v] == p[u]) {
        p[v] = u;
      }
    }
  }
  return tree;
}
}  // namespace Maxflow
void chemthan() {
  int n, m;
  cin >> n >> m;
  vector<vector<int> > d(n, vector<int>(n, INF));
  for (int i = (0); i < (n); ++i) d[i][i] = 0;
  for (int i = (0); i < (m); ++i) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    if (u ^ v) {
      d[u][v] = d[v][u] = 1;
    }
  }
  for (int w = (0); w < (n); ++w)
    for (int u = (0); u < (n); ++u)
      for (int v = (0); v < (n); ++v) chkmin(d[u][v], d[u][w] + d[w][v]);
  int s, b, k;
  cin >> s >> b >> k;
  vector<int> x(s), a(s), f(s), p(s);
  for (int i = (0); i < (s); ++i) {
    cin >> x[i] >> a[i] >> f[i] >> p[i], x[i]--;
  }
  vector<vector<pair<int, int> > > g(n);
  for (int i = (0); i < (b); ++i) {
    int x, d, gg;
    cin >> x >> d >> gg, x--;
    g[x].push_back(make_pair(d, gg));
  }
  for (int u = (0); u < (n); ++u) {
    sort((g[u]).begin(), (g[u]).end());
    for (int i = (1); i < (int((g[u]).size())); ++i) {
      chkmax(g[u][i].second, g[u][i - 1].second);
    }
  }
  vector<int> c(s), cc(s);
  for (int i = (0); i < (s); ++i) {
    for (int u = (0); u < (n); ++u)
      if (d[x[i]][u] <= f[i]) {
        int k =
            upper_bound((g[u]).begin(), (g[u]).end(), make_pair(a[i], INF)) -
            g[u].begin() - 1;
        if (0 <= k) {
          chkmax(c[i], g[u][k].second);
          cc[i] = 1;
        }
      }
    c[i] -= p[i];
  }
  int tot = s, S = tot++, t = tot++;
  Maxflow::init(tot, S, t);
  long long res = 0;
  for (int i = (0); i < (s); ++i) {
    if (0 <= c[i]) {
      Maxflow::add(S, i, c[i], 0);
      res += c[i];
    } else {
      Maxflow::add(i, t, -c[i], 0);
    }
  }
  for (int i = (0); i < (k); ++i) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    Maxflow::add(u, v, LINF, 0);
  }
  for (int i = (0); i < (s); ++i) {
    if (!cc[i]) {
      Maxflow::add(i, t, LINF, 0);
    }
  }
  cout << res - Maxflow::maxflow() << "\n";
}
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(0), cin.tie(0);
  if (argc > 1) {
    assert(freopen(argv[1], "r", stdin));
  }
  if (argc > 2) {
    assert(freopen(argv[2], "wb", stdout));
  }
  chemthan();
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}