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

 public class Main {
    public static void main(String[] args)  {

        InputReader in = new InputReader(System.in);
        OutputWriter out = new OutputWriter(System.out);
          int n = in.nextInt();
          int m = in.nextInt();
          int k = in.nextInt();
          HashMap<String,Integer>h = new HashMap<>();
          String[] names = new String[n];

          for (int i=0;i<n;i++) {
              names[i] = in.readString();
              h.put(names[i], i);
          }
          long[]costs = new long[n];
          for (int i =0;i<n;i++)
          {
              costs[i] = in.nextLong();
          }
          for (int i=0;i<m;i++)
          {
              int q = in.nextInt();
              long max=Integer.MAX_VALUE;
              int[] y = new int[q];
              for (int j=0;j<q;j++) {
                   y[j] = in.nextInt()-1;
                  max = Math.min(max,costs[y[j]]);

              }
              for (int j =0;j<q;j++)
                  costs[y[j]]= max;
          }
          long sum =0;
          for (int i =0;i<k;i++)
          {
              String s = in.readString();
              sum+=costs[h.get(s)];
          }
          out.printLine(sum);
        out.flush();

    }
     static void MergeSort(int[] a, int[] b, int[] c, int p, int r)
     {
         if (p < r)
         {
             int q = (r + p) / 2;
             MergeSort(a, b, c, p, q);
             MergeSort(a, b, c, q + 1, r);
             Merge(a, b, c, p, q, r);
         }
     }
     static void Merge(int[] a, int[] b, int[] c, int p, int q, int r)
     {
         int n1 = q - p + 1;
         int n2 = r - q;
         int[] R = new int[n1 + 1];
         int[] L = new int[n2 + 1];
         int[] R1 = new int[n1];
         int[] L1 = new int[n2];

         int[] R2 = new int[n1];
         int[] L2 = new int[n2];
         for (int i = 0; i < n1; i++)
         {
             R[i] = a[p + i];
             R1[i] = b[p + i];
             R2[i] = c[p + i];
         }
         R[n1] = Integer.MAX_VALUE;
         for (int i = 0; i < n2; i++)
         {
             L[i] = a[q + i + 1];
             L1[i] = b[q + i + 1];
             L2[i] = c[q + i + 1];
         }
         L[n2] =Integer.MAX_VALUE;
         int n = a.length;
         int j = 0;
         int k = 0;
         for (int i = p; i <= r; i++)
         {
             if (L[j] < R[k])
             {
                 a[i] = L[j];
                 b[i] = L1[j];
                 c[i] = L2[j];
                 j++;
             }
             else
             {
                 a[i] = R[k];
                 b[i] = R1[k];
                 c[i] = R2[k];
                 k++;
             }

         }
     }







}



class Graph {


    int n;
    LinkedList<Integer>[] adjList;

    public Graph(int n) {
        this.n = n;
        adjList = new LinkedList[n];
        for (int i = 0; i < n; i++)
            adjList[i] = new LinkedList<>();
    }

}


class InputReader {

    private final InputStream stream;
    private final byte[] buf = new byte[8192];
    private int curChar, snumChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (snumChars == -1)
            throw new InputMismatchException();
        if (curChar >= snumChars) {
            curChar = 0;
            try {
                snumChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (snumChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int nextInt() {
        int c = read();
        while (isSpaceChar(c)) {
            c = read();
        }
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public long nextLong() {
        int c = read();
        while (isSpaceChar(c)) {
            c = read();
        }
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public int[] nextIntArray(int n) {
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    public String readString() {
        int c = read();
        while (isSpaceChar(c)) {
            c = read();
        }
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public String nextLine() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isEndOfLine(c));
        return res.toString();
    }

    public boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    private boolean isEndOfLine(int c) {
        return c == '\n' || c == '\r' || c == -1;
    }

}

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object... objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }

    public void flush() {
        writer.flush();
    }

}