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 PYTHON3):

Solution:
from copy import deepcopy

class DSU:

	def __init__(self,n,cc):
		self.n = n
		self.par = list(range(self.n))
		self.size = [1 for i in range(self.n)]
		self.cost = cc

	def find(self,i):
		while(i != self.par[i]):
			self.par[i] = self.par[self.par[i]]
			i = self.par[i]
		return i

	def unite(self,a,b):
		par_a = self.find(a)
		par_b = self.find(b)
		if(par_a == par_b):
			return False
		else:
			# if(par_a <= par_b):
			# print('uniting:',par_a,par_b)
			# print(self.cost[par_a-1],self.cost[par_b-1])
			if(self.cost[par_a-1] <= self.cost[par_b-1]):
				self.par[par_b] = par_a
				self.size[par_a] += self.size[par_b]
				self.cost[par_b-1] = self.cost[par_a-1]
			else:
				self.par[par_a] = par_b
				self.size[par_b] += self.size[par_a]
				self.cost[par_a-1] = self.cost[par_b-1]
			return True

	def same(self,a,b):
		self.find(a)
		self.find(b)
		return self.par[a] == self.par[b]

	def size(self,a):
		return self.size[a]


def solve(words,d,r,cost,message,dsu,cc):
	n = len(words)
	# print('message:',message)
	# print('par:',dsu.par)
	minn = deepcopy(cc)
	# print(dsu.cost)
	minCost = 0
	for word in message:
		parA = dsu.find(d[word])
		# minCost += dsu.cost[d[word]-1]
		# print('->',parA)
		minCost += dsu.cost[parA-1]
	return minCost
	

n,k,m = list(map(int, input().split()))
words = list(map(str, input().split()))
cc = list(map(int, input().split()))
dsu = DSU(n+1,cc)
r,d = {},{}
cost = {}
for i in range(n):
	cost[i+1] = cc[i]
# print('cost:',cost)
for i in range(n):
	d[words[i]] = i+1
for i in d:
	r[d[i]] = i
# print('d:',d)
# print('r:',r)
for kk in range(k):
	ll = list(map(int, input().split()))
	if(ll[0] != 1):
		# print('ll:',ll)
		for i in range(1,ll[0]):
			dsu.unite(ll[i],ll[i+1])
			# print(i)
			# print(ll[i+1],ll[i])
message = list(map(str, input().split()))
print(solve(words,d,r,cost,message,dsu,cc))