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;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize(3)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("sse3", "sse2", "sse")
#pragma GCC target("avx", "sse4", "sse4.1", "sse4.2", "ssse3")
#pragma GCC target("f16c")
#pragma GCC optimize("inline", "fast-math", "unroll-loops", \
                     "no-stack-protector")
#pragma GCC push_options
#pragma GCC pop_options
#pragma GCC reset_options
#pragma GCC optimize("O3")
const double eps = 1e-9;
const int INFMEM = 63;
const int INF = 1061109567;
const long long LINF = 100000000000000LL;
const double DINF = numeric_limits<double>::infinity();
const long long MOD = 1000000007;
const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
const double PI = 3.141592653589793;
inline void fastll(long long &input_number) {
  input_number = 0;
  int ch = getchar_unlocked();
  int sign = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') sign = -1;
    ch = getchar_unlocked();
  }
  while (ch >= '0' && ch <= '9') {
    input_number = (input_number << 3) + (input_number << 1) + ch - '0';
    ch = getchar_unlocked();
  }
  input_number *= sign;
}
inline void open(string a) {
  freopen((a + ".in").c_str(), "r", stdin);
  freopen((a + ".out").c_str(), "w", stdout);
}
inline void fasterios() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
struct ShipDT {
  long long pos, att, fuel, price, profit;
};
struct BaseDT {
  long long pos, def, price;
};
struct dtE {
  long long power_, idx;
  bool type;
  bool operator<(const dtE &other) const {
    if (power_ != other.power_) return power_ < other.power_;
    return type > other.type;
  }
};
long long n, m;
long long dist[105][105];
long long CurMaxgold[105];
vector<dtE> events;
long long ShipN, BaseN, DepM;
ShipDT ship[100005];
BaseDT base[100005];
struct dt {
  long long to, cap, backidx;
};
struct dta {
  long long pos, step;
};
long long ans;
long long s, e;
long long st[200005];
long long level[200005];
queue<dta> antri;
vector<dt> edge[200005];
void make_edge(long long u, long long v, long long capto, long long backcap) {
  long long szu = edge[u].size();
  long long szv = edge[v].size();
  edge[u].push_back({v, capto, szv});
  edge[v].push_back({u, backcap, szu});
  return;
}
void bfs(dta now) {
  for (int i = 0; i < edge[now.pos].size(); i++) {
    long long nx = edge[now.pos][i].to;
    if (level[nx]) continue;
    if (edge[now.pos][i].cap == 0) continue;
    level[nx] = now.step + 1;
    antri.push({nx, now.step + 1});
  }
  return;
}
long long maxflow(long long pos, long long bcap) {
  if (pos == e) return bcap;
  for (; st[pos] < edge[pos].size(); st[pos]++) {
    long long i = st[pos];
    long long nx = edge[pos][i].to;
    if (level[nx] != level[pos] + 1) continue;
    if (edge[pos][i].cap == 0) continue;
    long long curflow = maxflow(nx, min(bcap, edge[pos][i].cap));
    if (curflow == 0) continue;
    edge[pos][i].cap -= curflow;
    edge[nx][edge[pos][i].backidx].cap += curflow;
    return curflow;
  }
  return 0;
}
int main() {
  cin >> n >> m;
  memset(dist, INFMEM, sizeof(dist));
  for (int i = 1; i <= m; i++) {
    long long u, v;
    cin >> u >> v;
    dist[u][v] = 1;
  }
  for (int i = 1; i <= n; i++) dist[i][i] = 0;
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  cin >> ShipN >> BaseN >> DepM;
  for (int i = 1; i <= ShipN; i++) {
    cin >> ship[i].pos >> ship[i].att >> ship[i].fuel >> ship[i].price;
    events.push_back({ship[i].att, i, 0});
  }
  for (int i = 1; i <= BaseN; i++) {
    cin >> base[i].pos >> base[i].def >> base[i].price;
    events.push_back({base[i].def, i, 1});
  }
  sort(events.begin(), events.end());
  for (int i = 1; i <= n; i++) CurMaxgold[i] = -LINF;
  for (int i = 0; i < events.size(); i++) {
    long long curidx = events[i].idx;
    if (events[i].type == 1) {
      CurMaxgold[base[curidx].pos] =
          max(CurMaxgold[base[curidx].pos], base[curidx].price);
    } else {
      long long u = ship[curidx].pos;
      ship[curidx].profit = -LINF;
      for (int j = 1; j <= n; j++) {
        if (dist[u][j] <= ship[curidx].fuel) {
          ship[curidx].profit =
              max(ship[curidx].profit, CurMaxgold[j] - ship[curidx].price);
        }
      }
    }
  }
  long long ans = 0;
  s = 0;
  e = ShipN + 1;
  for (int i = 1; i <= ShipN; i++) {
    if (ship[i].profit < 0) {
      make_edge(i, e, abs(ship[i].profit), 0);
    } else {
      ans += ship[i].profit;
      make_edge(s, i, ship[i].profit, 0);
    }
  }
  for (int i = 1; i <= DepM; i++) {
    long long u, v;
    cin >> u >> v;
    make_edge(u, v, LINF, 0);
  }
  while (1) {
    memset(level, 0, sizeof(level));
    memset(st, 0, sizeof(st));
    level[s] = 1;
    antri.push({s, 1});
    while (!antri.empty()) {
      dta tmp = antri.front();
      antri.pop();
      bfs(tmp);
    }
    if (level[e] == 0) break;
    long long curflow;
    while (curflow = maxflow(s, LINF)) ans -= curflow;
  }
  printf("%lld\n", ans);
  return 0;
  return 0;
}