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;
template <typename T, size_t size>
ostream &operator<<(ostream &os, const array<T, size> &arr) {
  os << '{';
  string sep;
  for (const auto &x : arr) os << sep << x, sep = ", ";
  return os << '}';
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[ ";
  for (auto v : V) os << v << " ";
  return os << "]";
}
template <class T>
ostream &operator<<(ostream &os, set<T> S) {
  os << "{ ";
  for (auto s : S) os << s << " ";
  return os << "}";
}
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <class L, class R>
ostream &operator<<(ostream &os, map<L, R> M) {
  os << "{ ";
  for (auto m : M) os << "(" << m.first << ":" << m.second << ") ";
  return os << "}";
}
const int MAX = 1000010;
const int MOD2 = 998244353;
const int MOD1 = 1000000007;
const int INF = 0x3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3fll;
const long double EPS = 1e-7;
struct edge {
  int from, to, cap, flow, index;
  edge(int from_, int to_, int cap_, int flow_, int index_)
      : from(from_), to(to_), cap(cap_), flow(flow_), index(index_) {}
};
struct PushRelabel {
  int n;
  vector<vector<edge>> g;
  vector<long long> excess;
  vector<int> height, active, count;
  queue<int> Q;
  PushRelabel(int n_)
      : n(n_), g(n_), excess(n_), height(n_), active(n_), count(2 * n_) {}
  void addEdge(int from, int to, int cap) {
    g[from].push_back(edge(from, to, cap, 0, static_cast<int>(g[to].size())));
    if (from == to) g[from].back().index++;
    g[to].push_back(edge(to, from, 0, 0, static_cast<int>(g[from].size()) - 1));
  }
  void enqueue(int v) {
    if (!active[v] and excess[v] > 0) {
      active[v] = true;
      Q.push(v);
    }
  }
  void push(edge &e) {
    int amt = (int)min(excess[e.from], (long long)e.cap - e.flow);
    if (height[e.from] <= height[e.to] or amt == 0) return;
    e.flow += amt;
    g[e.to][e.index].flow -= amt;
    excess[e.to] += amt;
    excess[e.from] -= amt;
    enqueue(e.to);
  }
  void relabel(int v) {
    count[height[v]]--;
    int d = 2 * n;
    for (auto &it : g[v]) {
      if (it.cap - it.flow > 0) d = min(d, height[it.to] + 1);
    }
    height[v] = d;
    count[height[v]]++;
    enqueue(v);
  }
  void gap(int k) {
    for (int v = 0; v < n; v++) {
      if (height[v] < k) continue;
      count[height[v]]--;
      height[v] = max(height[v], n + 1);
      count[height[v]]++;
      enqueue(v);
    }
  }
  void discharge(int v) {
    for (int i = 0; excess[v] > 0 and i < static_cast<int>(g[v].size()); i++)
      push(g[v][i]);
    if (excess[v] > 0) {
      if (count[height[v]] == 1)
        gap(height[v]);
      else
        relabel(v);
    }
  }
  long long max_flow(int source, int dest) {
    count[0] = n - 1;
    count[n] = 1;
    height[source] = n;
    active[source] = active[dest] = 1;
    for (auto &it : g[source]) {
      excess[source] += it.cap;
      push(it);
    }
    while (!Q.empty()) {
      int v = Q.front();
      Q.pop();
      active[v] = false;
      discharge(v);
    }
    long long max_flow = 0;
    for (auto &e : g[source]) max_flow += e.flow;
    return max_flow;
  }
} flow(2005);
const int mxn = 1005;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed << setprecision(25);
  cerr << fixed << setprecision(10);
  int n, m, s, b, k, h;
  vector<int> x(mxn), a(mxn), f(mxn), y(mxn), d(mxn);
  vector<vector<pair<int, int>>> in(mxn);
  vector<vector<int>> out(mxn), dist(mxn, vector<int>(mxn));
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (i ^ j) dist[i][j] = MOD1;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    dist[u][v] = dist[v][u] = 1;
  }
  cin >> s >> b >> k >> h;
  for (int i = 1; i <= s; i++) {
    flow.addEdge(0, i, 1);
    cin >> x[i] >> a[i] >> f[i];
  }
  for (int i = 1; i <= b; i++) {
    flow.addEdge(i + 1000, 2004, 1);
    cin >> y[i] >> d[i];
  }
  for (int z = 1; z <= n; z++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        dist[i][j] = min(dist[i][j], dist[i][z] + dist[z][j]);
  for (int i = 1; i <= s; i++)
    for (int j = 1; j <= b; j++)
      if (dist[x[i]][y[j]] <= f[i] and a[i] >= d[j])
        flow.addEdge(i, 1000 + j, 1);
  cout << min(k * flow.max_flow(0, 2004), s * 1ll * h) << "\n";
}