Problem: Mahmoud wants to send a message to his friend Ehab. Their language consists of n words numbered from 1 to n. Some words have the same meaning so there are k groups of words such that all the words in some group have the same meaning.

Mahmoud knows that the i-th word can be sent with cost ai. For each word in his message, Mahmoud can either replace it with another word of the same meaning or leave it as it is. Can you help Mahmoud determine the minimum cost of sending the message?

The cost of sending the message is the sum of the costs of sending every word in it.

Input

The first line of input contains integers n, k and m (1 ≤ k ≤ n ≤ 105, 1 ≤ m ≤ 105) — the number of words in their language, the number of groups of words, and the number of words in Mahmoud's message respectively.

The second line contains n strings consisting of lowercase English letters of length not exceeding 20 which represent the words. It's guaranteed that the words are distinct.

The third line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) where ai is the cost of sending the i-th word.

The next k lines describe the groups of words of same meaning. The next k lines each start with an integer x (1 ≤ x ≤ n) which means that there are x words in this group, followed by x integers which represent the indices of words in this group. It's guaranteed that each word appears in exactly one group.

The next line contains m space-separated words which represent Mahmoud's message. Each of these words appears in the list of language's words.

Output

The only line should contain the minimum cost to send the message after replacing some words (maybe none) with some words of the same meaning.

Examples

Input

5 4 4
i loser am the second
100 1 1 5 10
1 1
1 3
2 2 5
1 4
i am the second


Output

107

Input

5 4 4
i loser am the second
100 20 1 5 10
1 1
1 3
2 2 5
1 4
i am the second


Output

116

Note

In the first sample, Mahmoud should replace the word "second" with the word "loser" because it has less cost so the cost will be 100+1+5+1=107.

In the second sample, Mahmoud shouldn't do any replacement so the cost will be 100+1+5+10=116.

Solution (in JAVA):

Solution:

import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    
    private static final class FastScanner {
        private final InputStream is = System.in;
        private final byte[] buf = new byte[8192];
        private int curChar;
        private int numChars;
 
        public FastScanner() {
        }
 
        public int read() {
                if (this.numChars == -1) {
                        throw new InputMismatchException();
                }
                if (this.curChar >= this.numChars) {
                        this.curChar = 0;
                        try {
                                this.numChars = this.is.read(this.buf);
                        } catch (final IOException e) {
                                throw new InputMismatchException();
                        }
                        if (this.numChars <= 0) {
                                return -1;
                        }
                }
                return this.buf[this.curChar++];
        }
 
        public String nextLine() {
                int c;
                while (isSpaceChar(c = read())) {
                }
                final StringBuilder res = new StringBuilder();
                do {
                        res.appendCodePoint(c);
                } while (!isEndOfLine(c = read()));
                return res.toString();
        }
 
        public String nextString() {
                int c;
                while (isSpaceChar(c = read())) {
                }
                final StringBuilder res = new StringBuilder();
                do {
                        res.appendCodePoint(c);
                } while (!isSpaceChar(c = read()));
                return res.toString();
        }
 
        public long nextLong() {
                int c;
                while (isSpaceChar(c = read())) {
                }
                boolean f = true;
                if (c == '-') {
                        f = false;
                        c = read();
                }
                long res = 0;
                do {
                        /*if (c < '0' || c > '9') {
                                throw new InputMismatchException();
                        }*/
                        res = res * 10 + c - '0';
                } while ((c = read()) >= '0' && c <= '9');
                return f ? res : -res;
        }
 
        public int nextInt() {
                int c;
                while (isSpaceChar(c = read())) {
                }
                boolean f = true;
                if (c == '-') {
                        f = false;
                        c = read();
                }
                int res = 0;
                do {
                        /*if (c < '0' || c > '9') {
                                throw new InputMismatchException();
                        }*/
                        res = res * 10 + c - '0';
                } while ((c = read()) >= '0' && c <= '9');
                return f ? res : -res;
        }
 
        public double nextDouble() {
                return Double.parseDouble(nextString());
                // return FloatingDecimal.parseDouble(nextString());
        }
 
        public BigInteger nextBigInteger() {
                return new BigInteger(nextString(), 10);
        }
 
        public BigDecimal nextBigDecimal() {
                return new BigDecimal(nextString());
        }
 
        public int[] nextArray(final int n) {
                final int[] a = new int[n];
                for (int i = 0; i < n; i++) {
                        a[i] = nextInt();
                }
                return a;
        }
 
        public long[] nextLongArray(final int n) {
                final long[] a = new long[n];
                for (int i = 0; i < n; i++) {
                        a[i] = nextLong();
                }
                return a;
        }
 
        public char[] nextCharArray(final int n) {
                final char[] bf = new char[n];
                int b, p = 0;
                while (isSpaceChar(b = read())) {
                }
                while (p < n && !isSpaceChar(b)) {
                        bf[p++] = (char) b;
                        b = read();
                }
                return n == p ? bf : Arrays.copyOf(bf, p);
        }
 
        public char[][] nextMatrix(final int n, final int m) {
                final char[][] map = new char[n][];
                for (int i = 0; i < n; i++) {
                        map[i] = nextCharArray(m);
                }
                return map;
        }
 
        public int[][] nextIntMatrix(final int n, final int m) {
                final int[][] map = new int[n][];
                for (int i = 0; i < n; i++) {
                        map[i] = nextArray(m);
                }
                return map;
        }
 
        public long[][] nextLongMatrix(final int n, final int m) {
                final long[][] map = new long[n][];
                for (int i = 0; i < n; i++) {
                        map[i] = nextLongArray(m);
                }
                return map;
        }
 
        public boolean isSpaceChar(final int c) {
                return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
 
        public boolean isEndOfLine(final int c) {
                return c == '\n' || c == '\r' || c == -1;
        }
    }
        
    // static int[] arr1;
    static String[] arr2;
    static int[] arr3;
    
    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner();
        // BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        // StringTokenizer v;
        PrintWriter out = new PrintWriter(System.out);
        StringBuilder r = new StringBuilder();
        
        int n = in.nextInt();
        int k = in.nextInt();
        int m = in.nextInt();
        
        //arr1 = new int[n+1];
        arr2 = new String[n+1];
        arr3 = new int[n+1];
        
        for (int i = 1; i <= n; i++) {
            arr2[i] = in.nextString();
        }
        
        for (int i = 1; i <= n; i++) {
            arr3[i] = in.nextInt();
        }
        
        HashMap<Integer, Integer> map = new HashMap<>();
        HashMap<String, Integer> map2 = new HashMap<>();
        
        for (int i = 1; i <= k; i++) {
            
            int c = in.nextInt();
            
            int a = in.nextInt();
            //arr1[a] = i;
            map2.put(arr2[a], i);
            int min = arr3[a];
            
            for (int j = 1; j < c; j++) {
                a = in.nextInt();
                //arr1[a] = i;
                map2.put(arr2[a], i);
                if(arr3[a] < min) {
                    min = arr3[a];
                }
            }
            
            map.put(i, min);
        }
        
        // System.out.println(map);
        // System.out.println(map2);
        
        BigInteger sum = BigInteger.ZERO;
        for (int i = 0; i < m; i++) {
            String s = in.nextString();
            sum = sum.add(new BigInteger(map.get(map2.get(s))+""));
        }
        
        r.append(sum + "\n");
        
        out.print(r);
        out.flush();
        out.close();
    }
    
}