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 JAVA):

Solution:
import java.io.*;
import java.util.*;
public class BB{
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.flush();out.close();
    }
    static class TaskE {
            final int max = 10000;
            final int maxs = 100010 , maxn = 110 , maxk = 1010;
              class ship{
                long F , S , T ; int I;
                ship(long b, long c, long d, int a){F = b; S = c; T = d; I = a;}
              }
              class base{
                long F, S;
                base(long a, long b){F = a; S = b;}
              }
            ArrayDeque<Integer> ad = new ArrayDeque<>();
            ArrayList<ship> ship[];
            ArrayList<base> base[];
            TreeSet<base> qbase[];
            boolean visit[] = new boolean[maxn];
            int d[] = new int[maxn];
            long ans[] = new long[maxs];
            long C[] = new long[maxs];

            int ja[][], c[], from[], to[];
    
           public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt() , m = in.nextInt();
            ja = new int[n + 1][]; c = new int[n + 1]; from = new int[m]; to = new int[m];
            for(int i = 0; i < m; i++){
                int u = in.nextInt(), v = in.nextInt();
                from[i] = u; to[i] = v;
                c[u]++; c[v]++;
            }
            for(int i = 0; i <= n; i++){
                ja[i] = new int[c[i]]; c[i] = 0;
            }
            for(int i = 0; i < m; i++){
                ja[from[i]][c[from[i]]++] = to[i];
                ja[to[i]][c[to[i]]++] = from[i];
            }

            int s = in.nextInt() , b = in.nextInt(), k =in.nextInt();
            ship = new ArrayList[n + 1];
            base = new ArrayList[n + 1];
            qbase = new TreeSet[n + 1];

            for(int i = 0; i <= n; i++){
                ship[i] = new ArrayList<>();
                base[i] = new ArrayList<>();
                qbase[i] = new TreeSet<>((A , B) -> A.F == B.F ? Long.compare(B.S , A.S) : Long.compare(A.F , B.F));
            }

            for(int i = 0; i < s;i ++){
                ship[in.nextInt()].add(new ship(in.nextInt() , in.nextInt(),C[i + 1] = in.nextInt(), i + 1));
            }

            for(int i = 0; i < b;i ++){
                base[in.nextInt()].add(new base(in.nextInt() , in.nextInt()));   
            }

            for(int i = 0; i <= n; i++){
                Collections.sort(ship[i] , (A , B) -> Long.compare(A.S , B.S));
            }
            for(int i = 0; i <=n; i++){
                Collections.sort(base[i] , (A , B) -> A.F == B.F ? Long.compare(B.S , A.S) : Long.compare(A.F , B.F));
                int sz = base[i].size();
                long max = 0;
                for(int j = 0; j < sz; j++){
                    base p = base[i].get(j);
                    p.S = Math.max(max , p.S);
                    max = p.S;
                    qbase[i].add(p);
                }
                base[i].clear();
            }
            Arrays.fill(ans, -1);
            for(int i = 1; i <= n; i++){
                int sz = ship[i].size();
                if(sz == 0) continue;
                int p = 0;
                Arrays.fill(visit , false); Arrays.fill(d , max); ad.clear();
                visit[i] = true; d[i] = 0; ad.add(i);
                o : while(!ad.isEmpty() && p < sz){
                    int u = ad.pollFirst(); 
                    ship pship = ship[i].get(p);
                    while(d[u] > pship.S && p < sz){
                        ++p; 
                        if(p == sz) break o;
                        pship = ship[i].get(p);
                    }
                    int szb = qbase[u].size();
                    for(int j = p; j < sz && szb > 0; j++){
                        pship = ship[i].get(j);
                        base P = qbase[u].floor(new base(pship.F, 0));
                        if(P == null)continue;
                        // System.out.println(i + " " + pship.I + " " + u + " " + P.S);
                        ans[pship.I] = Math.max(ans[pship.I] ,P.S);
                    }
                    for(int v : ja[u]){
                        if(visit[v])continue;
                        d[v] = d[u] + 1; visit[v] = true;
                        ad.addLast(v);
                    }
                }
            }

            // s + 1 + 1
            int S = 0, T = s + 1;
            DinicMaxFlow maxf = new DinicMaxFlow(T + 1, S, T);

            for(int i = 1; i <= s; i++){
                if(ans[i] == -1){
                    maxf.addEdge(i, T, Long.MAX_VALUE);
                }else{
                    if(ans[i] < C[i]){
                        maxf.addEdge(i, T, C[i] - ans[i]);
                    }else{
                        maxf.addEdge(S, i, ans[i] - C[i]);
                    }
                }
            }

            for(int i = 0; i < k; i++){
                int u = in.nextInt(), v = in.nextInt();
                maxf.addEdge(u, v, Integer.MAX_VALUE);
            }
            
            maxf.convertToArray();
            maxf.maxFlow();

            long rs = -maxf.maxflow;
            // System.out.println(rs);
            for(int i = 1; i <= s; i++){
                rs += Math.max(ans[i] - C[i], 0);
            }
            out.println(rs);
          }

      class DinicMaxFlow{
        class Edge{
            int F, T; long S;
            Edge(int a, long b, int c){
                F = a; S = b; T = c;
            }
        }
        final int max = Integer.MAX_VALUE;
        int N, S, T;
        long maxflow;
        Edge ja[][];
        ArrayList<Edge> al[];

        DinicMaxFlow(int nodes, int source, int sink){
            N = nodes; S = source; T = sink;
            al = new ArrayList[N];
            ja = new Edge[N][];
            maxflow = 0;
            for(int i = 0; i < N; i++){
                al[i] = new ArrayList<>();
            }
        }
        void addEdge(int u, int v, long cap){
            int su = al[u].size(), sv = al[v].size();
            al[u].add(new Edge(v, cap, sv));
            al[v].add(new Edge(u, 0, su));
        }
        void convertToArray(){
            for(int i = 0; i < N; i++){
                int sz = al[i].size();
                ja[i] = new Edge[sz];
                for(int j = 0; j < sz; j++){
                    ja[i][j] = al[i].get(j);
                }
                al[i].clear();
            }
        }
        ArrayDeque<Integer> ad = new ArrayDeque<>();
        int order[];
        boolean bfs(){
            order = new int[N]; ad.clear();
            Arrays.fill(order, - 1);
            order[S] = 0; ad.add(S);
            while(!ad.isEmpty()){
                int u = ad.pollFirst();
                for(Edge e : ja[u]){
                    if(e.S == 0 || order[e.F] != -1)continue;
                    order[e.F] = order[u] + 1;
                    ad.addLast(e.F);
                }
            }
            return order[T] != -1;
        }
        long dfs(int u, long bf){
            if(u == T)return bf;
            for(Edge e : ja[u]){
                if(order[e.F] != order[u] + 1 || e.S == 0)continue;
                long sf = Math.min(bf, e.S);
                long ef = dfs(e.F, sf);
                if(ef == 0)continue;
                e.S -= ef;
                ja[e.F][e.T].S += ef; 
                return ef;
            }
            return 0;
        }
        long maxFlow(){
            long flow;
            while(bfs()){
                while((flow = dfs(S, max)) != 0){
                    maxflow += flow;
                }
            }
            return maxflow;
        }
    }
}
    static class InputReader {
        BufferedReader br;
        StringTokenizer st;
        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}