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

public class Solution {
	public final static int MOD = 1000000007;
	public static int count = 0;
	public static int dx[] = {-1,1,0,0};
	public static int dy[] = {0,0,-1,1};
	public static int max = 0;
	public static LinkedList<Integer> adj[];
	@SuppressWarnings("unchecked")
	public static void main(String[] args) throws IOException {
		InputReader scan = new InputReader(System.in);
	   	OutputStream outputStream = System.out;
	   	PrintWriter pw = new PrintWriter(outputStream);
	   	StringBuilder sb = new StringBuilder();
	   	int n = scan.nextInt();
	   	int k = scan.nextInt();
	   	int m = scan.nextInt();
	   	String temp[] = new String[n];
	   	for(int i=0;i<n;i++)
	   		temp[i] = scan.next();
	   	int arr[] = new int[n];
	   	for(int i=0;i<n;i++)
	   		arr[i] = scan.nextInt();
	   	ArrayList<Integer> grp[] = new ArrayList[k];
	   	int min[] = new int[k];
	   	for(int i=0;i<k;i++)
	   	{
	   		grp[i] = new ArrayList<>();
	   		int size = scan.nextInt();
	   		int z = Integer.MAX_VALUE;
	   		for(int j=0;j<size;j++){
	   			int v = scan.nextInt()-1;
	   			grp[i].add(v);
	   			z = Math.min(z, arr[v]);
	   		}
	   		min[i] = z;
	   	}
		HashMap<String,Integer> hm = new HashMap<>();
	   	for(int i=0;i<m;i++)
	   	{
	   		String w = scan.next();
	   		if(hm.containsKey(w))
	   			hm.put(w, hm.get(w)+1);
	   		else
	   			hm.put(w, 1);
	   	}
	   	long cost = 0;
	   	for(int i=0;i<k;i++)
	   	{
	   		for(int j=0;j<grp[i].size();j++)
	   		{
	   			int z = grp[i].get(j);
	   			if(hm.containsKey(temp[z]))
	   				cost+=((long)(min[i])*hm.get(temp[z]));
	   		}
	   	}
	   	pw.println(cost);
	   	pw.close();  	
	}
	public static int find(int x,int parent[])
	{
		if(parent[x]!=x)
			parent[x] = find(parent[x],parent);
		return parent[x];
	}
	public static void union(int parent[],int x,int y)
	{
		int xParent = find(x,parent);
		int yParent = find(y,parent);
		parent[xParent] = yParent;
	}
	public static Node[][] graph(Node from[],Node to[],int n)
	{
		Node[][] g = new Node[n+1][];
		int count[] = new int[n+1];
		for(int i=0;i<from.length;i++)
			count[from[i].v]++;
		for(int i=0;i<=n;i++)
			g[i] = new Node[count[i]];
		Arrays.fill(count, 0);
		for(int i=0;i<from.length;i++)
			g[from[i].v][count[from[i].v]++] = to[i];
		return g;
	}
	public static int dfs(int node,int parent,int arr[],int k)
	{
		int max = 0,sec_max = 0;
		for(int i=0;i<adj[node].size();i++)
		{
			if(adj[node].get(i)!=parent){
				int t = dfs(adj[node].get(i),node,arr,k);
				if(max<t)
				{
					sec_max = max;
					max = t;
				}
				else if(sec_max<t)
					sec_max = t;
			}
		}
		if(arr[node]%k==0){
			count = Math.max(count, sec_max+max+1);
			return sec_max+max+1;
		}
		else
			return 0;
	}
	static class Pair{
		int i,j,p;
		Pair(int a,int b,int parent)
		{
			i = a;
			j = b;
			p = parent;
		}
	}
	public static void buildTree(int arr[],int tree[],int node,int start,int end)
	{
		if(start==end)
		{
			tree[node] = arr[start];
			return;
		}
		int mid = (start+end)/2;
		buildTree(arr,tree,2*node,start,mid);
		buildTree(arr,tree,2*node+1,mid+1,end);
		tree[node] = tree[2*node]+tree[2*node+1];
	}
	public static void update(int arr[],int tree[],int node,int inx,int val,int start,int end)
	{ 
		if(start==end)
		{
			tree[node] = val;
			arr[inx] = val;
			return;
		}
		int mid = (start+end)/2;
		if(inx<=mid)
			update(arr,tree,2*node,inx,val,start,mid);
		else
			update(arr,tree,2*node+1,inx,val,mid+1,end);
		tree[node] = tree[2*node]+tree[2*node+1];
	}
	public static int query(int tree[],int node,int l,int r,int start,int end)
	{
		if(r<start || l>end)
			return 0;
		if(l<=start && end<=r)
			return tree[node];
		int mid = (start+end)/2;
		int ans1 = query(tree,2*node,l,r,start,mid);
		int ans2 = query(tree,2*node+1,l,r,mid+1,end);
		return ans1+ans2;
	}
	public static void merge(int arr[],int start,int mid,int end)
	{
		int l = start, r = mid+1;
		int temp[] = new int[end-start+1];
		int k = 0;
		for(int i=start;i<=end;i++)
		{
			if(l>mid)
				temp[k++] = arr[r++];
			else if(r>end)
				temp[k++] = arr[l++];
			else if(arr[l]<=arr[r])
				temp[k++] = arr[l++];
			else{
				temp[k++] = arr[r++];
				count+=(mid-l+1);
			}
		}
		for(int i=0;i<k;i++)
			arr[start++] = temp[i];
	}
	public static void mergeSort(int arr[],int l,int r)
	{
		if(l<r){
			int mid = (l+r)/2;
			mergeSort(arr,l,mid);
			mergeSort(arr,mid+1,r);
			merge(arr,l,mid,r);
		}
	}
	public static void sieve(int spf[],int n)
	{
		for(int i=1;i<=n;i++)
			spf[i] = i;
		for(int i=2;i*i<=n;i++)
		{
			if(spf[i]==i)
			{
				for(int j=i;j<=n;j+=i)
					if(spf[j]==j)
						spf[j] = i;
			}
		}
	}
	public static void factors(int n,int spf[],ArrayList<Integer> factors)
	{
		int pre = 0;
		while(n!=1)
		{
			int temp = spf[n];
			if(temp!=pre)
			{
				factors.add(temp);
				pre = temp;
			}
			n/=temp;
		}
	}
	public static boolean isPrime(int n)
	{
		if(n==0 || n==1)
			return false;
		int limit = (int)Math.sqrt(n);
		for(int i=2;i<=limit;i++)
		{
			if(n%i==0)
				return false;
		}
		return true;
	}
	public static long pow(long a,long b,int m)
	{
		long result = 1;
		while(b>0)
		{
			if(b%2==1)
				result = ((result%m)*(a%m))%m;
			a = ((a%m)*(a%m))%m;
			b/=2;
		}
		return result;
	}
	public static long mulinv(long a,long m)
	{
		long arr[] = new long[2];
		long gcd = gcdExtended(a,m,arr);
		if(gcd==1)
			return (arr[0]%m+m)%m;
		else
			return Integer.MAX_VALUE;
	}
	public static long gcdExtended(long a,long b,long arr[])
	{
		if (a == 0)
	    {
	        arr[0] = 0;
	        arr[1] = 1;
	        return b;
	    }
	    long gcd = gcdExtended(b%a, a, arr);
	    long temp = arr[0];
	    arr[0] = arr[1] - (b/a) * arr[0];
	    arr[1] = temp;
	    return gcd;
	}
	public static long kadane(int items[])
	{
		int n = items.length;
		long max = (long)items[0];
		long curr_max = (long)items[0];
		for(int i=1;i<n;i++)
		{
			curr_max = Math.max((long)curr_max+items[i], items[i]);
			max = Math.max(max, curr_max);
		}
		return max;
	}
	public static long gcd(int a,int b)
	{
		if(a%b==0){
			return pow(2,a-1,MOD);
		}
		long ans = gcd(b,a%b);
		int len = 0;
		long ans1 = 0;
		while(len<a)
		{
			if(a-len-b<0)
			{
				ans = ans>>(len+b-a);
				ans1 = (ans1+ans)%MOD;
			}
			else
				ans1 = (ans1+(ans*pow(2,a-b-len,MOD))%MOD)%MOD;
			len+=b;
		}
		System.out.println(ans1);
		return ans1;
	}
	public static int LCS(String s1,String s2) //Longest common subsequence
	{
		int n = s1.length();
		int m = s2.length();
		int lcs[][] = new int[n+1][m+1];
		for(int i=0;i<=n;i++)
		{
			for(int j=0;j<=m;j++)
			{
				if(i==0 || j==0)
					lcs[i][j] = 0;
				else if(s1.charAt(i-1)==s2.charAt(j-1))
					lcs[i][j] = lcs[i-1][j-1] + 1;
				else
					lcs[i][j] = Math.max(lcs[i][j-1], lcs[i-1][j]);
			}
		}
		return lcs[n][m];
	}
	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }
 
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt()
        {
            return Integer.parseInt(next());
        }
 
        long nextLong()
        {
            return Long.parseLong(next());
        }
 
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
 
        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}
class InputReader {
    public BufferedReader reader;
	public StringTokenizer tokenizer;
    public InputReader(InputStream inputstream) {
        reader = new BufferedReader(new InputStreamReader(inputstream));
		tokenizer = null;
	}
    public String nextLine(){
        String fullLine=null;
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
		    try {
		        fullLine=reader.readLine();
		    } catch (IOException e) {
    			throw new RuntimeException(e);
    			}
        		return fullLine;
        }
		return fullLine;
	}
    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
    			tokenizer = new StringTokenizer(reader.readLine());
    		} catch (IOException e) {
        		throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
    public long nextLong() {
        return Long.parseLong(next());
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
}

class Node{
	int v, weight;
	Node(int d,int w)
	{
		v = d;
		weight = w;
	}
}
class NodeComparator implements Comparator<Node>
{

	@Override
	public int compare(Node arg0, Node arg1) {
		return Integer.compare(arg0.weight, arg1.weight);
	}
	
}