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.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.StringTokenizer;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Andy Phan
 */
public class b2 {
    public static void main(String[] args) {
        FS in = new FS(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        int n = in.nextInt();
        int m = in.nextInt();
        
        int[][] shorty = new int[n][n];
        for(int[] arr : shorty) Arrays.fill(arr, 987654321);
        for(int i = 0; i < n; i++) shorty[i][i] = 0;
        for(int i = 0; i < m; i++) {
            int u = in.nextInt()-1;
            int v = in.nextInt()-1;
            shorty[u][v] = 1;
            shorty[v][u] = 1;
        }
        
        for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++)
                for(int k = 0; k < n; k++)
                    shorty[j][k] = Math.min(shorty[j][k], shorty[j][i]+shorty[i][k]);
        
        int s = in.nextInt();
        int b = in.nextInt();
        int k = in.nextInt();
        int h = in.nextInt();
        
        int[] x = new int[s];
        int[] a = new int[s];
        int[] f = new int[s];
        Dinic flow = new Dinic(s+b);
        for(int i = 0; i < s; i++) {
            x[i] = in.nextInt()-1;
            a[i] = in.nextInt();
            f[i] = in.nextInt();
            flow.add(flow.s, i, 1, 0);
        }
        
        for(int i = 0; i < b; i++) {
            int cX = in.nextInt()-1;
            int cD = in.nextInt();
            for(int j = 0; j < s; j++) {
                if(shorty[cX][x[j]] > f[j] || cD > a[j]) continue;
                flow.add(j, i+s, 1, 0);
            }
            flow.add(i+s, flow.t, 1, 0);
        }
        System.out.println(Math.min((long)flow.flow()*k, (long)h*s));
        out.close();
    }
    
    static class Dinic {

        static class Edge {

            int v1, v2, cap, flow;
            Edge rev;

            Edge(int V1, int V2, int Cap, int Flow) {
                v1 = V1;
                v2 = V2;
                cap = Cap;
                flow = Flow;
            }
        }

        ArrayDeque<Integer> q;
        ArrayList<Edge>[] adj;
        int n, s, t, oo = (int) 1E9;
        boolean[] blocked;
        int[] dist;

        public Dinic(int N) {
            n = N;
            s = n++;
            t = n++;
            blocked = new boolean[n];
            dist = new int[n];
            q = new ArrayDeque<Integer>();
            adj = new ArrayList[n];
            for (int i = 0; i < n; ++i) {
                adj[i] = new ArrayList<Edge>();
            }
        }
        // Specifying flow can represent minimum flow for circulation.

        void add(int v1, int v2, int cap, int flow) {
            Edge e = new Edge(v1, v2, cap, flow);
            Edge rev = new Edge(v2, v1, 0, 0);
            adj[v1].add(rev.rev = e);
            adj[v2].add(e.rev = rev);
        }

        //#
        // Only needed if you need remove function
        void remove(int v1, int v2) {
            Edge e;
            for (int i = 0; i < adj[v1].size(); i++) {
                e = adj[v1].get(i);
                if (e.v2 == v2 && e.cap != 0) {
                    adj[v1].remove(i--);
                }
            }

            for (int i = 0; i < adj[v2].size(); i++) {
                e = adj[v2].get(i);
                if (e.v2 == v1 && e.cap == 0) {
                    adj[v2].remove(i--);
                }
            }
        }
        //$

        boolean bfs() {
            q.clear();
            Arrays.fill(dist, -1);
            dist[t] = 0;
            q.add(t);

            while (!q.isEmpty()) {
                int node = q.poll();
                if (node == s) {
                    return true;
                }
                for (Edge e : adj[node]) {
                    if (e.rev.cap > e.rev.flow && dist[e.v2] == -1) {
                        dist[e.v2] = dist[node] + 1;
                        q.add(e.v2);
                    }
                }
            }
            return dist[s] != -1;
        }

