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;
using ll = long long;
class flow {
 private:
  int n;
  vector<int> head, d, cur;
  vector<tuple<int, ll, int>> edge;
  bool bfs(int s, int t) {
    d.assign(n, -1);
    queue<int> que;
    que.push(s);
    d[s] = 0;
    while (!que.empty()) {
      int u = que.front();
      que.pop();
      for (int i = head[u]; i != -1; i = get<2>(edge[i])) {
        int v = get<0>(edge[i]);
        if (get<1>(edge[i]) && d[v] == -1) {
          d[v] = d[u] + 1;
          if (v == t) {
            return true;
          }
          que.push(v);
        }
      }
    }
    return false;
  }
  ll dfs(int u, int t, ll f) {
    if (u == t) {
      return f;
    }
    ll res = f;
    for (int &i = cur[u]; i != -1 && res; i = get<2>(edge[i])) {
      int v = get<0>(edge[i]);
      ll &c = get<1>(edge[i]);
      if (d[v] == d[u] + 1 && c) {
        ll aug = dfs(v, t, min(res, c));
        res -= aug;
        c -= aug;
        get<1>(edge[i ^ 1]) += aug;
      }
    }
    return f - res;
  }

 public:
  flow(int _n) {
    n = _n;
    head.assign(n, -1);
  }
  void insert_edge(int u, int v, ll c) {
    edge.emplace_back(v, c, head[u]);
    head[u] = edge.size() - 1;
    edge.emplace_back(u, 0, head[v]);
    head[v] = edge.size() - 1;
  }
  ll max_flow(int s, int t) {
    ll flow = 0;
    while (bfs(s, t)) {
      cur = head;
      flow += dfs(s, t, 1e18);
    }
    return flow;
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> dis(n, vector<int>(n, 1e9));
  for (int i = 0; i < n; ++i) {
    dis[i][i] = 0;
  }
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    --u;
    --v;
    dis[u][v] = 1;
    dis[v][u] = 1;
  }
  for (int k = 0; k < n; ++k) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
      }
    }
  }
  int s, b, k;
  cin >> s >> b >> k;
  vector<tuple<int, int, int, int>> ship;
  vector<vector<pair<int, int>>> base(n);
  for (int i = 0; i < s; ++i) {
    int x, a, f, p;
    cin >> x >> a >> f >> p;
    --x;
    ship.emplace_back(x, a, f, p);
  }
  for (int i = 0; i < b; ++i) {
    int x, d, g;
    cin >> x >> d >> g;
    --x;
    base[x].emplace_back(d, g);
  }
  for (int i = 0; i < n; ++i) {
    sort(base[i].begin(), base[i].end());
    for (int j = 1; j < base[i].size(); ++j) {
      base[i][j].second = max(base[i][j].second, base[i][j - 1].second);
    }
  }
  vector<ll> gain(s);
  for (int i = 0; i < s; ++i) {
    int x = get<0>(ship[i]);
    int a = get<1>(ship[i]);
    int f = get<2>(ship[i]);
    int p = get<3>(ship[i]);
    gain[i] = -1e14;
    for (int j = 0; j < n; ++j) {
      if (dis[x][j] <= f && !base[j].empty() && a >= base[j][0].first) {
        gain[i] =
            max(gain[i], 1ll * (--upper_bound(base[j].begin(), base[j].end(),
                                              make_pair(a, (int)1e9)))
                                     ->second -
                             p);
      }
    }
  }
  vector<bool> used(s);
  vector<pair<int, int>> rel;
  for (int i = 0; i < k; ++i) {
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    used[x] = true;
    used[y] = true;
    rel.emplace_back(x, y);
  }
  int cnt = 0;
  ll ans = 0;
  vector<int> id(s, -1);
  for (int i = 0; i < s; ++i) {
    if (used[i]) {
      id[i] = cnt++;
    } else if (gain[i] > 0) {
      ans += gain[i];
    }
  }
  flow G(cnt + 2);
  int S = cnt;
  int T = cnt + 1;
  for (int i = 0; i < s; ++i) {
    if (used[i]) {
      if (gain[i] > 0) {
        G.insert_edge(S, id[i], gain[i]);
        ans += gain[i];
      } else if (gain[i] < 0) {
        G.insert_edge(id[i], T, -gain[i]);
      }
    }
  }
  for (int i = 0; i < k; ++i) {
    G.insert_edge(id[rel[i].first], id[rel[i].second], 1e18);
  }
  ans -= G.max_flow(S, T);
  cout << ans << endl;
  return 0;
}