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 N = 105;
const int INF = 1e9 + 5;
const long long INF_LL = 1e15 + 5;
int g[N][N], dist[N][N];
struct Ship {
  int loc, attack, fuel, price;
  void read() {
    cin >> loc >> attack >> fuel >> price;
    --loc;
  }
};
vector<pair<int, int>> reward[N];
struct Base {
  int loc, defence, gold;
  void read() {
    cin >> loc >> defence >> gold;
    --loc;
    reward[loc].emplace_back(defence, gold);
  }
};
template <typename T>
void max_self(T& a, T b) {
  a = max(a, b);
}
template <typename flow_t>
class Dinic {
 public:
  Dinic(int _n, int _source, int _sink) : n(_n), source(_source), sink(_sink) {
    g.resize(n);
    flow.resize(n, vector<flow_t>(n));
    level.resize(n);
    ptr.resize(n);
  }
  void add_edge(int from, int to, flow_t cap) {
    g[from].push_back(to);
    g[to].push_back(from);
    flow[from][to] += cap;
  }
  bool bfs() {
    vector<int> q{source};
    for (int i = 0; i < (int)q.size(); i++) {
      int u = q[i];
      for (int v : g[u]) {
        if (level[v] == -1 && flow[u][v] > 0) {
          level[v] = level[u] + 1;
          q.push_back(v);
        }
      }
    }
    return level[sink] != -1;
  }
  flow_t dfs(int u, flow_t pushed) {
    if (pushed == 0) {
      return 0;
    }
    if (u == sink) {
      return pushed;
    }
    for (int& pos = ptr[u]; pos < (int)g[u].size(); pos++) {
      int v = g[u][pos];
      if (level[v] != level[u] + 1 || flow[u][v] == 0) {
        continue;
      }
      flow_t maybe_push = dfs(v, min(pushed, flow[u][v]));
      if (maybe_push == 0) {
        continue;
      }
      flow[u][v] -= maybe_push;
      flow[v][u] += maybe_push;
      return maybe_push;
    }
    return 0;
  }
  flow_t max_flow() {
    flow_t mf(0);
    while (true) {
      level.assign(n, -1);
      level[source] = 0;
      if (!bfs()) {
        break;
      }
      ptr.assign(n, 0);
      flow_t now;
      do {
        now = dfs(source, FLOW_MAX);
        mf += now;
      } while (now != 0);
    }
    return mf;
  }

 private:
  const flow_t FLOW_MAX = numeric_limits<flow_t>::max() / 2;
  vector<vector<int>> g;
  vector<vector<flow_t>> flow;
  vector<int> level, ptr;
  int n, source, sink;
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  fill((int*)dist, (int*)dist + N * N, INF);
  for (int i = 0; i < int(N); i++) dist[i][i] = 0;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < int(m); i++) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    g[a][b] = g[b][a] = 1;
    dist[a][b] = dist[b][a] = 1;
  }
  for (int k = 0; k < int(n); k++)
    for (int i = 0; i < int(n); i++)
      for (int j = 0; j < int(n); j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
  int second, B, K;
  cin >> second >> B >> K;
  vector<Ship> ships(second);
  vector<Base> bases(B);
  for (auto& s : ships) {
    s.read();
  }
  for (auto& b : bases) {
    b.read();
  }
  for (int i = 0; i < int(n); i++) {
    sort(reward[i].begin(), reward[i].end());
    int sz = reward[i].size();
    for (int j = 1; j <= int(sz - 1); j++) {
      reward[i][j].second = max(reward[i][j].second, reward[i][j - 1].second);
    }
  }
  vector<long long> ship_reward(second, -INF_LL);
  for (int i = 0; i < int(second); i++) {
    Ship s = ships[i];
    for (int base = 0; base < int(n); base++)
      if (dist[s.loc][base] < INF) {
        int lo = 0, hi = (int)reward[base].size() - 1;
        int idx = -1;
        while (lo <= hi) {
          int mid = (lo + hi) / 2;
          if (reward[base][mid].first <= s.attack) {
            idx = mid;
            lo = mid + 1;
          } else {
            hi = mid - 1;
          }
        }
        if (idx == -1) {
          continue;
        }
        max_self(ship_reward[i], (long long)reward[base][idx].second - s.price);
      }
  }
  vector<pair<int, int>> dependencies;
  for (int i = 0; i < int(K); i++) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    dependencies.emplace_back(a, b);
  }
  long long ans = 0;
  for (int i = 0; i < int(second); i++) {
    if (ship_reward[i] > 0) {
      ans += ship_reward[i];
    }
  }
  map<int, int> id;
  int nodes = 0;
  for (auto [u, v] : dependencies) {
    if (!id.count(u)) {
      id[u] = nodes++;
    }
    if (!id.count(v)) {
      id[v] = nodes++;
    }
  }
  int source = nodes++;
  int sink = nodes++;
  Dinic<long long> graph(nodes, source, sink);
  for (auto [u, _] : id) {
    if (ship_reward[u] >= 0) {
      graph.add_edge(source, id[u], ship_reward[u]);
    } else {
      graph.add_edge(id[u], sink, -ship_reward[u]);
    }
  }
  for (auto [u, v] : dependencies) {
    graph.add_edge(id[u], id[v], INF_LL);
  }
  ans -= graph.max_flow();
  cout << ans << "\n";
}