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;
struct Dinic {
  using F = long long;
  const static F INF = 0x3f3f3f3f3f3f3f3f;
  struct Edge {
    int v, bro;
    F cap;
    Edge() {}
    Edge(int _v, int _bro, F _cap) : v(_v), bro(_bro), cap(_cap) {}
  };
  vector<Edge> e;
  vector<int> pos, cur;
  int n, s, t, m;
  Dinic(int _n, int _s, int _t) : n(_n), s(_s), t(_t), m(0) {
    pos.assign(n, -1);
    cur.resize(n);
    d.resize(n);
    e.reserve(4e5);
  }
  void add(int u, int v, F c = INF) {
    assert(u < n && v < n);
    e.emplace_back(v, pos[u], c);
    pos[u] = m++;
    e.emplace_back(u, pos[v], 0);
    pos[v] = m++;
  }
  vector<int> d;
  bool bfs() {
    fill(d.begin(), d.end(), -1);
    d[s] = 0;
    queue<int> q;
    q.push(s);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int i = cur[u] = pos[u]; i != -1; i = e[i].bro) {
        int v = e[i].v;
        if (d[v] == -1 && e[i].cap != 0) {
          d[v] = d[u] + 1;
          q.push(v);
        }
      }
    }
    return d[t] != -1;
  }
  F dfs(int u, F lim) {
    if (u == t) return lim;
    F tot = 0;
    for (int& i = cur[u]; i != -1; i = e[i].bro) {
      int v = e[i].v;
      if (e[i].cap != 0 && d[v] == d[u] + 1) {
        F flow = dfs(v, min(e[i].cap, lim - tot));
        tot += flow;
        e[i].cap -= flow;
        e[i ^ 1].cap += flow;
        if (tot == lim) return lim;
      }
    }
    return tot;
  }
  F flow() {
    F res = 0;
    while (bfs()) {
      res += dfs(s, INF);
    }
    return res;
  }
};
struct ProjectSelection {
  int n;
  int s, t;
  Dinic mc;
  using F = Dinic::F;
  F positive;
  ProjectSelection(int _n)
      : n(_n), s(n), t(n + 1), mc(n + 2, s, t), positive(0) {}
  void add_proj(int i, F profit) {
    if (profit >= 0) {
      mc.add(s, i, profit);
      positive += profit;
    } else {
      mc.add(i, t, -profit);
    }
  }
  void add_dep(int u, int v) { mc.add(u, v); }
  F profit() { return positive - mc.flow(); }
};
template <typename T = int>
struct Compress {
  map<T, int> id;
  vector<T> num;
  inline int get_id(T x) {
    if (!id.count(x)) {
      id[x] = num.size();
      num.emplace_back(x);
    }
    return id[x];
  }
  inline int get_num(int i) {
    assert(0 <= i && i < num.size());
    return num[i];
  }
};
struct ProjectSelectionDumper {
  using F = Dinic::F;
  F sum;
  ProjectSelectionDumper(const vector<F>& profits,
                         const vector<pair<int, int>>& deps) {
    vector<bool> trk(profits.size(), false);
    Compress<int> c;
    for (auto& p : deps) {
      c.get_id(p.first);
      c.get_id(p.second);
      trk[p.first] = true;
      trk[p.second] = true;
    }
    ProjectSelection ps(c.num.size());
    sum = 0;
    for (int i = 0; i < (int)profits.size(); i++) {
      if (trk[i]) {
        ps.add_proj(c.get_id(i), profits[i]);
      } else if (profits[i] > 0) {
        sum += profits[i];
      }
    }
    for (auto& p : deps) {
      int u = c.get_id(p.first);
      int v = c.get_id(p.second);
      ps.add_dep(u, v);
    }
    sum += ps.profit();
  }
};
using ll = long long;
const int INF = 0x3f3f3f3f;
const int N = 111;
int d[N][N];
void solve() {
  int n, m;
  cin >> n >> m;
  memset(d, INF, sizeof d);
  for (int _ = 0; _ < m; _++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    d[x][y] = d[y][x] = 1;
  }
  for (int i = 0; i < n; i++) {
    d[i][i] = 0;
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (d[i][k] < INF && d[k][j] < INF) {
          d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        }
      }
    }
  }
  int s, b, k;
  cin >> s >> b >> k;
  vector<int> x(s), a(s), f(s);
  vector<ll> p(s);
  for (int i = 0; i < s; i++) {
    cin >> x[i] >> a[i] >> f[i] >> p[i];
    --x[i];
  }
  vector<map<int, int>> dg(n);
  for (int _ = 0; _ < b; _++) {
    int i, d, g;
    cin >> i >> d >> g;
    i--;
    dg[i][d] = max(dg[i][d], g);
  }
  for (int i = 0; i < n; i++) {
    int pre = 0;
    for (auto it = dg[i].begin(); it != dg[i].end(); it++) {
      it->second = pre = max(it->second, pre);
    }
  }
  for (int i = 0; i < s; i++) {
    int mx = -1;
    int u = x[i];
    for (int j = 0; j < n; j++) {
      if (!dg[j].empty() && f[i] >= d[u][j]) {
        auto it = dg[j].upper_bound(a[i]);
        if (it != dg[j].begin()) {
          --it;
          mx = max(mx, it->second);
        }
      }
    }
    if (mx < 0)
      p[i] = -(1ll << 62);
    else
      p[i] = mx - p[i];
  }
  vector<pair<int, int>> deps;
  for (int _ = 0; _ < k; _++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    deps.emplace_back(u, v);
  }
  ProjectSelectionDumper ps(p, deps);
  cout << ps.sum << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  cout << endl;
}