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;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vpdd = vector<pdd>;
template <typename T>
void ckmin(T& a, const T& b) {
  a = min(a, b);
}
template <typename T>
void ckmax(T& a, const T& b) {
  a = max(a, b);
}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
namespace __input {
template <class T1, class T2>
void re(pair<T1, T2>& p);
template <class T>
void re(vector<T>& a);
template <class T, size_t SZ>
void re(array<T, SZ>& a);
template <class T>
void re(T& x) {
  cin >> x;
}
void re(double& x) {
  string t;
  re(t);
  x = stod(t);
}
template <class Arg, class... Args>
void re(Arg& first, Args&... rest) {
  re(first);
  re(rest...);
}
template <class T1, class T2>
void re(pair<T1, T2>& p) {
  re(p.first, p.second);
}
template <class T>
void re(vector<T>& a) {
  for (int i = 0; i < (int((a).size())); i++) re(a[i]);
}
template <class T, size_t SZ>
void re(array<T, SZ>& a) {
  for (int i = 0; i < (SZ); i++) re(a[i]);
}
}  // namespace __input
using namespace __input;
namespace __output {
template <class T1, class T2>
void pr(const pair<T1, T2>& x);
template <class T, size_t SZ>
void pr(const array<T, SZ>& x);
template <class T>
void pr(const vector<T>& x);
template <class T>
void pr(const set<T>& x);
template <class T1, class T2>
void pr(const map<T1, T2>& x);
template <class T>
void pr(const T& x) {
  cout << x;
}
template <class Arg, class... Args>
void pr(const Arg& first, const Args&... rest) {
  pr(first);
  pr(rest...);
}
template <class T1, class T2>
void pr(const pair<T1, T2>& x) {
  pr("{", x.first, ", ", x.second, "}");
}
template <class T>
void prContain(const T& x) {
  pr("{");
  bool fst = 1;
  for (const auto& a : x) pr(!fst ? ", " : "", a), fst = 0;
  pr("}");
}
template <class T, size_t SZ>
void pr(const array<T, SZ>& x) {
  prContain(x);
}
template <class T>
void pr(const vector<T>& x) {
  prContain(x);
}
template <class T>
void pr(const set<T>& x) {
  prContain(x);
}
template <class T1, class T2>
void pr(const map<T1, T2>& x) {
  prContain(x);
}
void ps() { pr("\n"); }
template <class Arg>
void ps(const Arg& first) {
  pr(first);
  ps();
}
template <class Arg, class... Args>
void ps(const Arg& first, const Args&... rest) {
  pr(first, " ");
  ps(rest...);
}
}  // namespace __output
using namespace __output;
namespace __io {
void setIn(string second) { freopen(second.c_str(), "r", stdin); }
void setOut(string second) { freopen(second.c_str(), "w", stdout); }
void setIO(string second = "") {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  if (int((second).size())) {
    setIn(second + ".in"), setOut(second + ".out");
  }
}
}  // namespace __io
using namespace __io;
template <typename F>
struct dinic {
  static const F inf = numeric_limits<F>::max();
  int V;
  vvi adj;
  vi dest;
  vector<F> cap;
  dinic(int V = 0) : V(V) { adj.resize(V); }
  void __arc(int u, int v, F c) {
    adj[u].push_back(dest.size());
    dest.push_back(v);
    cap.push_back(c);
  }
  void arc(int u, int v, F c) {
    __arc(u, v, c);
    __arc(v, u, F(0));
  }
  bool bfs(int second, int t, vi& level, vector<F>& flow) const {
    level = vi(V, -1);
    level[second] = 0;
    for (queue<int> q({second}); !q.empty(); q.pop()) {
      int u = q.front();
      for (int e : adj[u]) {
        if (level[dest[e]] == -1 && flow[e] < cap[e]) {
          level[dest[e]] = level[u] + 1;
          q.push(dest[e]);
        }
      }
    }
    return level[t] != -1;
  }
  F augment(int second, int t, vi& level, vector<F>& flow, vi& inx,
            F cur) const {
    if (second == t) return cur;
    for (int e; inx[second] < adj[second].size(); inx[second]++) {
      e = adj[second][inx[second]];
      if (level[dest[e]] != level[second] + 1) continue;
      if (flow[e] == cap[e]) continue;
      F incr =
          augment(dest[e], t, level, flow, inx, min(cur, cap[e] - flow[e]));
      if (incr > F(0)) {
        flow[e] += incr;
        flow[e ^ 1] -= incr;
        return incr;
      }
    }
    return F(0);
  }
  tuple<F, vector<F>> max_flow(int second, int t) const {
    assert(second != t);
    F res(0);
    vector<F> flow(cap.size());
    for (vi level; bfs(second, t, level, flow);) {
      for (vi inx(V, 0); F incr = augment(second, t, level, flow, inx, inf);)
        res += incr;
    }
    return make_tuple(res, flow);
  }
};
int main() {
  setIO();
  int N, M;
  re(N, M);
  vvi dist(N, vi(N, 1e9));
  for (int i = 0; i < (N); i++) dist[i][i] = 0;
  for (int i = 0; i < (M); i++) {
    int u, v;
    re(u, v);
    --u, --v;
    dist[u][v] = dist[v][u] = 1;
  }
  for (int k = 0; k < (N); k++)
    for (int i = 0; i < (N); i++)
      for (int j = 0; j < (N); j++) ckmin(dist[i][j], dist[i][k] + dist[k][j]);
  int S, B, K, H;
  re(S, B, K, H);
  vi sloc(S), atk(S), fuel(S);
  for (int second = 0; second < (S); second++)
    re(sloc[second], atk[second], fuel[second]), --sloc[second];
  vi bloc(B), def(B);
  for (int b = 0; b < (B); b++) re(bloc[b], def[b]), --bloc[b];
  const int SRC = 0, SHIPS = 1, BASES = SHIPS + S, SNK = BASES + B;
  dinic<int> g(SNK + 1);
  for (int second = 0; second < (S); second++) {
    g.arc(SRC, SHIPS + second, 1);
    for (int b = 0; b < (B); b++)
      if (atk[second] >= def[b] && dist[sloc[second]][bloc[b]] <= fuel[second])
        g.arc(SHIPS + second, BASES + b, 1);
  }
  for (int b = 0; b < (B); b++) g.arc(BASES + b, SNK, 1);
  int mf = get<0>(g.max_flow(SRC, SNK));
  ll ans = ll(mf) * K;
  for (int dummy = 0; dummy < (S + 1); dummy++) {
    ckmin(ans, ll(dummy) * H + ll(mf - max(0, dummy - (S - mf))) * K);
  }
  ps(ans);
  return 0;
}