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 maxn = 100 + 5;
const int maxs = 1e5 + 5;
vector<int> gr[maxs], rg[maxs], sg[maxs];
int x[maxs], a[maxs], f[maxs], p[maxs];
int y[maxs], d[maxs], g[maxs];
int w[maxn][maxn], mg[maxn];
int topo[maxs], scc[maxs], uf[maxs];
long long pf[maxs], sum[maxs], ans[maxs];
long long opt[maxs];
bool ok[maxs], used[maxs];
bool sok[maxs];
void build(int n, int s, int b) {
  vector<int> vs(s), vb(b);
  iota(vs.begin(), vs.end(), 0);
  iota(vb.begin(), vb.end(), 0);
  sort(vs.begin(), vs.end(), [&](int i, int j) { return a[i] < a[j]; });
  sort(vb.begin(), vb.end(), [&](int i, int j) { return d[i] < d[j]; });
  for (int i = 0; i < n; ++i) mg[i] = -1;
  for (int i = 0, j = 0; i < s; ++i) {
    while (j < b && d[vb[j]] <= a[vs[i]]) {
      mg[y[vb[j]]] = max(mg[y[vb[j]]], g[vb[j]]);
      ++j;
    }
    int res = -1;
    for (int k = 0; k < n; ++k) {
      if (w[x[vs[i]]][k] <= f[vs[i]]) res = max(res, mg[k]);
    }
    if (res == -1)
      ok[vs[i]] = false;
    else
      ok[vs[i]] = true, pf[vs[i]] = res - p[vs[i]];
  }
}
void dfs(int x) {
  static int sz = 0;
  used[x] = true;
  for (int i = 0; i < (int)gr[x].size(); ++i) {
    int u = gr[x][i];
    if (!used[u]) dfs(u);
  }
  topo[sz++] = x;
}
void rdfs(int x, int s) {
  scc[x] = s;
  for (int i = 0; i < (int)rg[x].size(); ++i) {
    int u = rg[x][i];
    if (scc[u] == -1) rdfs(u, s);
  }
}
int find(int x) {
  if (x == uf[x]) return x;
  return uf[x] = find(uf[x]);
}
void merge(int x, int y) { uf[find(x)] = find(y); }
vector<int> walk;
void dfs3(int x) {
  walk.push_back(x);
  used[x] = true;
  for (int i = 0; i < (int)sg[x].size(); ++i) {
    int u = sg[x][i];
    if (used[u]) continue;
    dfs3(u);
  }
}
struct dinic {
  static const int maxn = maxs;
  static const long long inf = 1e18;
  struct edge {
    int dest, rev;
    long long cap;
    edge(int d, long long c, int r) : dest(d), cap(c), rev(r) {}
  };
  vector<edge> g[maxn];
  int qu[maxn], ql, qr;
  int lev[maxn];
  void init() {
    for (int i = 0; i < maxn; ++i) g[i].clear();
  }
  void add_edge(int a, int b, long long c) {
    g[a].emplace_back(b, c, g[b].size() - 0);
    g[b].emplace_back(a, 0, g[a].size() - 1);
  }
  bool bfs(int s, int t) {
    memset(lev, -1, sizeof(lev));
    lev[s] = 0;
    ql = qr = 0;
    qu[qr++] = s;
    while (ql < qr) {
      int x = qu[ql++];
      for (edge &e : g[x])
        if (lev[e.dest] == -1 && e.cap > 0) {
          lev[e.dest] = lev[x] + 1;
          qu[qr++] = e.dest;
        }
    }
    return lev[t] != -1;
  }
  long long dfs(int x, int t, long long flow) {
    if (x == t) return flow;
    long long res = 0;
    for (edge &e : g[x])
      if (e.cap > 0 && lev[e.dest] == lev[x] + 1) {
        long long f = dfs(e.dest, t, min(e.cap, flow - res));
        res += f;
        e.cap -= f;
        g[e.dest][e.rev].cap += f;
      }
    if (res == 0) lev[x] = -1;
    return res;
  }
  long long operator()(int s, int t) {
    long long flow = 0;
    for (; bfs(s, t); flow += dfs(s, t, inf))
      ;
    return flow;
  }
};
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) w[i][j] = i == j ? 0 : 1e8;
  }
  for (int i = 0; i < m; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    --u, --v;
    if (u == v) continue;
    w[u][v] = w[v][u] = 1;
  }
  for (int k = 0; k < n; ++k) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) w[i][j] = min(w[i][j], w[i][k] + w[k][j]);
    }
  }
  int s, b, k;
  scanf("%d%d%d", &s, &b, &k);
  for (int i = 0; i < s; ++i) {
    scanf("%d%d%d%d", &x[i], &a[i], &f[i], &p[i]);
    --x[i];
  }
  for (int i = 0; i < b; ++i) {
    scanf("%d%d%d", &y[i], &d[i], &g[i]);
    --y[i];
  }
  build(n, s, b);
  dinic flow;
  long long sum = 0;
  for (int i = 0; i < s; ++i) {
    if (!ok[i]) {
      flow.add_edge(i, s + 1, 2e14);
      continue;
    }
    if (pf[i] >= 0) {
      sum += pf[i];
      flow.add_edge(s, i, pf[i]);
    } else {
      flow.add_edge(i, s + 1, -pf[i]);
    }
  }
  while (k--) {
    int u, v;
    scanf("%d%d", &u, &v);
    --u, --v;
    flow.add_edge(u, v, 2e14);
  }
  printf("%lld\n", sum - flow(s, s + 1));
  return 0;
}