        int dfs(int pos, int min) {
            if (pos == t) {
                return min;
            }
            int flow = 0;
            for (Edge e : adj[pos]) {
                int cur = 0;
                if (!blocked[e.v2] && dist[e.v2] == dist[pos] - 1 && e.cap - e.flow > 0) {
                    cur = dfs(e.v2, Math.min(min - flow, e.cap - e.flow));
                    e.flow += cur;
                    e.rev.flow = -e.flow;
                    flow += cur;
                }
                if (flow == min) {
                    return flow;
                }
            }
            blocked[pos] = flow != min;
            return flow;
        }

        int flow() {
            clear();
            int ret = 0;
            while (bfs()) {
                Arrays.fill(blocked, false);
                ret += dfs(s, oo);
            }
            return ret;
        }

        void clear() {
            for (ArrayList<Edge> edges : adj) {
                for (Edge e : edges) {
                    e.flow = 0;
                }
            }
        }
        // Convert the given graph into a graph to test for circulation

        Dinic circulation() {
            int[] delta = new int[n];
            for (int node = 0; node < n; ++node) {
                for (Edge e : adj[node]) {
                    if (e.cap > 0 && e.flow > 0) {
                        delta[e.v1] -= e.flow;
                        delta[e.v2] += e.flow;
                    }
                }
            }

            Dinic d = new Dinic(n);
            for (int i = 0; i < n; ++i) {
                if (delta[i] > 0) {
                    d.add(d.s, i, delta[i], 0);
                } else if (delta[i] < 0) {
                    d.add(i, d.t, -delta[i], 0);
                }
            }

            for (int node = 0; node < n; ++node) {
                for (Edge e : adj[node]) {
                    if (e.cap > 0 && e.cap - e.flow > 0) {
                        d.add(e.v1, e.v2, e.cap - e.flow, 0);
                    }
                }
            }

            return d;
        }

        /* Vertex cover on bipartite graph (L, R):
	Find nodes in S side of S/T min cut (bfs(); dist[i] == -1)
	L1 = L & S, L2 = L - S, R1 = R & S, R2 = R - S
	Let B be the set of vertices in R2 that have neighbors in L1
	C = L2 | R1 | B
	Maximum independent set is the complement nodes */
        //#
        ArrayList<Integer> vertexCover() {
            BitSet leftNodes = new BitSet();
            BitSet rightNodes = new BitSet();
            BitSet minCut = new BitSet();
            for (Edge e : adj[s]) {
                if (e.v1 == s) {
                    leftNodes.set(e.v2);
                }
            }
            for (Edge e : adj[t]) {
                if (e.v1 == t) {
                    rightNodes.set(e.v2);
                }
            }
            bfs();
            for (int i = 0; i < s; ++i) {
                if (dist[i] == -1) {
                    minCut.set(i);
                }
            }

            BitSet l1 = new BitSet();
            l1.or(leftNodes);
            l1.and(minCut);
            BitSet l2 = new BitSet();
            l2.or(leftNodes);
            l2.andNot(minCut);
            BitSet r1 = new BitSet();
            r1.or(rightNodes);
            r1.and(minCut);
            BitSet r2 = new BitSet();
            r2.or(rightNodes);
            r2.andNot(minCut);

            BitSet b = new BitSet();
            for (int bit = r2.nextSetBit(0); bit >= 0; bit = r2.nextSetBit(bit + 1)) {
                for (Edge e : adj[bit]) {
                    if (e.v1 == bit && l1.get(e.v2)) {
                        b.set(bit);
                        break;
                    }
                }
            }

            BitSet c = new BitSet();
            c.or(l2);
            c.or(r1);
            c.or(b);
            ArrayList<Integer> ret = new ArrayList<Integer>();
            for (int bit = c.nextSetBit(0); bit >= 0; bit = c.nextSetBit(bit + 1)) {
                ret.add(bit);
            }
            return ret;
        }//$
    }
    
    static class FS {

        BufferedReader in;
        StringTokenizer token;
        
        public FS(InputStream str) {
            in = new BufferedReader(new InputStreamReader(str));
        }
        
        public String next() {
            if (token == null || !token.hasMoreElements()) {
                try {
                    token = new StringTokenizer(in.readLine());
                } catch (IOException ex) {
                }
                return next();
            }
            return token.nextToken();
        }
        
        public int nextInt() {
            return Integer.parseInt(next());
        }
    }
}