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.IOException;
import java.math.BigInteger;
import java.util.*;
import java.io.*;

public class ll {
    public static void main(String[] args) throws Exception {
        gg g = new gg();
    }

}

class gg {
    ArrayList<Integer>[] g;
    PrintWriter pw;


    gg() throws Exception {
        //    FScanner fs = new FScanner(new FileReader("multimap.in"));
        //  pw = new PrintWriter("multimap.out");
        FScanner fs = new FScanner(new InputStreamReader(System.in));
        pw = new PrintWriter(System.out);
        int n = fs.nextInt(), k = fs.nextInt(), m = fs.nextInt();
        HashMap<String, Integer> res = new HashMap<>();
        ArrayList<String> arr = new ArrayList<>();
        for (int i = 0; i<n; i++) {
            arr.add(fs.nextToken());
        }
        for (int i = 0; i <n; i++) {
            res.put(arr.get(i), fs.nextInt());
        }
        for (int i = 0; i<k; i++) {
            int f = fs.nextInt();
            ArrayList<Integer> list = new ArrayList<>();
            for (int j = 0; j<f; j++) {
                list.add(fs.nextInt()-1);
            }
            int min = Integer.MAX_VALUE;
            for (int j =0; j<f; j++) {
                min = Math.min(min, res.get(arr.get(list.get(j))));
            }
            for (int j = 0; j<f; j++) {
                res.put(arr.get(list.get(j)), min);
            }
        }
        long ans = 0;
        for (int i =0 ; i<m; i++) {
            ans+=res.get(fs.nextToken());
        }
        pw.println(ans);
        pw.close();
    }

}

class List {
    Node start;
    int size = 0;

    void freeNode(Node that, Node x) {
        if (x.before == null && x.after == null) {
            that.last = null;
        } else if (x.before == null) {
            x.after.before = null;
        } else if (x.after == null) {
            x.before.after = null;
            that.last = x.before;
        } else {
            x.before.after = x.after;
            x.after.before = x.before;
        }
    }

    void addNode(Node that, Node x) {
        x.before = that.last;
        if (that.last != null)
            that.last.after = x;
        that.last = x;
    }

    void add(Node that, String key) {
        Node a = new Node();
        a.key = key;
        a.next = start;
        addNode(that, a);
        if (start != null)
            start.prev = a;
        start = a;
        size++;
    }

    Node get(String key) {
        if (start == null)
            return null;
        Node cur = start;
        while (!cur.key.equals(key))
            cur = cur.next;
        return cur;
    }

    boolean delete(Node that, String key) {
        Node cur = start;
        while (cur != null && !cur.key.equals(key)) {
            cur = cur.next;
        }
        if (cur == null)
            return false;
        else {
            freeNode(that, cur);
            if (cur == start) {
                if (size == 1) {
                    size = 0;
                    start = null;
                } else {
                    start = start.next;
                    start.prev = null;
                    size--;
                }
                return true;
            } else {
                if (cur.next == null) {
                    cur.prev.next = null;
                    size--;
                } else {
                    cur.prev.next = cur.next;
                    cur.next.prev = cur.prev;
                    size--;
                }
                return true;
            }
        }
    }

    boolean exists(String key) {
        Node cur = start;
        while (cur != null && !cur.key.equals(key)) {
            cur = cur.next;
        }
        if (cur == null)
            return false;
        else return true;
    }
}

class Node {
    String key;
    Node last;
    Node next, prev;
    Node after, before;
    List[] h;
}

class Pair implements Comparable<Pair> {
    long a;
    int x;

    Pair(long x1, int y1) {
        a = x1;
        a = y1;
    }

    @Override
    public int compareTo(Pair o) {
        if (a == o.a)
            return Integer.compare(x, o.x);
        else return Long.compare(a, o.a);
    }
}


class FScanner {
    StringTokenizer st;
    BufferedReader reader;

    FScanner(InputStreamReader isr) throws IOException {
        reader = new BufferedReader(isr);
    }

    String nextLine() throws IOException {
        return reader.readLine();
    }

    String nextToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            String s = reader.readLine();
            if (s == null)
                return null;
            st = new StringTokenizer(s);
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    char nextChar() throws IOException {
        return (char) reader.read();
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    int[] iarr(int n) throws IOException {
        int[] mas = new int[n];
        for (int i = 0; i < n; i++)
            mas[i] = nextInt();
        return mas;
    }

    double[] darr(int n) throws IOException {
        double[] mas = new double[n];
        for (int i = 0; i < n; i++)
            mas[i] = nextDouble();
        return mas;
    }

    char[][] cmas2(int n, int m) throws IOException {
        char[][] mas = new char[n][m];
        for (int i = 0; i < n; i++)
            mas[i] = nextLine().toCharArray();
        return mas;
    }

    long[] larr(int n) throws IOException {
        long[] mas = new long[n];
        for (int i = 0; i < n; i++)
            mas[i] = nextLong();
        return mas;
    }
}

class PairP implements Comparable<PairP> {
    double l, r;

    PairP(double l1, double r1) {
        l = l1;
        r = r1;
    }

    @Override
    public int compareTo(PairP o) {
        if (l == o.l)
            return Double.compare(r, o.r);
        else return Double.compare(l, o.l);
    }
}