Sometimes Sergey visits fast food restaurants. Today he is going to visit the one called PizzaKing.
Sergey wants to buy N meals, which he had enumerated by integers from 1 to N. He knows that the meal i costs Ci rubles. He also knows that there are M meal sets in the restaurant.
The meal set is basically a set of meals, where you pay Pj burles and get Qj meals - Aj, 1, Aj, 2, ..., Aj, Qj.
Sergey has noticed that sometimes he can save money by buying the meals in the meal sets instead of buying each one separately. And now he is curious about what is the smallest amount of rubles he needs to spend to have at least one portion of each of the meals.

-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a pair of integer numbers N and M denoting the number of meals and the number of the meal sets.
The second line contains N space-separated integers C1, C2, ..., CN denoting the costs of the meals, bought separately.
Each of the following M lines starts with a pair of integer numbers Pi and Qi, denoting the cost of the meal set and the number of meals in it, followed with the integer numbers Ai, 1 Ai, 2, ..., Ai, Qi denoting the meal numbers.

-----Output-----
For each test case, output a single line containing the minimal total amount of money Sergey needs to spend in order to have at least one portion of each meal.

-----Constraints-----
- 1 ≤ Pi, Ci ≤ 106
- 1 ≤ M ≤ min{2N, 2 × 100000}
- No meal appears in the set twice or more times.
- Subtask 1 (16 points): 1 ≤ T ≤ 103, 1 ≤ N ≤ 8
- Subtask 2 (23 points): For each test file, either 1 ≤ T ≤ 10, 1 ≤ N ≤ 12 or the constraints for Subtask 1 are held.
- Subtask 3 (61 points): For each test file, either T = 1, 1 ≤ N ≤ 18 or the constraints for Subtask 1 or 2 are held.

-----Example-----
Input:1
3 3
3 5 6
11 3 1 2 3
5 2 1 2
5 2 1 3

Output:10

-----Explanation-----
Example case 1. If Sergey buys all the meals separately, it would cost him 3 + 5 + 6 = 14 rubles. He can buy all of them at once by buying the first meal set, which costs for 11 rubles, but the optimal strategy would be either to buy the second and the third meal set, thus, paying 5 + 5 = 10 rubles, or to buy the third meal set and the second meal separately by paying the same amount of 10 rubles.

Source: codechef | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
T = int(input())
for t in range(T):
	(n, m) = list(map(int, input().split()))
	c = list(map(int, input().split()))
	dp1 = [1000000000.0] * ((1 << n) + 1)
	for i in range(n):
		dp1[1 << i] = c[i]
	dp1[1 << n - 1] = min(dp1[1 << n - 1], sum(c))
	for i in range(m):
		l = list(map(int, input().split()))
		cost = l[0]
		s = l[1]
		items = l[2:]
		mask = 0
		for j in items:
			mask = mask | 1 << j - 1
		dp1[mask] = min(dp1[mask], cost)
	for i in range((1 << n) - 1, -1, -1):
		for j in range(n):
			if i & 1 << j:
				dp1[i ^ 1 << j] = min(dp1[i ^ 1 << j], dp1[i])
	dp2 = [1000000000.0] * ((1 << n) + 1)
	dp2[0] = 0
	for i in range(1 << n):
		submask = i
		while submask > 0:
			dp2[i] = min(dp2[i], dp2[i ^ submask] + dp1[submask])
			submask = submask - 1 & i
	print(dp2[(1 << n) - 1])


author = 'himanshu malhotra'
(aa, bb) = (0, 0)
for _ in range(eval(input())):
	(n, m) = list(map(int, input().split()))
	li = list(map(int, input().split()))
	dp = [float('inf')] * ((1 << n) + 1)
	for i in range(n):
		dp[1 << i] = li[i]
	dp[1 << n - 1] = min(dp[1 << n - 1], sum(li))
	for i in range(m):
		q = list(map(int, input().split()))
		(cost, no, items) = (q[0], q[1], q[2:])
		mask = 0
		for j in items:
			mask |= 1 << j - 1
		dp[mask] = min(dp[mask], cost)
	for i in range((1 << n) - 1, -1, -1):
		for j in range(n):
			if i & 1 << j:
				dp[i ^ 1 << j] = min(dp[i ^ 1 << j], dp[i])
	ans = [float('inf')] * ((1 << n) + 1)
	ans[0] = 0
	for i in range(1 << n):
		submask = i
		while submask > 0:
			ans[i] = min(ans[i], dp[submask] + ans[i - submask])
			submask = submask - 1 & i
	print(ans[(1 << n) - 1])


T = int(input())
for test_cases in range(T):
	[N, M] = list(map(int, input().split(' ')))
	cost_single = list(map(int, input().split(' ')))

	class meal(object):

		def __init__(self, price, number, meal_list):
			self.cost = price
			self.num_meals = number
			self.meals = [0] * N
			for i in meal_list:
				self.meals[i - 1] = 1
			self.averageprice = price / number
	meal_sets = []
	for i in range(N):
		meal_sets.append(meal(cost_single[i], 1, [i + 1]))
	for i in range(M):
		line = input().split(' ')
		if int(line[0]) < sum((cost_single[j - 1] for j in map(int, line[2:]))):
			meal_sets.append(meal(int(line[0]), int(line[1]), list(map(int, line[2:]))))
	M = len(meal_sets) - N
	meal_sets = sorted(meal_sets, key=lambda meal_sets: meal_sets.averageprice)
	min_cost = [0]
	min_cost[0] = sum(cost_single)

	def selection(choice, index):
		this_cost = 0
		for i in range(N + M):
			this_cost += choice[i] * meal_sets[i].cost
		if this_cost >= min_cost[0]:
			return 0
		else:
			temp_list = []
			check_list = [0] * N
			for j in range(N + M):
				if choice[j] == 1:
					temp_list.append(meal_sets[j].meals)
			check = 1
			if temp_list:
				for j in range(N):
					check_list[j] = sum((row[j] for row in temp_list))
					if check_list[j] == 0:
						check = 0
						break
				if check == 1:
					min_cost[0] = this_cost
		if index == N + M - 2:
			selection(choice[0:index + 1] + [0], index + 1)
			selection(choice[0:index + 1] + [1], index + 1)
		elif index < N + M - 1:
			selection(choice[0:index + 1] + [0] + choice[index + 2:], index + 1)
			selection(choice[0:index + 1] + [1] + choice[index + 2:], index + 1)
	selection([0] * (N + M), 0)
	selection([1] + [0] * (N + M - 1), 0)
	print(min_cost[0])


INF = 5 * 10 ** 6

def solve():
	dp = [INF] * (1 << 18 + 1)
	(n, m) = list(map(int, input().split()))
	line = list(map(int, input().split()))
	for i in range(n):
		dp[1 << i] = line[i]
	for i in range(m):
		line = list(map(int, input().split()))
		c = line[0]
		mask = 0
		for j in range(line[1]):
			mask = mask | 1 << line[2 + j] - 1
		dp[mask] = min(dp[mask], c)
	mask = (1 << n) - 1
	while mask >= 0:
		for j in range(n):
			submask = mask & 1 << j
			if submask > 0:
				dp[mask ^ 1 << j] = min(dp[mask ^ 1 << j], dp[mask])
		mask -= 1
	for _ in range(1):
		for i in range(1 << n):
			submask = i - 1 & i
			while submask > 0:
				dp[i] = min(dp[i], dp[submask] + dp[i ^ submask])
				submask = submask - 1 & i
	print(dp[(1 << n) - 1])
t = eval(input())
for _ in range(t):
	solve()