Lee just became Master in Codeforces, and so, he went out to buy some gifts for his friends. He bought $n$ integers, now it's time to distribute them between his friends rationally...

Lee has $n$ integers $a_1, a_2, \ldots, a_n$ in his backpack and he has $k$ friends. Lee would like to distribute all integers in his backpack between his friends, such that the $i$-th friend will get exactly $w_i$ integers and each integer will be handed over to exactly one friend.

Let's define the happiness of a friend as the sum of the maximum and the minimum integer he'll get.

Lee would like to make his friends as happy as possible, in other words, he'd like to maximize the sum of friends' happiness. Now he asks you to calculate the maximum sum of friends' happiness.


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases.

Next $3t$ lines contain test cases — one per three lines.

The first line of each test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5$; $1 \le k \le n$) — the number of integers Lee has and the number of Lee's friends.

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$) — the integers Lee has.

The third line contains $k$ integers $w_1, w_2, \ldots, w_k$ ($1 \le w_i \le n$; $w_1 + w_2 + \ldots + w_k = n$) — the number of integers Lee wants to give to each friend. 

It's guaranteed that the sum of $n$ over test cases is less than or equal to $2 \cdot 10^5$.


-----Output-----

For each test case, print a single integer — the maximum sum of happiness Lee can achieve.


-----Example-----
Input
3
4 2
1 13 7 17
1 3
6 2
10 10 10 10 11 11
3 3
4 4
1000000000 1000000000 1000000000 1000000000
1 1 1 1

Output
48
42
8000000000



-----Note-----

In the first test case, Lee should give the greatest integer to the first friend (his happiness will be $17 + 17$) and remaining integers to the second friend (his happiness will be $13 + 1$).

In the second test case, Lee should give $\{10, 10, 11\}$ to the first friend and to the second friend, so the total happiness will be equal to $(11 + 10) + (11 + 10)$

In the third test case, Lee has four friends and four integers, it doesn't matter how he distributes the integers between his friends.

Difficulty: MEDIUM
Tags: Sorting

Amortized analysis

Mathematics

Greedy algorithms
Skill types: Sorting

Amortized analysis

Greedy algorithms

Starter code:

Solutions:
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	E = 0
	d = 0
	arrow = k - 1
	a.sort(reverse=True)
	w.sort()
	for i in range(k):
		E += a[i]
	for i in range(k):
		if w[i] == 1:
			E += a[d]
			d += 1
		else:
			arrow += w[i] - 1
			E += a[arrow]
	print(E)


t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	co = w.count(1)
	a.sort(reverse=True)
	w.sort()
	ans = sum(a[:k]) + sum(a[:co])
	a = a[k:]
	c = -1
	for i in w:
		if i != 1:
			c = c + i - 1
			ans += a[c]
	print(ans)
	t -= 1


def solve():
	(n, k) = map(int, input().split())
	lst1 = list(map(int, input().split()))
	lst1.sort(reverse=True)
	ind = 0
	ans = 0
	lst2 = list(map(int, input().split()))
	lst2.sort()
	for i in range(k):
		lst2[i] -= 1
		if lst2[i] == 0:
			ans += lst1[ind]
		ans += lst1[ind]
		ind += 1
	lst2.sort()
	for i in lst2:
		if i != 0:
			ind += i - 1
			ans += lst1[ind]
			ind += 1
	print(ans)
for i in range(int(input())):
	solve()


for ii in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	w = [int(i) for i in input().split()]
	a.sort()
	ans = 0
	for i in range(k):
		ans += a[n - i - 1]
	double = 0
	index = []
	for i in w:
		if i == 1:
			double += 1
		else:
			index.append(i - 1)
	for i in range(double):
		ans += a[n - i - 1]
	if index == []:
		print(ans)
	else:
		index.sort()
		index.reverse()
		ans += a[0]
		index.pop()
		l = 0
		for i in index:
			l += i
			ans += a[l]
		print(ans)


from sys import stdin
from collections import deque
input = stdin.readline
T = int(input())
while T > 0:
	T -= 1
	(N, K) = [int(x) for x in input().split()]
	arr = sorted(list(map(int, input().split())))
	d = deque(arr)
	arr2 = list(reversed(sorted(list(map(int, input().split())))))
	res = 0
	for x in arr2:
		if x == 1:
			res += 2 * d[-1]
			d.pop()
	for x in arr2:
		if x == 1:
			continue
		res += d[0]
		res += d[-1]
		d.pop()
		for i in range(0, x - 1):
			d.popleft()
	print(res)


t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	W = list(map(int, input().split()))
	A.sort(reverse=True)
	W.sort()
	happy = 0
	for i in range(k):
		happy += A[i]
		W[i] -= 1
	j = 0
	if n == k:
		print(happy * 2)
	else:
		while W[j] == 0:
			happy += A[j]
			j += 1
		while i < n - 1:
			inc = W[j]
			i += inc
			happy += A[i]
			j += 1
		print(happy)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	w.sort(reverse=True)
	i = 0
	arr = [None] * k
	for j in range(k):
		if w[j] > 1:
			arr[j] = a[i]
			i += w[j] - 1
		else:
			break
	i = n - 1
	j = k - 1
	ans = 0
	while j >= 0:
		if arr[j] == None:
			ans += 2 * a[i]
		else:
			ans += arr[j] + a[i]
		i -= 1
		j -= 1
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	lst = list(map(int, input().split()))
	lst.sort(reverse=True)
	weight = list(map(int, input().split()))
	weight.sort()
	single = weight.count(1)
	ans = sum(lst[:k]) + sum(lst[:single])
	index = k
	for i in range(k):
		min_ele = weight[i] - 1
		if min_ele > 0:
			ans += lst[index + min_ele - 1]
			index = index + min_ele
	print(ans)


t = int(input())
ans = []
while t > 0:
	string = input()
	string = string.split(' ')
	nums = input()
	nums = nums.split(' ')
	array = []
	for i in range(len(nums)):
		array.append(int(nums[i]))
	chunks = input().split(' ')
	c = []
	for i in range(len(chunks)):
		c.append(int(chunks[i]))
	array = sorted(array)[::-1]
	c = sorted(c)
	currSum = 0
	start = 0
	end = len(array) - 1
	for i in range(len(c)):
		if c[i] == 1:
			currSum += array[i] * 2
		else:
			currSum += array[i]
		start += 1
	pos = len(c) - 1
	for i in range(len(c)):
		first = True
		while pos >= 0 and c[pos] - 1 > 0:
			if first:
				currSum += array[end]
			end -= 1
			c[pos] -= 1
			first = False
		pos -= 1
	ans.append(currSum)
	t -= 1
for ele in ans:
	print(ele)


import sys
ip = lambda : sys.stdin.readline().rstrip()
for _ in range(int(ip())):
	(n, k) = map(int, ip().split())
	a = sorted(map(int, ip().split()))
	w = list(map(int, ip().split()))
	b = []
	s = 0
	ans = 0
	for i in range(k):
		if w[i] == 1:
			ans += 2 * a.pop()
			w[i] = 0
		if w[i]:
			b.append(w[i])
	b.sort(reverse=True)
	(st, end) = (0, len(a) - 1)
	for i in b:
		ans += a[st] + a[end]
		st += i - 1
		end -= 1
	print(ans)


T = int(input())
while T > 0:
	(n, k) = map(int, input().split())
	integers = list(map(int, input().split()))
	w = list(map(int, input().split()))
	res = 0
	integers.sort(reverse=True)
	w.sort()
	index = 0
	people_index = -1
	for i in range(k):
		if w[i] == 1:
			res += 2 * integers[index]
			index += 1
			people_index = i
		else:
			break
	w = w[people_index + 1:]
	w.reverse()
	front_index = index
	back_index = n - 1
	for people in w:
		res += integers[front_index]
		res += integers[back_index]
		front_index += 1
		back_index -= people - 1
	print(res)
	T -= 1


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split() if i != '\n']
	w = [int(i) for i in input().split() if i != '\n']
	a.sort()
	w.sort(reverse=True)
	one = w.count(1)
	(ans, count) = (0, 0)
	while count < one:
		ans += 2 * a[-count - 1]
		count += 1
	(front, end) = (0, n - one - 1)
	for i in range(k):
		if w[i] > 1:
			ans += a[front] + a[end]
			end -= 1
			front += w[i] - 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	nlist = list(map(int, input().split()))
	klist = list(map(int, input().split()))
	nlist.sort()
	klist.sort()
	i = 0
	while i < k:
		if klist[i] != 1:
			break
		i += 1
	start = i
	ans = 0
	for i in range(n - 1, n - start - 1, -1):
		ans += nlist[i] * 2
	count = k - start
	for i in range(n - start - 1, n - start - count - 1, -1):
		ans += nlist[i]
	curr = 0
	for i in range(k - 1, start - 1, -1):
		ans += nlist[curr]
		curr += klist[i] - 1
	print(ans)


def solve():
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	w = sorted(list(map(int, input().split())), reverse=True)
	s = 0
	b = 0
	e = n - 1
	qq = w.count(1)
	s += sum(a[n - qq:]) * 2
	e -= qq
	for (i, wi) in enumerate(w):
		if wi == 1:
			break
		else:
			s += a[b] + a[e]
			e -= 1
			b += wi - 1
	print(s)
t = int(input())
for _ in range(t):
	solve()


z = input
w = int
m = sorted
for _ in range(w(z())):
	(n, k) = map(w, z().split())
	l = m(list(map(w, z().split())))[::-1]
	p = m(list(map(w, z().split())))
	(i, a) = (k - 1, l[:k])
	for j in range(k):
		if p[j] == 1:
			a[j] += a[j]
		else:
			i += p[j] - 1
			a[j] += l[i]
	print(sum(a))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	w = list(map(int, input().split()))
	w.sort(reverse=True)
	s = 0
	for i in w[::-1]:
		if i == 1:
			s += a[-1] * 2
			k -= 1
			a.pop()
			w.pop()
		else:
			break
	if len(a) != 0 and len(w) != 0:
		for i in w[::-1]:
			s += a[-1]
			a.pop()
		f = 0
		for i in w[::-1]:
			s += a[(f + i - 1) * -1]
			f += i - 1
	print(s)


from sys import stdin
for _ in [0] * int(input()):
	(a, k) = map(int, stdin.readline().rstrip().split(' '))
	l1 = list(map(int, stdin.readline().rstrip().split(' ')))
	l2 = list(map(int, stdin.readline().rstrip().split(' ')))
	l1.sort(reverse=True)
	l2.sort()
	s = 0
	for i in range(k):
		s += l1[i]
	la = k - 1
	for i in range(k):
		if l2[i] > 1:
			s += l1[la + l2[i] - 1]
			la = la + l2[i] - 1
		else:
			s += l1[i]
	print(s)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	b = list(map(int, input().split()))
	w = list(map(int, input().split()))
	w.sort()
	b.sort(reverse=True)
	c = b[k:]
	j = 0
	s = 0
	p = 0
	g = [0] * (n + 1)
	s += sum(b[:k])
	while j < k:
		if w[j] == 1:
			s += b[j]
		else:
			s += c[p + w[j] - 2]
			p += w[j] - 1
		j += 1
	print(s)


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
INF = 10 ** 10

def solve(n, k, a, w):
	a = sorted(a, reverse=True)
	w = sorted(w)
	ans = 0
	left = 0
	while left < k and w[left] == 1:
		ans += 2 * a[left]
		left += 1
	right = n - 1
	for i in range(k - 1, -1, -1):
		if w[i] <= 1:
			continue
		ans += a[left] + a[right]
		left += 1
		right -= w[i] - 1
	return ans

def main():
	for _ in range(ri()):
		(n, k) = ria()
		a = ria()
		w = ria()
		wi(solve(n, k, a, w))
main()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	li = list(map(int, input().split()))
	wi = list(map(int, input().split()))
	li.sort(reverse=True)
	wi.sort()
	sum = 0
	for i in range(k):
		if wi[i] == 1:
			sum += 2 * li[i]
		else:
			sum += li[i]
	j = 0
	for i in range(k):
		if wi[i] > 1:
			sum += li[k - 1 + wi[i] - 1 + j]
			j = j + wi[i] - 1
	print(sum)


from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

def input():
	return sys.stdin.readline()

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
for _ in range(int(input())):
	(n, k) = mapi()
	a = list(mapi())
	b = list(mapi())
	a.sort(reverse=True)
	b.sort()
	sm = 0
	bl = [[] for i in range(k)]
	for i in range(k):
		bl[i].append(a[i])
	i = k
	j = 0
	while i < n:
		while i < n and len(bl[j]) < b[j]:
			bl[j].append(a[i])
			i += 1
		j += 1
	for i in range(k):
		sm += min(bl[i]) + max(bl[i])
	print(sm)


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	(n, k) = map(int, stdin.readline().split())
	a = sorted(list(map(int, stdin.readline().split())))
	w = sorted(list(map(int, stdin.readline().split())))
	v = list()
	s = 0
	for i in range(k):
		v += ([a.pop()],)
		w[i] -= 1
	for i in range(k - 1, -1, -1):
		for j in range(w[i]):
			v[i] += (a.pop(0),)
	for i in range(k):
		s += v[i][0] + v[i][1] if len(v[i]) > 1 else v[i][0] << 1
	stdout.write(str(s) + '\n')


import os
import sys
from io import BytesIO, IOBase

def main():
	T = int(input())
	for _ in range(T):
		(n, k) = map(int, input().split())
		A = list(map(int, input().split()))
		W = list(map(int, input().split()))
		A.sort()
		W.sort(reverse=True)
		ans = 0
		ones = 0
		for w in W:
			if w == 1:
				ones += 1
		oneCheck = 0
		for _ in range(k):
			x = A.pop()
			if oneCheck < ones:
				ans += 2 * x
				oneCheck += 1
			else:
				ans += x
		i = 0
		for j in range(k):
			if i >= len(A):
				break
			ans += A[i]
			for _ in range(W[j] - 1):
				i += 1
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = lambda s: self.buffer.write(s.encode()) if self.writable else None

	def read(self):
		if self.buffer.tell():
			return self.buffer.read().decode('ascii')
		return os.read(self._fd, os.fstat(self._fd).st_size).decode('ascii')

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline().decode('ascii')

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

def print(*args, sep=' ', end='\n', file=sys.stdout, flush=False):
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(end)
	if flush:
		file.flush()
(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.setrecursionlimit(10000)
main()


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	W = list(map(int, input().split()))
	A.sort()
	W.sort()
	ans = 0
	i = len(A) - 1
	for x in W:
		ans += A[i]
		if x == 1:
			ans += A[i]
		i -= 1
	idx = 0
	for x in W[::-1]:
		if x > 1:
			ans += A[idx]
			idx += x - 1
	print(ans)


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 998244353

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]

def make(l):
	l1 = [[l[0], 1]]
	for i in range(1, len(l)):
		if l[i] == l1[-1][0]:
			l1[-1][1] += 1
		else:
			l1.append([l[i], 1])
	return l1[:]
for _ in range(val()):
	(n, k) = li()
	l1 = sorted(li(), reverse=1)
	l2 = sorted(li())
	l3 = []
	ones = 0
	for i in l2:
		if i and i != 1:
			l3.append(i)
		elif i == 1:
			ones += 1
	k = len(l3)
	ans = sum(l1[:ones]) * 2
	l1 = l1[ones:]
	ans += sum(l1[:k])
	l1 = l1[k:]
	ind = -1
	for i in l3:
		ind += i - 1
		ans += l1[ind]
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	w.sort(reverse=True)
	b = [0] * k
	d = [[] for i in range(k)]
	c = 0
	s = 0
	for i in range(k):
		b[k - i - 1] += 1
		d[k - i - 1].append(a[-1])
		s += a[-1]
		del a[-1]
	for i in range(n - k):
		if b[c] < w[c]:
			d[c].append(a[i])
			b[c] += 1
		else:
			c += 1
			d[c].append(a[i])
			b[c] += 1
	for i in d:
		s += min(i)
	print(s)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	w.sort()
	ans = 0
	start = m
	l = 0
	r = n - 1
	for i in range(m):
		if w[i] > 1:
			start = i
			break
		ans += a[l] * 2
		l += 1
	for d in range(m - 1, start - 1, -1):
		y = w[d]
		ans += a[l] + a[r]
		r = r - y + 1
		l += 1
	print(ans)


for test_i in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	w = list(map(int, input().split()))
	w.sort()
	l1 = 0
	while l1 < n:
		if w[l1] == 1:
			l1 += 1
		else:
			break
	ans = sum(arr[-1:-l1 - 1:-1]) + sum(arr[-1:-k - 1:-1])
	pos = 0
	for i in range(k - l1):
		ans += arr[pos]
		pos += w[-i - 1] - 1
	print(ans)


t = int(input())
while t != 0:
	t -= 1
	(n, k) = map(int, input().split())
	lt = [int(x) for x in input().split()]
	w = [int(x) for x in input().split()]
	lt.sort()
	w.sort(reverse=True)
	ans = 0
	ones = 0
	waux = []
	for i in w:
		if i == 1:
			ones += 1
		else:
			waux.append(i)
	if ones > 0:
		ans += 2 * sum(lt[-ones:])
	(i, j) = (0, n - 1 - ones)
	for p in range(len(waux)):
		ans += lt[i]
		ans += lt[j]
		aux = waux[p] - 2
		i += aux + 1
		j -= 1
	print(ans)


t = int(input())
for ty in range(t):
	(n, k) = list(map(int, input().split()))
	kp = list(map(int, input().split()))
	kp = sorted(kp)[::-1]
	rp = list(map(int, input().split()))
	rp = sorted(rp)
	sums = 0
	index = 0
	end = n - 1
	rl = 0
	for al in range(k):
		if rp[al] == 1:
			sums += 2 * kp[index]
			index += 1
	rp = rp[::-1]
	for al in range(k):
		if rp[al] != 1:
			sums += kp[index] + kp[end]
			index += 1
			end -= rp[al] - 1
	print(sums)


def Solve(ints, friends):
	ints.sort(reverse=True)
	friends.sort()
	listt = []
	for i in range(len(friends)):
		if friends[i] == 1:
			listt.append([ints[i]] * 2)
			friends[i] -= 1
			continue
		listt.append([ints[i]])
		friends[i] -= 1
	j = 0
	for i in range(len(friends), len(ints)):
		while friends[j] == 0 and j < len(friends):
			j += 1
		listt[j].append(ints[i])
		friends[j] -= 1
	maxx = 0
	for val in listt:
		maxx += max(val) + min(val)
	return maxx
T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	ints = list(map(int, input().split()))
	friends = list(map(int, input().split()))
	print(Solve(ints, friends))


from sys import stdin, stdout
cin = stdin.readline
cout = stdout.write
mp = lambda : list(map(int, cin().split()))
(t,) = mp()
for _ in range(t):
	(n, k) = mp()
	a = sorted(mp(), reverse=True)
	w = sorted(mp())
	summ = sum(a[:k])
	for i in range(k):
		w[i] -= 1
		if not w[i]:
			summ += a[i]
	m = k - 1
	for i in range(k):
		if w[i]:
			summ += a[m + w[i]]
			m += w[i]
	cout(str(summ) + '\n')


test = int(input())
for _ in range(test):
	(n, k) = [int(x) for x in input().split()]
	l = [int(x) for x in input().split()]
	w = [int(x) for x in input().split()]
	l.sort()
	w.sort()
	ans = 0
	x = -1 * w.count(1)
	if x != 0:
		ans = sum(l[x:])
		ans = ans * 2
		l = l[:x]
		x = -1 * x
		w = w[x:]
		k = k - x
	l.reverse()
	ans += sum(l[:k])
	pv = k - 1
	for i in range(len(w)):
		w[i] -= 1
		pv += w[i]
		ans += l[pv]
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	b.sort(reverse=True)
	a.sort()
	ans = []
	res = 0
	for i in range(m):
		t = a.pop()
		ans.append(t)
		res += t
	count = 0
	for i in range(m):
		if b[i] != 1:
			res += a.pop(0)
			c = b[i] - 2
			while c != 0:
				a.pop(0)
				c -= 1
		if b[i] == 1:
			count += 1
	for i in range(count):
		res += ans[i]
	print(res)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def instr():
	return str(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
from collections import Counter

def main():
	t = inp()
	for _ in range(t):
		(_, _) = inlt()
		aa = inlt()
		ww = inlt()
		aa = sorted(aa, reverse=True)
		ones = sum((w == 1 for w in ww))
		twos = sum((w == 2 for w in ww))
		others = len(ww) - ones - twos
		twos *= 2
		res = sum(aa[:ones]) * 2 + sum(aa[ones:ones + twos]) + sum(aa[ones + twos:ones + twos + others])
		ww = sorted(ww)
		idx = ones + twos + others - 1
		for w in ww[ones + twos // 2:]:
			idx += w - 1
			res += aa[idx]
		print(res)
main()


import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def get_str():
	return input().decode().strip()

def rint():
	return map(int, input().split())

def oint():
	return int(input())
t = oint()
for _ in range(t):
	(n, k) = rint()
	a = list(rint())
	w = list(rint())
	a.sort(reverse=True)
	w.sort()
	ans = 0
	ci = k
	ans += sum(a[:k])
	for i in range(k):
		l = w[i] - 1
		if l == 0:
			ans += a[i]
			continue
		ans += a[ci + l - 1]
		ci += l
	print(ans)


import sys
for _ in range(int(input())):
	sys.stdin.readline()
	item = map(int, sys.stdin.readline().split())
	friend = map(int, sys.stdin.readline().split())
	item = sorted(item)
	friend = sorted(friend)
	ans = sum(item[-len(friend):])
	one = 0
	for x in friend:
		if x == 1:
			one += 1
	if one > 0:
		ans += sum(item[-one:])
	i = 0
	for x in friend[::-1]:
		if x == 1:
			break
		x -= 1
		ans += item[i]
		i += x
	print(ans)


for u in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	ll = list(map(int, input().split()))
	ll.sort()
	l.sort(reverse=True)
	s = 0
	for i in range(k):
		if ll[i] == 1:
			s = s + l[i] * 2
			k = k - 1
		else:
			s = s + l[i]
	l = l[::-1]
	ll = ll[::-1]
	x = 0
	for i in range(k):
		if ll[i] > 1:
			s = s + l[x]
			x = x + ll[i] - 1
	print(s)


from collections import deque
from sys import stdin, stdout

def II():
	return int(stdin.readline())

def MI():
	return map(int, stdin.readline().split())

def LI():
	return list(map(int, stdin.readline().split()))
t = II()
for _ in range(t):
	(n, k) = MI()
	a = LI()
	a.sort()
	dq = deque(a)
	w = LI()
	cnt = 0
	x = []
	for i in w:
		if i == 1:
			cnt += 1
		else:
			x.append(i)
	(happiness, f, th) = (0, 0, 0)
	for i in range(cnt):
		f = dq.pop()
		th += 2 * f
	happiness += th
	x.sort(reverse=True)
	for i in x:
		f = dq.pop()
		l = dq.popleft()
		for j in range(i - 2):
			dq.popleft()
		happiness += f + l
	stdout.write(str(happiness) + '\n')


t = int(input())
while t:
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	w = list(map(int, input().split()))
	arr.sort(reverse=True)
	w.sort(reverse=True)
	singles = w.count(1)
	total = 0
	for i in range(singles):
		total += 2 * arr[i]
	j = n - 1
	for i in range(k - singles):
		total += arr[singles] + arr[j]
		singles += 1
		j = j - w[i] + 1
	print(total)
	t -= 1


from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))

def solve():
	(n, k) = get_tuple()
	values = get_list()
	numbers_req = get_list()
	numbers_req.sort(reverse=True)
	values.sort(reverse=True)
	cnt1 = numbers_req.count(1)
	numbers_req = [val - 1 for val in numbers_req if val > 1]
	ans = sum(values[:cnt1]) * 2 + sum(values[cnt1:k])
	j = n - 1
	for val in numbers_req:
		count = val
		if count > 0:
			ans += values[j]
			while count > 0:
				count -= 1
				j -= 1
	return ans

def main():
	print(solve())
TestCases = True
if TestCases:
	for i in range(get_int()):
		main()
else:
	main()


for i in range(int(input())):
	(n, k) = map(int, input().split())
	g = list(map(int, input().split()))
	f = list(map(int, input().split()))
	g.sort(reverse=True)
	f.sort(reverse=True)
	pos1 = f.count(1)
	sum1 = 0
	sum1 += 2 * sum(g[:pos1])
	rear = n - 1
	t = pos1
	for i in range(k - t):
		sum1 += g[pos1] + g[rear]
		pos1 += 1
		rear = rear - f[i] + 1
	print(sum1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	integers = list(map(int, input().split()))
	give = list(map(int, input().split()))
	integers.sort()
	give.sort(reverse=True)
	ones = 0
	for i in give:
		if i == 1:
			ones += 1
	start = 0
	end = n - 1
	happy = 0
	for i in range(ones):
		happy += 2 * integers[end]
		end -= 1
	for i in range(k - ones):
		happy += integers[end] + integers[start]
		start += give[i] - 1
		end -= 1
	print(happy)


import sys
import math
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	n = list(map(int, input().split()))
	w = list(map(int, input().split()))
	n.sort(reverse=True)
	w.sort()
	ans = 0
	for j in range(b):
		ans += n[j]
		if w[j] == 1:
			ans += n[j]
	ind = b - 1
	for j in range(b):
		if w[j] > 1:
			ind += w[j] - 1
			ans += n[ind]
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	w = list(map(int, input().split(' ')))
	a.sort()
	aux = 0
	ans = 0
	for i in range(k):
		if w[i] == 1:
			aux += 1
		w[i] -= 1
	for i in range(k):
		if aux != 0:
			ans += 2 * a[n - i - 1]
			aux -= 1
		else:
			ans += a[n - i - 1]
	ind = 0
	w.sort(reverse=True)
	for i in range(k):
		if w[i] != 0:
			ans += a[ind]
			ind += w[i]
	print(ans)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	w = [int(x) for x in input().split()]
	a.sort()
	w.sort()
	(res_max, res_min) = (0, 0)
	for x in range(n - 1, n - 1 - k, -1):
		res_max += a[x]
	now = 0
	cnt = 0
	for x in w:
		if x == 1:
			cnt += 1
	for x in range(n - 1, n - 1 - cnt, -1):
		res_min += a[x]
	cnt = k - cnt
	for x in w[::-1]:
		if cnt == 0:
			break
		res_min += a[now]
		now += x - 1
		cnt -= 1
	print(res_max + res_min)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = sorted(list(map(int, input().split())))
	w = sorted(list(map(int, input().split())), reverse=True)
	x = 0
	i = 0
	j = n - 1
	s = 0
	for z in range(k - 1, -1, -1):
		if w[z] == 1:
			s += 2 * l[j]
			j -= 1
		else:
			break
	for p in range(k):
		if w[p] == 1:
			break
		s += l[i] + l[j]
		j -= 1
		i += w[p] - 1
	print(s)


t = int(input())
for _ in range(t):
	hsum = 0
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	a.reverse()
	ones = 0
	for we in w:
		if we == 1:
			ones += 1
	hsum += sum(a[:ones]) * 2
	a = a[ones:]
	hsum += sum(a[:k - ones])
	a.reverse()
	w.sort()
	w = w[ones:]
	w.reverse()
	adders = []
	beg = 0
	for we in w:
		adders.append(beg)
		beg += we - 1
	for ad in adders:
		hsum += a[ad]
	print(hsum)


tc = int(input())
while tc > 0:
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	w = list(map(int, input().split()))
	w.sort()
	max_pos = 0
	min_pos = k
	ans = 0
	for i in w:
		max_pos += 1
		ans += a[-max_pos]
		if i > 1:
			min_pos += i - 1
			ans += a[-min_pos]
		else:
			ans += a[-max_pos]
	print(ans)
	tc -= 1


import math
import collections
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
import heapq as hq
setrecursionlimit(2 ** 20)
t = 1
t = int(stdin.readline())
for _ in range(t):
	(n, k) = list(map(int, stdin.readline().rstrip().split()))
	a = list(map(int, stdin.readline().rstrip().split()))
	w = list(map(int, stdin.readline().rstrip().split()))
	if n == k:
		print(2 * sum(a))
		continue
	f = 0
	l = n - 1
	ans = 0
	a.sort()
	w.sort()
	ptr = 0
	for ptr in range(k):
		if w[ptr] > 1:
			break
		ans += a[l]
		l -= 1
	l = n - 1
	for i in range(k):
		ans += a[l]
		l -= 1
	i = ptr
	while i < k:
		w[i] -= 1
		ans += a[l - w[i] + 1]
		l -= w[i]
		i += 1
	print(ans)


def check(integer, friends):
	friends.sort()
	integer.sort(reverse=True)
	m = 0
	a = 0
	b = len(friends) - 1
	for i in range(0, len(friends)):
		if friends[i] == 1:
			a += 1
	for i in range(0, a):
		m += integer[i]
	for i in range(0, len(friends)):
		m += integer[i]
	for i in range(0, len(friends)):
		if friends[i] - 1 > 0:
			b += friends[i] - 1
			m += integer[b]
	return m
c = int(input())
for i in range(0, c):
	a = list(map(int, input().split()))
	interger_n = a[0]
	friends_n = a[1]
	integer = list(map(int, input().split()))
	friends = list(map(int, input().split()))
	print(check(integer, friends))


import os
import sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split(' '))
		a = list(map(int, input().split(' ')))
		b = list(map(int, input().split(' ')))
		a.sort()
		b.sort()
		high = n - 1
		temp = [[] for x in range(k)]
		for x in range(k):
			temp[x].append(a[high])
			high -= 1
			b[x] -= 1
		b.sort()
		low = 0
		for x in range(k - 1, -1, -1):
			while b[x] > 0:
				temp[x].append(a[low])
				low += 1
				b[x] -= 1
		ans = 0
		for x in temp:
			ans += max(x) + min(x)
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
l = []
for i in range(t):
	(m, n) = list(map(int, input().split()))
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l.append([l1, l2])
for j in l:
	(ii, ans, r, l) = (len(j[1]), 0, len(j[0]) - 1, 0)
	j[0].sort(reverse=True)
	j[1].sort()
	for i in range(len(j[1])):
		if j[1][i] > 1:
			ii = i
			break
		else:
			ans += j[0][i] * 2
			l += 1
	for p in range(len(j[1]) - 1, ii - 1, -1):
		q = j[1][p]
		ans += j[0][r] + j[0][l]
		l += 1
		r = r - q + 1
	print(ans)


def find_happ(lst, w):
	happ = [[] for _ in range(len(w))]
	w = sorted(w)
	lst = sorted(lst, reverse=True)
	sm = sum(lst[:len(w)])
	i = len(w)
	j = 0
	while j < len(w):
		f = w[j] - 1
		if f > 0:
			sm += lst[i + f - 1]
			i += f
		else:
			sm += lst[j]
		j += 1
	return sm

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		lst = list(map(int, input().split()))
		w = list(map(int, input().split()))
		print(find_happ(lst, w))
main()


t = int(input())
while t:
	t = t - 1
	(n, k) = map(int, input().split())
	li = list(map(int, input().split()))
	li.sort()
	frnds_count_li = list(map(int, input().split()))
	frnds_count_li.sort()
	frnds_li = []
	for i in range(k):
		frnds_li.append([li.pop()])
		frnds_count_li[i] -= 1
	for (ind, count) in enumerate(frnds_count_li):
		x = count
		while x > 0:
			frnds_li[ind].append(li.pop())
			x -= 1
	sum = 0
	for i in frnds_li:
		sum += max(i)
		sum += min(i)
	print(sum)


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	(n, k) = I()
	l = sorted(I())
	f = sorted(I())
	an = 0
	i = n - 1
	j = 0
	while j < k:
		if f[j] == 1:
			an += 2 * l[i]
		else:
			an += l[i]
		f[j] -= 1
		i -= 1
		j += 1
	j = k - 1
	i = 0
	while j > -1:
		if f[j] != 0:
			an += l[i]
			i += f[j]
		j -= 1
	print(an)


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().strip().split()))
	list1 = list(map(int, input().strip().split()))
	list2 = list(map(int, input().strip().split()))
	list1.sort()
	list2.sort()
	list1.reverse()
	res = 0
	for i in range(len(list2)):
		if list2[i] == 1:
			res += 2 * list1[i]
		else:
			res += list1[i]
	list3 = []
	for i in range(len(list2), len(list1)):
		list3.append(list1[i])
	list1 = list3
	list1.reverse()
	list2.reverse()
	index = 0
	for i in range(len(list2)):
		if list2[i] == 1:
			break
		res += list1[index]
		index += list2[i] - 1
	print(res)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	l1 = list(map(int, input().split()))
	l1.sort()
	l.sort(reverse=True)
	sum1 = 0
	sum1 += sum(l[0:m])
	i1 = m - 1
	for i in range(len(l1)):
		if l1[i] > 1:
			sum1 += l[i1 + l1[i] - 1]
			i1 += l1[i] - 1
		else:
			sum1 += l[i]
	print(sum1)


t = int(input())
for _ in range(t):
	(n, k) = tuple(map(int, input().split()))
	a = sorted(list(map(int, input().split())), reverse=True)
	w = sorted(list(map(int, input().split())))
	ans = 0
	k -= 1
	for (i, el) in enumerate(w):
		if el == 1:
			ans += 2 * a[i]
		else:
			k += el - 1
			ans += a[i] + a[k]
	print(ans)


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
from collections import deque
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	z = list(map(int, input().split()))
	z.sort()
	l.sort(reverse=True)
	ans = sum(l[:k]) + sum(l[:z.count(1)])
	for i in z:
		if i != 1:
			k += i - 1
			ans += l[k - 1]
	print(ans)


import sys
input = sys.stdin.readline

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
for _ in range(int(input())):
	(n, k) = int_array()
	a = int_array()
	w = int_array()
	ans = 0
	x = w.count(1)
	a.sort()
	while x:
		ans += 2 * a.pop()
		x -= 1
	w.sort()
	i = 0
	j = len(a) - 1
	while w:
		x = w.pop()
		if x == 1:
			continue
		ans += a[j]
		ans += a[i]
		j -= 1
		i += x - 1
	print(ans)


TC = int(input())
for tc in range(TC):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	W = list(map(int, input().split()))
	A.sort(reverse=True)
	W.sort()
	result = 0
	pos = 0
	for i in range(K):
		if W[i] > 1:
			result += A[i]
		else:
			result += 2 * A[i]
		pos += 1
	pos -= 1
	for i in range(K):
		if W[i] > 1:
			result += A[pos + W[i] - 1]
			pos += W[i] - 1
	print(result)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [*map(int, input().split())]
	w = [*map(int, input().split())]
	a.sort()
	w.sort()
	ws = [[] for _ in range(len(w))]
	while len(a):
		for i in range(k):
			w[i] -= 1
			ws[i].append(a[-1])
			del a[-1]
		for i in range(k):
			while w[i] > 0:
				w[i] -= 1
				ws[i].append(a[-1])
				del a[-1]
	print(sum((max(i) + min(i) for i in ws)))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	w.sort()
	(ii, l, r) = (k, 0, n - 1)
	ans = 0
	for i in range(k):
		if w[i] > 1:
			ii = i
			break
		ans = ans + a[l] * 2
		l = l + 1
	for u in range(k - 1, ii - 1, -1):
		i = w[u]
		ans = ans + a[l] + a[r]
		r = r - i + 1
		l = l + 1
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	wrr = list(map(int, input().split()))
	wrr.sort()
	arr.sort()
	ans = 0
	for i in range(k):
		ans += arr[-1]
		wrr[i] -= 1
		if wrr[i] == 0:
			ans += arr[-1]
		arr.pop()
	i = 0
	j = 0
	wrr.sort(reverse=True)
	while i < len(arr) and j < len(wrr):
		if wrr[j] == 0:
			j += 1
		else:
			ans += arr[i]
			i += wrr[j]
			wrr[j] = 0
	print(ans)


def help():
	(n, k) = map(int, input().split(' '))
	arr = sorted(list(map(int, input().split(' '))))
	wi = sorted(list(map(int, input().split(' '))))
	toret = 0
	arr_done = n - 1
	arr_start = 0
	ot = 0
	for i in range(k):
		if wi[i] == 1:
			toret += arr[arr_done]
			toret += arr[arr_done]
			arr_done -= 1
			ot += 1
		elif wi[i] == 2:
			toret += arr[arr_done]
			arr_done -= 1
			toret += arr[arr_done]
			arr_done -= 1
			ot += 1
		else:
			curr = k - 1 - (i - ot)
			toret += arr[arr_start]
			arr_start += wi[curr] - 1
			toret += arr[arr_done]
			arr_done -= 1
	print(toret)
for _ in range(int(input())):
	help()


t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	li = [int(x) for x in input().split()]
	ppp = [int(x) for x in input().split()]
	li.sort()
	ppp.sort(reverse=True)
	sumi = 0
	count = 0
	for i in ppp:
		if i == 1:
			count = count + 1
			sumi = sumi + 2 * li.pop()
	for i in ppp:
		if i == 1:
			continue
		else:
			sumi = sumi + li.pop()
			sumi = sumi + li.pop(0)
			for k in range(0, i - 2):
				li.pop(0)
	print(sumi)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	w.sort()
	r = len(a) - 1
	ans = 0
	new_w = []
	for i in w:
		if i == 1:
			ans += a[r] * 2
			r -= 1
			a.pop()
		else:
			new_w.append(i)
	new_w.sort(reverse=True)
	l = 0
	if r != -1:
		for i in new_w:
			ans += a[r]
			r -= 1
			ans += a[l]
			l += i - 1
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	wrr = list(map(int, input().split()))
	one = 0
	wrr.sort()
	arr.sort(reverse=True)
	ind = 0
	ans = 0
	for i in wrr:
		if i == 1:
			ans += 2 * arr[ind]
			ind += 1
		else:
			ans += arr[ind]
			ind += 1
	for i in wrr:
		if i != 1:
			co = i - 1
			while co > 1:
				ind += 1
				co -= 1
			mini = arr[ind]
			ind += 1
			ans += mini
	print(ans)


T = int(input())
for i in range(0, T):
	(N, K) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	Li = list(map(int, input().split()))
	Li.sort()
	A.sort()
	A.reverse()
	mark_f = 1
	mark_b = K
	ans = 0
	for j in range(0, K):
		if Li[j] == 1:
			ans += A[mark_f - 1]
			ans += A[mark_f - 1]
			mark_f += 1
		else:
			ans += A[mark_f - 1]
			ans += A[mark_b + Li[j] - 2]
			mark_f += 1
			mark_b += Li[j] - 1
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = sorted(map(int, input().split()))[::-1]
	w = sorted(map(int, input().split()))
	f = w.count(1)
	ans = sum(s[:k]) + sum(s[:f])
	for i in w[f:]:
		k += i - 1
		ans += s[k - 1]
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l1.sort()
	l2.sort(reverse=True)
	l3 = []
	s = 0
	for i in range(m):
		x = l1.pop()
		s += x
		l3.append(x)
	c = 0
	for i in range(m):
		if l2[i] == 1:
			c += 1
		else:
			s += l1.pop(0)
			c = l2[i] - 2
			while c:
				l1.pop(0)
				c -= 1
	for i in range(c):
		s += l3[i]
	print(s)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort(reverse=True)
	b.sort()
	ans = sum(a[:k])
	c = b.count(1)
	ans += sum(a[:c])
	for i in b[c:]:
		k += i - 1
		ans += a[k - 1]
	print(ans)


import math
import os
import random
import re
import sys
import collections

def solve():
	for _ in range(int(input())):
		(n, k) = map(int, input().strip().split())
		l = list(map(int, input().strip().split()))
		dis = list(map(int, input().strip().split()))
		dis.sort()
		s = [0] * k
		l.sort(reverse=True)
		for i in range(k):
			s[i] += l[i]
		l = l[k:]
		j = 0
		for i in range(k):
			if dis[i] > 1:
				j += dis[i] - 2
				if i == k - 1:
					s[i] += l[-1]
					break
				s[i] += l[j]
				j += 1
			else:
				s[i] = s[i] * 2
		print(sum(s))
solve()


t = int(input())
for test in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	w.sort()
	tot = sum(a[:k])
	ind = 0
	while ind < len(w) and w[ind] == 1:
		tot += a[ind]
		ind += 1
	val = k
	for i in range(ind, len(w)):
		val += w[i] - 2
		tot += a[val]
		val += 1
	print(tot)


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	W = list(map(int, input().split()))
	W.sort()
	A.sort(reverse=True)
	ANS = [[] for i in range(k)]
	ind = 0
	for i in range(k):
		ANS[i].append(A[ind])
		ind += 1
		W[i] -= 1
	for i in range(k):
		while W[i]:
			ANS[i].append(A[ind])
			ind += 1
			W[i] -= 1
	L = 0
	for ans in ANS:
		L += max(ans) + min(ans)
	print(L)


t = int(input())
for s in range(t):
	(n, m) = map(int, input().split())
	array = sorted(list(map(int, input().split())))
	rama = sorted(list(map(int, input().split())))
	array = array[::-1]
	add = 0
	for i in range(m):
		add += array[i]
	i = m
	visited = [array[i] for i in range(m)]
	for j in range(m):
		if rama[j] == 1:
			add += visited[j]
		else:
			q = i + rama[j] - 2
			add += array[q]
			i = q + 1
	print(add)


import sys
import math
from collections import defaultdict

def solve(test):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	left = 0
	for j in range(k):
		if w[j] > 1:
			left += 1
		w[j] -= 1
	ans = sum(a[:k]) + sum(a[:k - left])
	w.sort(reverse=True)
	a = a[::-1]
	res = 0
	idx = 0
	for j in range(left):
		res += a[idx]
		idx += w[j]
	ans += res
	print(ans)
test_cases = int(input())
for t in range(1, test_cases + 1):
	solve(t)


t = int(input())
for test in range(0, t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	a = input().split()
	w = input().split()
	for i in range(0, n):
		a[i] = int(a[i])
		if i < k:
			w[i] = int(w[i])
	a.sort()
	w.sort()
	one = 0
	ans = 0
	for i in range(0, len(w)):
		if w[i] == 1:
			ans += 2 * a[len(a) - 1]
			a.pop()
			one += 1
		else:
			break
	s = 0
	l = len(a) - 1
	for i in range(len(w) - 1, one - 1, -1):
		ans += a[s] + a[l]
		s += w[i] - 1
		l -= 1
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	nums = list(map(int, input().split()))
	gifts = list(map(int, input().split()))
	ans = 0
	gifts.sort()
	nums.sort()
	answers = [[] for _ in range(k)]
	for i in range(k):
		if gifts[i] == 1:
			answers[i] = [nums.pop(-1)]
			gifts[i] = 0
		else:
			answers[i] = [nums.pop(-1)]
			gifts[i] -= 1
	for i in range(k):
		for j in range(gifts[i]):
			answers[i].append(nums.pop(-1))
	for g in answers:
		ans += max(g) + min(g)
	print(ans)


list_ans = []
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	list1 = list(map(int, input().split()))
	list2 = list(map(int, input().split()))
	list1.sort(reverse=True)
	list2.sort()
	for i in range(k):
		if list2[i] >= 3:
			list2 = list2[:i] + list2[i:][::-1]
			break
	ans = 0
	a = b = 0
	for i in range(k):
		x = list2[i]
		if x == 1:
			ans += list1[a] * 2
			a += 1
		elif x == 2:
			ans += list1[a] + list1[a + 1]
			a += 2
		else:
			ans += list1[a] + list1[-1 - b]
			a += 1
			b += x - 1
	list_ans.append(ans)
print(*list_ans, sep='\n')


for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	w = [int(x) for x in input().split()]
	a.sort()
	w.sort()
	j = -1
	summ = 0
	for i in range(k):
		summ += a[j]
		if w[i] == 1:
			summ += a[j]
		j -= 1
	j = 0
	for wk in w[::-1]:
		if wk > 1:
			summ += a[j]
		j += wk - 1
	print(summ)


t = int(input())
while t > 0:
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	arr1 = input().split()
	arr1 = [int(i) for i in arr1]
	arr2 = input().split()
	arr2 = [int(i) for i in arr2]
	arr1.sort()
	arr2.sort()
	sum1 = 0
	x = 0
	y = len(arr1) - 1
	arrmin = arr1[0:n - k]
	arrmax = arr1[n - k:n]
	x = len(arrmin) - 1
	y = len(arrmax) - 1
	for i in range(k):
		if arr2[i] == 1:
			sum1 += 2 * arrmax[y]
			y -= 1
		else:
			sum1 += arrmax[y]
			temp = arr2[i] - 2
			if temp >= 1:
				x -= temp
			sum1 += arrmin[x]
			x -= 1
			y -= 1
	print(sum1)
	t -= 1


for i in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	w = list(map(int, input().split()))
	w.sort()
	l.sort(reverse=True)
	ans = 0
	for i in range(k):
		if w[i] > 1:
			w[i] -= 1
			ans += l[i]
		else:
			w[i] -= 1
			ans += 2 * l[i]
	w.sort(reverse=True)
	l.sort()
	j = 0
	for i in range(k):
		if w[i] > 0:
			ans += l[j]
			j += w[i]
	print(ans)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	krr = list(map(int, input().split()))
	arr.sort()
	krr.sort()
	j = n - 1
	ans = 0
	l = 0
	begin = 0
	for i in range(k):
		if krr[i] == 1:
			ans += 2 * arr[j]
			j -= 1
			krr[i] = 0
			begin = i + 1
		elif krr[i] == 2:
			ans += arr[j] + arr[j - 1]
			j -= 2
			krr[i] = 0
			begin = i + 1
		else:
			ans += arr[j]
			krr[i] -= 1
			j -= 1
	for i in range(k - 1, begin - 1, -1):
		ans += arr[l]
		l += krr[i]
	print(ans)


from sys import stdin, stdout
import math
import collections
input = stdin.readline

def print(x='', end='\n'):
	stdout.write(str(x) + end)

def solve():
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	a = list(map(int, input().split()))
	a.sort()
	l.sort()
	(cur, st) = (0, 0)
	ans = 0
	a = collections.deque(a)
	while a and a[0] == 1:
		ans += 2 * l[-1]
		l.pop()
		a.popleft()
	a = list(a)
	a.sort(reverse=True)
	cur = 0
	a = collections.deque(a)
	l = collections.deque(l)
	while a:
		temp = a[0]
		ans += l.pop() + l.popleft()
		temp -= 2
		while temp != 0:
			temp -= 1
			l.popleft()
		a.popleft()
		cur += 1
	print(ans)
tt = 1
tt = int(input())
for __ in range(tt):
	solve()


def main():
	(n, k) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	w = list(map(int, input().split(' ')))
	a.sort()
	w.sort()
	w.reverse()
	s = 0
	i = 0
	for j in range(k):
		if w[j] > 1:
			s += a[i]
			i += w[j] - 1
	for j in range(k):
		s += a[i]
		if w[j] == 1:
			s += a[i]
		i += 1
	return s
for _ in range(int(input())):
	print(main())


import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	b.sort()
	a.sort()
	ans = 0
	j = 0
	i = n - 1
	z = k - 1
	m = 0
	while 1:
		if b[j] == 1:
			ans += 2 * a[i]
			i -= 1
			j += 1
			if j == k:
				break
		else:
			ans += a[i] + a[m]
			m = m + (b[z] - 1)
			i -= 1
			z -= 1
			if z < j:
				break
	su = 0
	print(ans)


def modinv(n, p):
	return pow(n, p - 2, p)

def main():
	for case in range(int(input())):
		(n, k) = [int(x) for x in input().split()]
		arr = [int(x) for x in input().split()]
		weights = [int(x) for x in input().split()]
		arr.sort(reverse=True)
		weights.sort(reverse=True)
		ans = 0
		new_weights = []
		c = 0
		for w in weights:
			if w == 1:
				c += 1
			else:
				new_weights.append(w)
		ans += 2 * sum(arr[:c])
		arr = arr[c:]
		for w in new_weights:
			ans += arr[0]
			ans += arr[-1]
			arr.pop(0)
			t = w - 1
			while t > 0:
				arr.pop(-1)
				t -= 1
		print(ans)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from collections import deque
t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort(reverse=True)
	b.sort(reverse=True)
	q = deque()
	for i in range(n):
		q.append(a[i])
	ans = []
	for i in range(k):
		ans.append([])
	for i in range(k):
		for j in range(1, b[i]):
			ans[i].append(q[-1])
			q.pop()
	for i in range(k):
		ans[i].append(q[-1])
		q.pop()
	total = 0
	for i in range(k):
		total += max(ans[i]) + min(ans[i])
	print(total)


T = int(input())
for test in range(T):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	w.sort()
	cur = 0
	ans = 0
	cnt = k - 1
	left = n - 1
	while cur < k and w[cur] == 1:
		ans += 2 * a[cur]
		cur += 1
	rest = k - cur
	for i in range(rest):
		ans += a[cur + i]
		ans += a[left]
		left -= w[cnt] - 1
		cnt -= 1
	print(ans)


from collections import *
from sys import *
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	w = list(map(int, input().split()))
	w.sort(reverse=True)
	sn = 0
	d = deque(a)
	cn = 0
	i = 0
	while i < len(w):
		k = w[i] - 1
		if k == 0:
			sn += 2 * d[-1]
			d.pop()
			i += 1
			continue
		sn += d[0]
		cn += 1
		while k > 0:
			d.popleft()
			k -= 1
		i += 1
	a = list(d)
	for i in a:
		sn += i
	stdout.write(str(sn) + '\n')


t = int(input())
for case in range(t):
	(n, k) = list(map(int, input().split(' ')))
	a = list(map(int, input().split(' ')))
	w = list(map(int, input().split(' ')))
	a.sort()
	w.sort(reverse=True)
	result = 0
	last_big = n - 1
	try:
		first_one_in_w = w.index(1)
	except:
		first_one_in_w = -1
	if first_one_in_w != -1:
		result += sum(a[n - (k - first_one_in_w):]) * 2
		last_big = n - (k - first_one_in_w) - 1
		w = w[:first_one_in_w]
	if len(w) == 0:
		print(result)
	else:
		smallest_index = 0
		biggest_index = last_big
		result += a[smallest_index] + a[biggest_index]
		for index in range(len(w) - 1):
			smallest_index += w[index] - 1
			biggest_index -= 1
			result += a[smallest_index] + a[biggest_index]
		print(result)


import sys
import math

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
t = II()
for q in range(t):
	(n, k) = MI()
	a = sorted(LI())[:][::-1]
	w = sorted(LI())[:][::-1]
	l = w.count(1)
	r = n - 1
	s = 2 * sum(a[:l])
	for i in range(k):
		if w[i] == 1:
			break
		else:
			s += a[l] + a[r]
			l += 1
			r -= w[i] - 1
	print(s)


from sys import stdin, stdout
n = int(stdin.readline())
for i in range(n):
	(a, c) = map(int, stdin.readline().split())
	gifts = [int(i) for i in stdin.readline().split()]
	ppl = [int(i) for i in stdin.readline().split()]
	gifts.sort()
	b = -1
	ans = 0
	indx = 0
	ppl.sort()
	no1 = 0
	something = False
	for i in ppl:
		if i == 1:
			ans += gifts[b] * 2
			b -= 1
			no1 += 1
			if abs(b) == len(ppl) + 1:
				something = True
				break
		else:
			ppl = ppl[no1:]
			ppl.reverse()
			break
	if something:
		stdout.write(str(ans) + '\n')
		continue
	for i in ppl:
		ans += gifts[indx] + gifts[b]
		indx += i - 1
		b -= 1
	stdout.write(str(ans) + '\n')


import sys
input = lambda : sys.stdin.readline().strip()
t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	adj = [[] for _ in range(k)]
	a.sort()
	w.sort()
	i = 0
	for i in range(k):
		adj[i].append(a.pop())
		w[i] -= 1
	for i in range(k):
		while w[i] > 0:
			adj[i].append(a.pop())
			w[i] -= 1
	ans = 0
	for i in range(k):
		ans += min(adj[i]) + max(adj[i])
	print(ans)


import sys
input = sys.stdin.readline
for T in range(int(input())):
	(n, m) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	lis = list(map(int, input().split()))
	lis.sort(reverse=True)
	arr.sort(reverse=True)
	cnt = lis.count(1)
	i = cnt
	e = n - 1
	res = 2 * sum(arr[:i])
	for j in range(len(lis) - cnt):
		res += arr[i] + arr[e]
		i += 1
		e = e - lis[j] + 1
	print(res)


t = int(input())
for qu in range(t):
	(n, k) = map(int, input().split())
	a = sorted([int(i) for i in input().split()])
	w = sorted([int(i) for i in input().split()], reverse=True)
	(l, r) = (0, n - 1)
	ans = 0
	for i in range(k):
		if w[i] == 1:
			ans += 2 * a[r]
			r -= 1
	for i in range(k):
		if w[i] == 2:
			ans += a[r] + a[r - 1]
			r -= 2
	for i in range(k):
		if w[i] > 2:
			ans += a[r] + a[l]
			r -= 1
			l += w[i] - 1
	print(ans)


def rationalee(n, k, a, w):
	a.sort()
	w.sort()
	i = 0
	j = n - 1
	ans = 0
	start = 0
	for y in w:
		if y == 1:
			ans += 2 * a[j]
			j -= 1
			start += 1
		else:
			break
	w = w[start:]
	w = w[::-1]
	for x in w:
		if x == 1:
			ans += 2 * a[j]
			j -= 1
		else:
			ans += a[j] + a[i]
			j -= 1
			i += x - 1
	return ans
t = int(input())
a = []
for i in range(t):
	(n, k) = list(map(int, input().split(' ')))
	a1 = list(map(int, input().split(' ')))
	w = list(map(int, input().split(' ')))
	a.append([n, k, a1, w])
for x in a:
	print(rationalee(*x))


import io
import os
from collections import deque
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	b.sort()
	a.sort()
	a = deque(a)
	b = deque(b)
	ans = 0
	while 1:
		e = b.popleft()
		if e == 1:
			ans += 2 * a.pop()
		else:
			b.appendleft(e)
			ans += a.pop() + a.popleft()
			b[-1] = b[-1] - 2
			while b[-1] > 0:
				a.popleft()
				b[-1] -= 1
			b.pop()
		if len(a) == 0:
			break
	print(ans)


import math

def main():
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	w = sorted(list(map(int, input().split())))
	sm = 0
	w = list(reversed(w))
	for i in range(k):
		r = a.pop()
		w[k - 1 - i] -= 1
		if w[k - 1 - i] == 0:
			sm += 2 * r
		else:
			sm += r
	o = 0
	for i in range(k):
		if w[i] != 0:
			sm += a[o]
			o += w[i]
	print(sm)
t = int(input())
for i in range(t):
	main()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	w.sort(reverse=True)
	p = 0
	for ele in w:
		if ele == 1:
			p += 1
	ans = 0
	j = 0
	for i in range(p):
		ans += 2 * a[i]
		j += 1
	l = n - 1
	for i in range(k - p):
		ans += a[j] + a[l]
		j += 1
		l = l - w[i] + 1
	print(ans)


a = input()
for x in range(int(a)):
	b = input().split(' ')
	c = input().split(' ')
	d = input().split(' ')
	list1 = [int(i) for i in c]
	list3 = [int(i) for i in d]
	tag = list3.count(1)
	if tag == len(list3):
		print(sum(list1) * 2)
	else:
		i = 0
		j = len(list1) - 1
		list3.sort(reverse=True)
		if tag >= 1:
			list3 = list3[:-tag]
			list3 = [1] * tag + list3
		list1.sort()
		ans = 0
		for x in list3:
			if x == 1:
				ans += list1[j] * 2
				j -= 1
			else:
				ans += list1[i] + list1[j]
				i += x - 1
				j -= 1
		print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort(reverse=True)
	b.sort()
	count = 0
	j = k
	for i in range(k):
		count = count + a[i]
	for i in range(k):
		if b[i] == 1:
			count = count + a[i]
		else:
			count += a[j + b[i] - 2]
			j += b[i] - 1
	print(count)


t = int(input())
for jack in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	w.sort()
	w1 = w[::-1]
	r = [[] for _ in range(k)]
	d = sorted(a, reverse=True)
	p = d[::-1][:n - k]
	for i in range(k):
		r[i].append(d[i])
	u = 0
	for i in range(k):
		if u < len(p):
			r[k - 1 - i].append(p[u])
		u += w1[i] - 1
	detour = 0
	for i in range(k):
		detour += max(r[i]) + min(r[i])
	print(detour)


import math

def isPrimes2(n):
	if n > 1:
		if n == 2:
			return True
		if n % 2 == 0:
			return False
		for x in range(3, int(math.sqrt(n) + 1), 2):
			if n % x == 0:
				return False
		return True
	return False

def isok(n):
	while n != 1:
		if n % 2 == 1:
			return False
		n /= 2
	return True

def main():
	t = int(input())
	for i in range(t):
		(n, k) = map(int, input().split())
		a = list(map(int, input().split()))
		w = list(map(int, input().split()))
		a = sorted(a)
		w = sorted(w)
		flag0 = 0
		flag1 = len(a) - 1
		ans = 0
		tmp = 0
		for j in range(len(w)):
			if w[j] == 1 and j < len(w) - 1:
				ans += 2 * a[flag1]
				flag1 -= 1
			elif w[j] == 1 and j == len(w) - 1:
				ans += 2 * a[flag1]
				flag1 -= 1
				tmp = j + 1
				break
			else:
				tmp = j
				break
		for j in range(len(w) - tmp):
			ans += a[flag1]
			ans += a[flag0]
			flag1 -= 1
			flag0 += w[-j - 1] - 1
		print(ans)
main()


for ad in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	w.sort()
	a.sort()
	s = 0
	b = a[n - k:]
	a = a[:n - k]
	a.reverse()
	b.reverse()
	p = 0
	q = 0
	for i in w:
		if i == 1:
			s += 2 * b[p]
			p += 1
		elif i == 2:
			s += a[q] + b[p]
			q += 1
			p += 1
		else:
			s += b[p] + a[i - 2 + q]
			p += 1
			q += i - 1
	print(s)


for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	w = [int(i) for i in input().split()]
	a.sort()
	w.sort()
	given = [[] for i in range(k)]
	ans = 0
	for i in range(len(w)):
		given[i].append(a[n - i - 1])
		w[i] -= 1
	ind = 0
	for i in range(len(w) - 1, -1, -1):
		if w[i] != 0:
			given[i].append(a[ind])
			ind += w[i]
	for i in given:
		if len(i) == 1:
			ans += 2 * i[0]
		else:
			ans += i[0] + i[1]
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	nums = sorted(list(map(int, input().split())))
	friends = sorted(list(map(int, input().split())), key=lambda x: -x)
	allmax = 0
	while friends and friends[-1] == 1:
		friends.pop()
		allmax += 2 * nums.pop()
	for i in range(len(friends)):
		allmax += nums.pop()
	idx = 0
	for i in friends:
		allmax += nums[idx]
		idx += i - 1
	print(allmax)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	w = list(map(int, input().split()))
	w.sort(reverse=True)
	l = 0
	r = n - 1
	ans = 0
	p = k - 1
	while p >= 0 and w[p] == 1:
		ans += 2 * a[r]
		r -= 1
		p -= 1
	for i in w[:p + 1]:
		ans += a[l if i > 1 else r] + a[r]
		r -= 1
		l += i - 1
	print(ans)


n = int(input(''))
ints = []
frnds = []
for i in range(n):
	C = input('')
	t_ints = input('')
	t_frnds = input('')
	entries = list(map(int, t_ints.split()))
	n_entries = list(map(int, t_frnds.split()))
	ints.append(entries)
	frnds.append(n_entries)
for i in range(n):
	cnt = 0
	my_int = ints[i]
	my_frnds = frnds[i]
	my_int.sort(reverse=True)
	my_frnds.sort()
	index = 0
	strt = 0
	for j in range(len(my_frnds)):
		if my_frnds[j] == 1:
			cnt = cnt + 2 * my_int[index]
			index = index + 1
			strt = strt + 1
		elif my_frnds[j] == 2:
			cnt = cnt + my_int[index] + my_int[index + 1]
			index = index + 2
			strt = strt + 1
		else:
			cnt = cnt + my_int[index]
			index = index + 1
	while index < len(my_int):
		cnt = cnt + my_int[index + my_frnds[strt] - 2]
		index = index + my_frnds[strt] - 1
		strt = strt + 1
	print(cnt)


import heapq
for _ in range(0, int(input())):
	(n, k) = map(int, input().strip().split())
	l = list(map(int, input().strip().split()))
	w = list(map(int, input().strip().split()))
	l = [-a for a in l]
	heapq.heapify(l)
	w.sort()
	pockets = [[] for a in range(0, len(w))]
	for i in range(0, len(w)):
		pockets[i].append(-heapq.heappop(l))
	for i in range(0, len(w)):
		weight1 = w[i] - 1
		for j in range(0, weight1):
			pockets[i].append(-heapq.heappop(l))
	r = 0
	for i in range(0, len(pockets)):
		r += pockets[i][0] + pockets[i][-1]
	print(r)


t = int(input())
for tc in range(t):
	line = input().split()
	(n, k) = (int(line[0]), int(line[1]))
	line = input().split()
	w = []
	for x in line:
		w.append(int(x))
	w.sort()
	line = input().split()
	friends = []
	for x in line:
		friends.append(int(x))
	friends.sort()
	happiness = 0
	i = 0
	j = n - 1
	p = 0
	while p < k and friends[p] == 1:
		happiness += 2 * w[j]
		j -= 1
		p += 1
	q = k - 1
	while q >= p:
		happiness += w[j] + w[i]
		j -= 1
		i += 1
		friends[q] -= 2
		while friends[q] > 0:
			i += 1
			friends[q] -= 1
		q -= 1
	print(happiness)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	w.sort()
	ans = sum(a[:k])
	tmp = k - 1
	for i in range(k):
		if w[i] == 1:
			ans += a[i]
		else:
			tmp += w[i] - 1
			ans += a[tmp]
	print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import heapq
import collections

def main():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		nList = list(map(int, input().split()))
		kList = list(map(int, input().split()))
		nList.sort()
		kList.sort()
		nList = collections.deque(nList)
		kList = collections.deque(kList)
		ans = 0
		while kList and kList[0] == 1:
			kList.popleft()
			temp = nList.pop()
			ans += temp * 2
		while nList and kList:
			tempK = kList.pop()
			tempN = nList.pop()
			ans += tempN
			tempN = nList.popleft()
			ans += tempN
			tempK -= 2
			while tempK > 0:
				nList.popleft()
				tempK -= 1
		print(ans)
	return
main()


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	w.sort()
	sum = 0
	(val_x, l, r) = (k, 0, n - 1)
	for x in range(k):
		if w[x] > 1:
			val_x = x
			break
		sum += a[l] * 2
		l += 1
	for p in range(k - 1, val_x - 1, -1):
		val = w[p]
		sum += a[l] + a[r]
		r = r - val + 1
		l += 1
	print(sum)


for i in range(int(input())):
	(n, k) = input().split(' ')
	(n, k) = (int(n), int(k))
	A = input().split(' ')
	B = input().split(' ')
	for j in range(n):
		A[j] = int(A[j])
	for j in range(k):
		B[j] = int(B[j])
	A.sort()
	B.sort(reverse=True)
	M = []
	for j in B:
		if j > 1:
			M += [1] + [0] * (j - 2)
	for j in B:
		if j > 1:
			M += [1]
		else:
			M += [2]
	ans = 0
	for j in range(n):
		ans += M[j] * A[j]
	print(ans)


from collections import OrderedDict
T = int(input())
for i in range(T):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	W = list(map(int, input().split()))
	A.sort(reverse=True)
	W.sort()
	ans = 0
	d = OrderedDict()
	for j in range(N):
		if j < K:
			ans += A[j]
			d[W[j], j] = 1
			if W[j] == 1:
				ans += A[j]
	prev = K - 1
	temp = 0
	for j in d:
		temp = j[0] - d[j]
		if temp != 0:
			prev += temp
			ans += A[prev]
	print(ans)


import sys
input = sys.stdin.readline
ans = []
for kek in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	w.sort()
	a.sort(reverse=True)
	happy = 0
	one = 0
	for i in w:
		if i == 1:
			one += 1
	for i in range(one):
		happy += 2 * a[i]
	for i in range(one, len(w)):
		happy += a[i]
	for i in range(len(w)):
		w[i] -= 1
	index = len(w)
	for i in w:
		if i != 0:
			index += i
			happy += a[index - 1]
	ans.append(happy)
print(*ans, sep='\n')


from sys import stdin, stdout
from sys import maxsize

def solve():
	pass
test = 1
test = int(input())
for t in range(0, test):
	(n, k) = list(map(int, input().split()))
	a = [int(x) for x in input().split()]
	w = [int(x) for x in input().split()]
	w.sort(reverse=True)
	a.sort()
	ans = 0
	j = 0
	counter = k
	for i in range(k):
		if w[i] == 1:
			counter = i
			break
		ans += a[j]
		j += w[i] - 1
	a.reverse()
	for i in range(k):
		ans += a[i]
	for i in range(k - counter):
		ans += a[i]
	print(ans)
	ans = solve()


from sys import stdin, stdout
for test in range(int(stdin.readline())):
	arr0 = [int(x) for x in stdin.readline().split()]
	n = arr0[0]
	k = arr0[1]
	arr1 = [int(x) for x in stdin.readline().split()]
	arr2 = [int(x) for x in stdin.readline().split()]
	arr1.sort()
	arr2.sort()
	ans = 0
	ind1 = -1
	for i in arr2:
		if i == 1:
			ind1 += 1
		else:
			break
	for i in range(ind1 + 1):
		ans += 2 * arr1[n - i - 1]
	if ind1 == -1:
		up = n - 1
		ind1 = 0
	else:
		up = n - ind1 - 2
		ind1 += 1
	low = 0
	for i in range(k - ind1):
		ans += arr1[up] + arr1[low]
		up -= 1
		low += arr2[k - 1 - i] - 1
	stdout.write(str(ans) + '\n')


t = int(input())
for _ in range(0, t):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	a.sort()
	b.sort()
	z = 0
	for i in range(0, k):
		if b[i] == 1:
			z += 1
	z2 = k - z
	p = z
	s = 0
	s1 = 0
	s2 = 0
	for i in range(n - 1, -1, -1):
		if z > 0:
			s += a[i]
			z -= 1
		elif z2 > 0:
			s1 += a[i]
			z2 -= 1
		if z2 == 0 and z == 0:
			break
	j = i - 1
	while j >= 0:
		while b[p] != 2:
			b[p] -= 1
			j -= 1
		s2 += a[j]
		j -= 1
		p += 1
	ans = 2 * s + s1 + s2
	print(ans)


import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	for _ in range(II()):
		(n, k) = MI()
		aa = LI()
		ww = LI()
		aa.sort()
		ww.sort(reverse=True)
		c1 = ww.count(1)
		ans = sum(aa[n - k:]) + sum(aa[n - c1:])
		i = 0
		for w in ww:
			if w == 1:
				break
			ans += aa[i]
			i += w - 1
		print(ans)
main()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	w = list(map(int, input().split()))
	arr.sort(reverse=True)
	w.sort()
	qu_1 = 0
	for i in w:
		if i == 1:
			qu_1 += 1
	ans = 0
	for i in range(0, qu_1):
		ans += arr[i] * 2
	for i in range(qu_1, k):
		ans += arr[i]
	arr.reverse()
	w.reverse()
	m = 0
	i = 0
	while m != k - qu_1:
		ans += arr[i]
		i += w[m] - 1
		m += 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	A = [int(a) for a in input().split()]
	W = [int(w) for w in input().split()]
	A.sort(reverse=True)
	W.sort()
	ans = 0
	i = 0
	for w in W:
		if w == 1:
			ans += 2 * A[i]
		else:
			ans += A[i]
		i += 1
	i = n - 1
	W.sort(reverse=True)
	for w in W:
		if w > 1:
			ans += A[i]
			i -= w - 1
	print(ans)


T = int(input())
for _ in range(T):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	W = list(map(int, input().split()))
	A.sort()
	W.sort()
	ans = 0
	for i in range(K):
		a = A.pop()
		if W[i] == 1:
			ans += a
		ans += a
	for w in W:
		if w == 1:
			continue
		for _ in range(w - 2):
			A.pop()
		ans += A.pop()
	print(ans)


import math
from collections import Counter, defaultdict
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
for _ in range(I()):
	(n, m) = M()
	a = LI()
	b = LI()
	a.sort(reverse=True)
	b.sort()
	(ii, l, r) = (m, 0, n - 1)
	ans = 0
	for i in range(m):
		if b[i] > 1:
			ii = i
			break
		ans = ans + a[l] * 2
		l = l + 1
	for i in range(m - 1, ii - 1, -1):
		ans = ans + a[l] + a[r]
		r = r - b[i] + 1
		l = l + 1
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	cnt = 0
	c = []
	for i in range(k):
		d = []
		c.append(d)
	j = n - 1
	l = 0
	x = 0
	for i in range(k):
		b[i] -= 1
		c[i].append(a[j])
		j -= 1
	for i in range(k - 1, -1, -1):
		if b[i] == 0:
			break
		c[i].append(a[l])
		b[i] -= 1
		l += b[i] + 1
	suma = 0
	for i in range(k):
		suma += c[i][0] + c[i][-1]
	print(suma)


for z in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	z = list(map(int, input().split()))
	a.sort()
	z.sort()
	su = 0
	ind2 = 0
	ind1 = n - 1
	count = 0
	for i in range(k):
		if z[i] == 1:
			su += 2 * a[ind1]
			ind1 -= 1
			count += 1
		elif z[i] == 2:
			su += a[ind1] + a[ind1 - 1]
			ind1 -= 2
			count += 1
		else:
			break
	for i in range(k - 1, count - 1, -1):
		su += a[ind1] + a[ind2]
		ind1 -= 1
		ind2 = ind2 + (z[i] - 1)
	print(su)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	alis = list(map(int, input().split()))
	blis = list(map(int, input().split()))
	alis.sort()
	blis.sort()
	ans = 0
	p = 0
	i = n - 1
	j = 0
	flag = 0
	while True:
		if p < k and blis[p] == 1:
			ans = ans + alis[i] * 2
			p = p + 1
			if p == k:
				break
			else:
				i = i - 1
		else:
			for l in range(k - 1, p - 1, -1):
				fact = blis[l]
				ans = ans + alis[i] + alis[j]
				i = i - 1
				j = j + fact - 1
			break
	print(ans)


t = int(input())
for _ in range(t):
	l = list(map(int, input().split()))
	(n, k) = (l[0], l[1])
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	w.sort(reverse=True)
	maxarr = []
	for p in range(-1, -k - 1, -1):
		maxarr.append(a[p])
	minarr = []
	x = w.count(1)
	for p in range(-1, -x - 1, -1):
		minarr.append(a[p])
	for i in range(k):
		w[i] -= 1
	w.sort(reverse=True)
	if len(minarr) < k:
		minarr.append(a[0])
	key = 0
	temp = a[0:n - k]
	w = [i for i in w if i != 0]
	x = 0
	for i in range(len(w) - 1):
		try:
			minarr.append(temp[w[i] + x])
			x += w[i]
		except:
			pass
	print(sum(minarr) + sum(maxarr))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	w = list(map(int, input().split()))
	l.sort(reverse=True)
	w.sort()
	ans = sum(l[:k])
	m = l[k:]
	last = 0
	ch = 0
	for i in range(k):
		if w[i] != 1:
			ans += m[last + w[i] - 2]
			last = last + w[i] - 1
		else:
			ans += l[ch]
			ch += 1
	print(ans)


import sys
stdin = sys.stdin
stdout = sys.stdout
test = int(stdin.readline())
for t in range(test):
	(n, k) = [int(_) for _ in stdin.readline().split()]
	a = [int(_) for _ in stdin.readline().split()]
	w = [int(_) for _ in stdin.readline().split()]
	a.sort()
	w.sort()
	happiness = 0
	happiness += sum(a[-k:])
	current = 0
	current_back = -1
	for num in w[::-1]:
		if num > 1:
			happiness += a[current]
			current += num - 1
		else:
			happiness += a[current_back]
			current_back -= 1
	stdout.write(f'{happiness}\n')


a = int(input())
for i in range(a):
	(n, k) = map(int, input().split())
	z = list(map(int, input().split()))
	fri = list(map(int, input().split()))
	fri.sort()
	total = 0
	z.sort(reverse=True)
	ans = [0 for i in range(k)]
	for i in range(k):
		ans[i] = z[i]
	fri.sort(reverse=True)
	z.sort()
	index = 0
	for i in range(len(fri)):
		if fri[i] > 1:
			ans[k - i - 1] += z[index]
			index += fri[i] - 1
		else:
			ans[k - i - 1] = ans[k - i - 1] * 2
	print(sum(ans))


import math, sys, bisect
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
for _ in range(int(input())):
	(n, k) = ilele()
	A = alele()
	B = alele()
	c = B.count(1)
	A.sort()
	t = k
	Ans = 0
	while t > 0:
		t -= 1
		m = A.pop()
		Ans += m
		if c > 0:
			Ans += m
			c -= 1
	B.sort(reverse=True)
	while len(B) > 0:
		n = B.pop() - 1
		z = 0
		while n > 0:
			z = A.pop()
			n -= 1
		Ans += z
	print(Ans)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(item) for item in input().split()]
	w = [int(item) for item in input().split()]
	a.sort(reverse=True)
	w.sort()
	ans = 0
	minw = []
	for i in range(k):
		ans += a[i]
		w[i] -= 1
		minw.append(a[i])
	j = k
	for i in range(k):
		if w[i] > 0:
			ctr = w[i]
			j += ctr
			minw[i] = a[j - 1]
	print(ans + sum(minw))


def lee(n, m, a, w):
	if n == m:
		return 2 * sum(a)
	a.sort(reverse=True)
	w.sort()
	s = 0
	j = n - 1
	l = m - 1
	for i in range(m):
		if w[i] == 1:
			s += 2 * a[i]
		else:
			s += a[i] + a[j]
			j = j - w[l] + 1
			l -= 1
	return s
t = int(input())
for i in range(t):
	(n, m) = [int(j) for j in input().split()]
	a = [int(j) for j in input().split()]
	w = [int(j) for j in input().split()]
	print(lee(n, m, a, w))


import os, io
from sys import stdout
import collections
import random
import math
from operator import itemgetter
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def binomial_coefficient(n, k):
	if 0 <= k <= n:
		ntok = 1
		ktok = 1
		for t in range(1, min(k, n - k) + 1):
			ntok *= n
			ktok *= t
			n -= 1
		return ntok // ktok
	else:
		return 0

def powerOfK(k, max):
	if k == 1:
		return [1]
	if k == -1:
		return [-1, 1]
	result = []
	n = 1
	while n <= max:
		result.append(n)
		n *= k
	return result

def prefixSum(arr):
	for i in range(1, len(arr)):
		arr[i] = arr[i] + arr[i - 1]
	return arr

def divisors(n):
	i = 1
	result = []
	while i * i <= n:
		if n % i == 0:
			if n / i == i:
				result.append(i)
			else:
				result.append(i)
				result.append(n / i)
		i += 1
	return result
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	l = sorted(list(map(int, input().split())))
	f = sorted(list(map(int, input().split())), reverse=True)
	i = 0
	res = 0
	last = len(l) - 1
	for j in f:
		if j == 1:
			res += l[last] * 2
			last -= 1
			continue
		res += l[i]
		i += 1
		i += max(0, j - 2)
	while i <= last:
		res += l[i]
		i += 1
	print(res)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().strip().split(' '))
	a = list(map(int, input().strip().split(' ')))
	w = list(map(int, input().strip().split(' ')))
	a.sort(reverse=True)
	w.sort()
	s = 0
	c1 = w.count(1)
	c2 = w.count(2)
	p = c1 + c2
	temp = 0
	for j in range(c1):
		s += a[j] * 2
	temp = c1
	for j in range(c2):
		s += a[temp]
		temp += 1
		s += a[temp]
		temp += 1
	temp = c1 + c2 * 2
	for j in range(k - (c1 + c2)):
		s += a[temp]
		temp += 1
	temp -= 1
	for j in range(c1 + c2, k):
		s += a[temp + w[j] - 1]
		temp = temp + w[j] - 1
	print(s)


import sys

def solve(test):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	weight = list(map(int, input().split()))
	arr.sort(reverse=True)
	weight.sort()
	ans = [[] for i in range(k)]
	index = 0
	for i in range(k):
		ans[index].append(arr[index])
		index += 1
	for i in range(k):
		curr_weight_arr = ans[i]
		while len(curr_weight_arr) < weight[i]:
			curr_weight_arr.append(arr[index])
			index += 1
	ans_sum = 0
	for lis in ans:
		ans_sum += lis[0] + lis[-1]
	print(ans_sum)

def main():
	test_case = int(input())
	for test in range(test_case):
		solve(test + 1)
main()


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	integer = list(map(int, input().split()))
	happy = list(map(int, input().split()))
	l = []
	integer.sort(reverse=True)
	happy.sort()
	j = 0
	u = 0
	maximum = 0
	while u < k:
		l.append(integer[j])
		j += 1
		u += 1
	j -= 1
	for u in range(k):
		if happy[u] == 1:
			maximum += 2 * l[u]
		else:
			j += happy[u] - 1
			maximum += l[u] + integer[j]
	print(maximum)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = [int(x) for x in input().split()]
	l.sort(reverse=True)
	f = [int(x) for x in input().split()]
	f.sort(reverse=True)
	d = {}
	for i in f:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	s = 0
	c = 0
	if 1 in d:
		s += sum(l[:d[1]]) * 2
		c = d[1]
		d[1] = 0
		j = i
	for i in range(c, c + len(f) - c):
		s += l[i]
		j = i
	i = 0
	z = 0
	l = l[::-1]
	for z in range(len(f)):
		if f[z] == 1:
			break
		s += l[i]
		i += f[z] - 1
	print(s)


def sol():
	(x, y) = map(int, input().split())
	s = sorted(list(map(int, input().split())))
	z = list(map(int, input().split()))
	s.reverse()
	res = sum(s[:y])
	for n in range(z.count(1)):
		res += s[n]
	tem = s[y:]
	v = [n - 1 for n in z]
	v.sort()
	cur = 0
	n = 0
	while n < len(v):
		if v[n] == 0:
			n += 1
			continue
		res += tem[cur + v[n] - 1]
		cur += v[n]
		n += 1
	print(res)
for n in range(int(input())):
	sol()


for _ in range(int(input())):
	(n, k) = map(int, input().strip().split(' '))
	arr = list(map(int, input().strip().split(' ')))
	frn = list(map(int, input().strip().split(' ')))
	arr.sort(reverse=True)
	frn.sort()
	i = 0
	ans = 0
	for j in range(k):
		if frn[j] == 1:
			ans += arr[i] * 2
			i += 1
			frn[j] = 0
		elif frn[j] == 2:
			ans += arr[i]
			i += 1
			ans += arr[i]
			i += 1
			frn[j] = 0
		else:
			ans += arr[i]
			i += 1
			frn[j] -= 1
	arr = arr[i:]
	arr.sort()
	frn.sort(reverse=True)
	i = 0
	n = len(arr)
	for f in frn:
		if f == 0:
			break
		ans += arr[i]
		i += f
	print(ans)


from itertools import groupby
from math import sqrt
from math import floor

def solve():
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	W = list(map(int, input().split()))
	A.sort(reverse=True)
	W.sort()
	res = 0
	for i in range(k):
		res += A[i]
	l = k - 1
	for i in range(k):
		if W[i] == 1:
			res += A[i]
		else:
			l += W[i] - 1
			res += A[l]
	print(res)
for cnt in range(int(input())):
	solve()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	v = {}
	a = sorted(a, reverse=True)
	j = 0
	b.sort()
	for i in range(k):
		v[i] = [a[j]]
		b[i] -= 1
		j += 1
	for i in range(k):
		while b[i] > 0 and j < n:
			v[i].append(a[j])
			j += 1
			b[i] = b[i] - 1
	s = 0
	for i in v.keys():
		s = s + max(v[i]) + min(v[i])
	print(s)


t = int(input())
for i in range(0, t):
	(n, k) = map(int, input().split())
	ln = list(map(int, input().split()))
	lk = list(map(int, input().split()))
	ln.sort()
	ln.reverse()
	lk.sort()
	tits = 0
	c = 0
	for j in range(0, k):
		if lk[j] == 1:
			c = c + 1
	tits = 2 * sum(ln[0:c])
	xx = 0
	for j in range(c, k):
		tits += ln[j]
		tits += ln[k + lk[j] - 2 + xx]
		xx = xx + lk[j] - 1
	print(tits)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	list1 = list(map(int, input().split()))
	list1.sort()
	wlist = list(map(int, input().split()))
	wlist.sort()
	if n == k:
		print(2 * sum(list1))
	else:
		sum1 = 0
		right = list1[len(list1) - k:]
		j = len(list1) - k
		for i in range(len(wlist)):
			if wlist[i] == 1:
				sum1 += 2 * list1[len(list1) - i - 1]
			else:
				j -= wlist[i] - 1
				sum1 += list1[j] + list1[len(list1) - i - 1]
		print(sum1)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = sorted(map(int, input().split()))[::-1]
	w = sorted(map(int, input().split()))
	f = w.count(1)
	res = sum(s[:m]) + sum(s[:f])
	for i in w[f:]:
		m += i - 1
		res += s[m - 1]
	print(res)


from sys import stdin, stdout
import math
t = int(stdin.readline())
for _ in range(t):
	(n, k) = list(map(int, stdin.readline().split()))
	a = list(map(int, stdin.readline().split()))
	w = list(map(int, stdin.readline().split()))
	a = sorted(a)
	w = sorted(w)
	(st, end) = (0, n - 1)
	ans = 0
	idx = 0
	while idx < k and w[idx] == 1:
		ans += a[end] * 2
		end -= 1
		idx += 1
	for i in range(k - 1, idx - 1, -1):
		wi = w[i]
		ans += a[st] + a[end]
		end -= 1
		st += wi - 1
	print(ans)


from functools import reduce
T = int(input())
for test in range(T):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	w = [int(x) for x in input().split()]
	a.sort()
	w.sort(reverse=True)
	max = reduce(lambda x, y: x + y, a[-k:])
	min = 0
	index = 0
	indexmax = n - 1
	for i in range(k):
		if w[i] == 1:
			min += a[indexmax]
			indexmax -= 1
		else:
			min += a[index]
			index += w[i] - 1
	print(min + max)


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict, Counter
import math

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
t = intIn()
while t > 0:
	t -= 1
	(n, k) = listIn()
	a = listIn()
	w = listIn()
	w.sort()
	a.sort()
	total = 0
	for i in range(k):
		ele = a.pop(-1)
		if w[i] == 1:
			total += ele * 2
		else:
			total += ele
		n -= 1
	j = n
	while j > 0:
		for i in range(k):
			req = w[i] - 1
			if req != 0:
				total += a[j - req]
				j -= req
	print(total)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	(*li,) = map(int, input().split())
	(*li1,) = map(int, input().split())
	li.sort(reverse=True)
	li1.sort()
	(j, ans) = (0, 0)
	for i in range(k):
		if li1[i] == 1:
			ans += li[i] * 2
		else:
			j += li1[i] - 1
			ans += li[i] + li[k + j - 1]
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	(sum, count, p) = (0, 0, n - 1)
	a = [int(x) for x in input().split()]
	a.sort()
	w = [int(y) for y in input().split()]
	w.sort()
	while count < k:
		if w[count] == 1:
			sum += 2 * a[p]
			p -= 1
		elif w[count] == 2:
			sum += a[p] + a[p - 1]
			p -= 2
		else:
			sum += a[p]
			p -= 1
		count += 1
	p += 1
	count = 0
	while count < k:
		if w[count] > 2:
			p -= w[count] - 1
			sum += a[p]
		count += 1
	print(sum)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	j = k - 1
	a = sorted(list(map(int, input().split())), reverse=True)
	w = sorted(list(map(int, input().split())))
	out = sum(a[:k])
	for i in range(k):
		if w[i] == 1:
			out += a[i]
		else:
			j += w[i] - 1
			out += a[j]
	print(out)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	w.sort(reverse=True)
	t = w.count(1)
	z = t
	ans = 0
	ans += 2 * sum(a[:t])
	b = n - 1
	for i in range(k - z):
		ans += a[t] + a[b]
		t += 1
		b = b - w[i] + 1
	print(ans)


from collections import *
import sys
input = sys.stdin.readline
from math import *
t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	b = list(map(int, input().split()))
	b.sort(reverse=True)
	r = 0
	z = b.count(1)
	j1 = n - 1
	for i in range(z):
		r += a[j1] * 2
		j1 -= 1
	i1 = 0
	for i in range(0, len(b) - z):
		ma = []
		ma.append(a[j1])
		j1 -= 1
		for j in range(b[i] - 1):
			ma.append(a[i1])
			i1 += 1
		r += min(ma) + max(ma)
	print(r)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	w.sort()
	_sum = 0
	minW = list()
	for i in range(k):
		_sum += a[i]
		w[i] -= 1
		minW.append(a[i])
	j = n
	for i in range(k - 1, -1, -1):
		if w[i] > 0:
			ctr = w[i]
			minW[i] = a[j - 1]
			j -= ctr
	print(_sum + sum(minW))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = sorted(list(map(int, input().split())))
	weights = sorted(list(map(int, input().split())), reverse=True)
	cnt = ones = weights.count(1)
	i = 0
	j = n - 1
	t = 0
	ans = 0
	while cnt > 0:
		ans += 2 * arr[j]
		j -= 1
		cnt -= 1
	while t < k - ones:
		if weights[t] % 2 == 1:
			ans += arr[i] + arr[j]
			j -= 1
			i += weights[t] - 1
		else:
			ans += arr[i] + arr[j]
			j -= 1
			i += weights[t] - 1
		t += 1
	print(ans)


o = int(input())
for _ in range(o):
	(n, k) = list(map(int, input().split(' ')))
	A = list(map(int, input().split(' ')))
	W = list(map(int, input().split(' ')))
	A.sort(reverse=True)
	W.sort()
	ans = 0
	i = 0
	ind = -1
	while i < k:
		if W[i] == 1:
			ans += 2 * A[i]
			i += 1
		else:
			ind = i
			break
	if ind == -1:
		print(ans)
		continue
	for i in range(ind, k):
		ans += A[i]
	r = n - 1
	for i in range(k - 1, -1, -1):
		if W[i] < 2:
			break
		else:
			x = W[i]
			ans += A[r]
			r -= W[i] - 1
	print(ans)


import os
import operator
import sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		(n, f) = map(int, input().split())
		arr = [int(k) for k in input().split()]
		w = [int(k) for k in input().split()]
		arr.sort()
		w.sort()
		j = n - 1
		result = 0
		for i in range(f):
			if w[i] == 1:
				result += arr[j] * 2
				j -= 1
			else:
				result += arr[j]
				j -= 1
		j += 1
		for i in range(f):
			if w[i] == 1:
				continue
			else:
				j -= w[i] - 1
				result += arr[j]
		print(result)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for tt in range(t):
	(n, k) = [int(x) for x in input().split(' ')]
	a = list(map(int, input().split(' ')))
	w = list(map(int, input().split(' ')))
	a.sort()
	w.sort()
	hp = 0
	fp = 0
	lp = int(n)
	wp = 0
	while w[wp] == 1:
		hp += 2 * a[lp - 1]
		lp -= 1
		wp += 1
		if wp == k:
			break
	wp_savdata = int(wp)
	wp = k - 1
	while wp_savdata <= wp:
		hp += a[fp]
		fp += w[wp] - 1
		hp += a[lp - 1]
		lp -= 1
		wp -= 1
	print(hp)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	fri = list(map(int, input().split()))
	arr.sort()
	fri.sort()
	i = n
	maxi = [0 for i in range(n)]
	s = 0
	i = n
	for j in range(k):
		i -= 1
		maxi[j] = arr[i]
		s += maxi[j]
		fri[j] -= 1
	for j in range(k):
		if fri[j] == 0:
			s += maxi[j]
		else:
			i -= fri[j]
			s += arr[i]
	print(s)


from math import *

def r1(t):
	return t(input())

def r2(t):
	return [t(i) for i in input().split()]
for _ in range(r1(int)):
	(n, k) = r2(int)
	a = r2(int)
	w = r2(int)
	w.sort()
	a.sort()
	ans = 0
	t = [0] * k
	for i in range(k):
		t[i] = a[n - i - 1]
	ci = 0
	for i in range(k - 1, -1, -1):
		if w[i] == 1:
			t[i] += a[n - i - 1]
		else:
			t[i] += a[ci]
			ci += w[i] - 1
	print(sum(t))


import sys, bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range

def Golf():
	(n, *t) = map(int, open(0).read().split())

def I():
	return int(input())

def S_():
	return input()

def IS():
	return input().split()

def LS():
	return [i for i in input().split()]

def MI():
	return map(int, input().split())

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def RA():
	return map(int, open(0).read().split())

def GI(V, E, ls=None, Directed=False, index=1):
	org_inp = []
	g = [[] for i in range(V)]
	FromStdin = True if ls == None else False
	for i in range(E):
		if FromStdin:
			inp = LI()
			org_inp.append(inp)
		else:
			inp = ls[i]
		if len(inp) == 2:
			(a, b) = inp
			c = 1
		else:
			(a, b, c) = inp
		if index == 1:
			a -= 1
			b -= 1
		aa = (a, c)
		bb = (b, c)
		g[a].append(bb)
		if not Directed:
			g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	for i in range(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def accum(ls):
	rt = [0]
	for i in ls:
		rt += [rt[-1] + i]
	return rt

def bit_combination(n, base=2):
	rt = []
	for tb in range(base ** n):
		s = [tb // base ** bt % base for bt in range(n)]
		rt += [s]
	return rt

def gcd(x, y):
	if y == 0:
		return x
	if x % y == 0:
		return y
	while x % y != 0:
		(x, y) = (y, x % y)
	return y

def YN(x):
	print(['NO', 'YES'][x])

def Yn(x):
	print(['No', 'Yes'][x])

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
mo = 10 ** 9 + 7
inf = float('inf')
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
l_alp = string.ascii_lowercase
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()

class Tree:

	def __init__(self, inp_size=None, ls=None, init=True, index=1):
		self.LCA_init_stat = False
		self.ETtable = []
		if init:
			if ls == None:
				self.stdin(inp_size, index=index)
			else:
				self.node_size = len(ls) + 1
				(self.edges, _) = GI(self.node_size, self.node_size - 1, ls, index=index)
		return

	def stdin(self, inp_size=None, index=1):
		if inp_size == None:
			self.node_size = int(input())
		else:
			self.node_size = inp_size
		(self.edges, _) = GI(self.node_size, self.node_size - 1, index=index)
		return

	def listin(self, ls, index=0):
		self.node_size = len(ls) + 1
		(self.edges, _) = GI(self.node_size, self.node_size - 1, ls, index=index)
		return

	def dfs(self, x, func=lambda pr, prv, nx, dist: prv + dist, root_v=0):
		q = deque([x])
		v = [None] * self.node_size
		v[x] = root_v
		while q:
			c = q.pop()
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = func(c, v[c], nb, d)
		return v

	def bfs(self, x, func=lambda pr, prv, nx, dist: prv + dist, root_v=0):
		q = deque([x])
		v = [None] * self.node_size
		v[x] = root_v
		while q:
			c = q.popleft()
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = func(c, v[c], nb, d)
		return v

	def parent(self, x):
		return self.dfs(0, func=lambda pr, prv, nx, dist: pr, root_v=-1)

	def topological_sort(self, x):
		tps = []
		q = deque([x])
		v = [None] * self.node_size
		v[x] = 0
		while q:
			c = q.popleft()
			tps.append(c)
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = 0
		return tps

	def EulerTour(self, x):
		q = deque()
		q.append(x)
		self.depth = [None] * self.node_size
		self.depth[x] = 0
		self.ETtable = []
		self.ETdepth = []
		self.ETin = [-1] * self.node_size
		self.ETout = [-1] * self.node_size
		cnt = 0
		while q:
			c = q.pop()
			if c < 0:
				ce = ~c
			else:
				ce = c
				for (nb, d) in self.edges[ce]:
					if self.depth[nb] == None:
						q.append(~ce)
						q.append(nb)
						self.depth[nb] = self.depth[ce] + 1
			self.ETtable.append(ce)
			self.ETdepth.append(self.depth[ce])
			if self.ETin[ce] == -1:
				self.ETin[ce] = cnt
			else:
				self.ETout[ce] = cnt
			cnt += 1
		return

	def LCA_init(self, root):
		self.EulerTour(root)
		self.st = SparseTable(self.ETdepth, init_func=min, init_idl=inf)
		self.LCA_init_stat = True
		return

	def LCA(self, root, x, y):
		if self.LCA_init_stat == False:
			self.LCA_init(root)
		(xin, xout) = (self.ETin[x], self.ETout[x])
		(yin, yout) = (self.ETin[y], self.ETout[y])
		a = min(xin, yin)
		b = max(xout, yout, xin, yin)
		id_of_min_dep_in_et = self.st.query_id(a, b + 1)
		return self.ETtable[id_of_min_dep_in_et]

	def __str__(self):
		return str(self.edges)

	def show(self):
		if all([all([d == 1 for (nd, d) in e]) for e in self.edges]):
			print([[nd for (nd, d) in e] for e in self.edges])
		else:
			print(self)

class SparseTable:

	def __init__(self, ls, init_func=min, init_idl=float('inf')):
		self.func = init_func
		self.idl = init_idl
		self.size = len(ls)
		self.N0 = self.size.bit_length()
		self.table = [ls[:]]
		self.index = [list(range(self.size))]
		self.lg = [0] * (self.size + 1)
		for i in range(2, self.size + 1):
			self.lg[i] = self.lg[i >> 1] + 1
		for i in range(self.N0):
			tmp = [self.func(self.table[i][j], self.table[i][min(j + (1 << i), self.size - 1)]) for j in range(self.size)]
			tmp_id = [self.index[i][j] if self.table[i][j] == self.func(self.table[i][j], self.table[i][min(j + (1 << i), self.size - 1)]) else self.index[i][min(j + (1 << i), self.size - 1)] for j in range(self.size)]
			self.table += [tmp]
			self.index += [tmp_id]

	def query(self, l, r):
		if r > self.size:
			r = self.size
		N = self.lg[r - l]
		return self.func(self.table[N][l], self.table[N][max(0, r - (1 << N))])

	def query_id(self, l, r):
		if r > self.size:
			r = self.size
		N = self.lg[r - l]
		(a, b) = (self.index[N][l], self.index[N][max(0, r - (1 << N))])
		if self.table[0][a] == self.func(self.table[N][l], self.table[N][max(0, r - (1 << N))]):
			b = a
		return b

	def right_bound(self, pos, x):
		k = (self.size - pos).bit_length()
		for j in range(k)[::-1]:
			nx = pos + (1 << j)
			if nx < n and self.query(pos, nx + 1) <= x:
				pos += 1 << j
		return pos

	def left_bound(self, pos, x):
		k = pos.bit_length()
		for j in range(k)[::-1]:
			nx = pos - (1 << j)
			if 0 <= nx and self.query(nx, pos + 1) <= x:
				pos -= 1 << j
		return pos

	def __str__(self):
		return str(self.table[0])

	def print(self):
		for i in self.table:
			print(*i)
show_flg = False
show_flg = True
ans = 0
for _ in range(int(input())):
	ans = 0
	(n, k) = LI()
	a = sorted(LI())
	w = sorted(LI())[::-1]
	while w and w[-1] == 1:
		w.pop()
		ans += 2 * a.pop()
		n -= 1
		k -= 1
	ans += sum(a[n - k:])
	t = 0
	for i in w:
		ans += a[t]
		t += i - 1
	print(ans)


t = int(input())
while t:
	(m, k) = map(int, input().split())
	l = list(map(int, input().split()))
	w = list(map(int, input().split()))
	l.sort()
	ans = 0
	w.sort(reverse=True)
	while w and w[-1] == 1:
		ans += 2 * l[-1]
		l.pop()
		w.pop()
	ii = 0
	for i in w:
		ans += l[-1]
		ans += l[ii]
		l.pop()
		for j in range(i - 1):
			ii += 1
	print(ans)
	t -= 1


import sys
from bisect import bisect_left
from collections import defaultdict
input = lambda : sys.stdin.readline().rstrip()
R = lambda : list(map(int, input().split()))
(T,) = R()
for _ in range(T):
	(n, m) = R()
	a = R()
	w = R()
	a.sort(reverse=True)
	w.sort()
	ans = 0
	(l, r) = (0, n - 1)
	mark = m
	for i in range(m):
		if w[i] == 1:
			ans += a[l] * 2
			l += 1
		else:
			mark = i
			break
	for i in range(m - 1, mark - 1, -1):
		hid = w[i] - 2
		ans += a[l] + a[r]
		r -= hid + 1
		l += 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	ct = 0
	nw = []
	for i in w:
		if i == 1:
			ct += 1
		else:
			nw.append(i)
	a.sort()
	s = 0
	for i in range(n - 1, n - (ct + 1), -1):
		s += 2 * a[i]
	j = n - (ct + 1)
	i = 0
	nw.sort(reverse=True)
	for z in nw:
		ct = 0
		if z != 1:
			s += a[j] + a[i]
		else:
			s += 2 * a[j]
		i += z - 1
		j -= 1
	print(s)


import sys
input = sys.stdin.readline
(T,) = map(int, input().split())
for _ in range(T):
	(N, K) = map(int, input().split())
	X = list(map(int, input().split()))
	Y = list(map(int, input().split()))
	X.sort()
	Y.sort()
	R = 0
	for i in range(K):
		if Y[i] != 1:
			break
		else:
			R += 2 * X.pop()
	else:
		i += 1
	X = X[::-1]
	Y = Y[::-1]
	for j in range(K - i):
		R += X.pop()
		for _ in range(Y[j] - 2):
			X.pop()
	R += sum(X)
	print(R)


t = int(input())
while t:
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	w.sort()
	value = 0
	check = len(a) - 1
	for i in range(0, k):
		w[i] = w[i] - 1
		value = value + a[check]
		if w[i] == 0:
			value = value + a[check]
		check = check - 1
	for i in range(0, k):
		if w[i] > 0:
			value = value + a[check - w[i] + 1]
			check = check - w[i]
	print(value)
	t = t - 1


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt
from bisect import bisect_right, bisect_left
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def factorial(n):
	if n == 0:
		return 1
	return n * factorial(n - 1)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return len(set(factors))

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))
MOD = 10 ** 9 + 9
T = 1
T = int(stdin.readline())
for _ in range(T):
	(n, k) = list(map(int, stdin.readline().split()))
	a = list(map(int, stdin.readline().split()))
	w = list(map(int, stdin.readline().split()))
	a.sort()
	w.sort(reverse=True)
	ans = 0
	oix = []
	for i in range(k):
		if w[i] == 1:
			ans += 2 * a.pop()
			oix.append(i)
			n -= 1
			k -= 1
	ans += sum(a[n - k:])
	p = 0
	for i in range(k):
		ans += a[p]
		p += w[i] - 1
	print(ans)


N = int(input())
for i in range(N):
	out = 0
	(ngifts, nusers) = tuple(map(int, input().split()))
	gifts = list(map(int, input().split()))
	users = list(map(int, input().split()))
	gifts.sort()
	users.sort()
	one = users.count(1)
	g1 = 0
	g2 = ngifts - 1
	if one:
		out += sum(gifts[-1 * one:]) * 2
		g2 -= one
	for u in range(nusers, one, -1):
		out += gifts[g1] + gifts[g2]
		g1 += users[u - 1] - 1
		g2 -= 1
	print(out)


from sys import stdin
import io
import os
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	b.sort()
	a.sort()
	ans = 0
	j = 0
	i = n - 1
	z = k - 1
	m = 0
	while 1:
		if b[j] == 1:
			ans += 2 * a[i]
			i -= 1
			j += 1
			if j == k:
				break
		else:
			ans += a[i] + a[m]
			m = m + (b[z] - 1)
			i -= 1
			z -= 1
			if z < j:
				break
	su = 0
	print(ans)


def f(ints, dist):
	ints.sort()
	dist.sort()
	dist.reverse()
	summ = 0
	while len(dist) > 0 and dist[-1] == 1:
		summ = summ + 2 * ints[-1]
		ints.pop()
		dist.pop()
	cr = 0
	for i in range(len(dist)):
		summ = summ + ints[cr]
		cr = cr + dist[i] - 1
		summ = summ + ints[-1]
		ints.pop()
	return summ
for tc in range(int(input())):
	_ = input()
	ints = list(map(int, input().split()))
	dist = list(map(int, input().split()))
	print(f(ints, dist))


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	have = [int(x) for x in input().split()]
	required = [int(x) - 1 for x in input().split()]
	have.sort()
	required.sort()
	ans = 0
	for i in range(k):
		c = 1
		if not required[i]:
			c += 1
		ans += have[-1] * c
		have.pop()
	i = 0
	while len(required):
		if required[-1]:
			ans += have[i]
			i += required[-1]
		required.pop()
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ar = list(map(int, input().split()))
	w = list(map(int, input().split()))
	ar.sort(reverse=True)
	i = 0
	ans = 0
	w.sort(reverse=True)
	for j in range(k - 1, -1, -1):
		if w[j] == 1:
			ans += 2 * ar[i]
			i += 1
		else:
			break
	j = n - 1
	for ij in range(k - i):
		ans += ar[i] + ar[j]
		i += 1
		j -= w[ij] - 1
	print(ans)


from collections import deque

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		a = list(map(int, input().split()))
		w = list(map(int, input().split()))
		l = [[] for i in range(k)]
		w = [[i, w[i]] for i in range(k)]
		w.sort(key=lambda x: x[1])
		w = deque(w)
		a.sort()
		i = 0
		s = 0
		for i in range(k):
			if w[i][1] == 1:
				s += 2 * a.pop()
			else:
				s += a.pop()
		t = 0
		for i in range(k - 1, -1, -1):
			if w[i][1] != 1:
				s += min(a[t:t + (w[i][1] - 1)])
				t += w[i][1] - 1
		print(s)
main()


from math import ceil, log, floor, sqrt
import math

def mod_expo(n, p, m):
	result = 1
	while p != 0:
		if p % 2 == 1:
			result = result * n % m
		p //= 2
		n = n * n % m
	return result

def is_beauty(n):
	if n % 4 == 0:
		return 'YES'
	else:
		return 'NO'

def find_max_happiness(n, k, arr, w):
	(ii, l, r) = (k, 0, n - 1)
	res = 0
	arr.sort(reverse=True)
	w.sort()
	for i in range(k):
		if w[i] > 1:
			ii = i
			break
		res += arr[l] * 2
		l += 1
	for i in range(k - 1, ii - 1, -1):
		u = w[i]
		res += arr[l] + arr[r]
		r = r - u + 1
		l += 1
	return res

def find_with_neg(arr, w):
	l = 0
	k = len(w)
	h = 0
	w.sort(reverse=True)
	arr.sort()
	for i in range(k):
		h += arr[l] + arr[l + w[i] - 1]
		l += w[i]
		if arr[l] > 0:
			arr = arr[l:]
			w = w[i + 1:]
			return h + find_max_happiness(arr, w)
	return h

def get_happiness(arr, w):
	if min(arr) < 0:
		return find_with_neg(arr, w)
	return find_max_happiness(arr, w)
t = 1
t = int(input())
while t:
	t = t - 1
	(n, k) = map(int, input().split())
	arr = list(map(int, input().strip().split()))[:n]
	w = list(map(int, input().strip().split()))[:k]
	print(find_max_happiness(n, k, arr, w))


from sys import stdin
from bisect import bisect_left as bl
from bisect import bisect_right as br

def input():
	return stdin.readline()[:-1]

def intput():
	return int(input())

def sinput():
	return input().split()

def intsput():
	return map(int, sinput())

class RangedList:

	def __init__(self, start, stop, val=0):
		self.shift = 0 - start
		self.start = start
		self.stop = stop
		self.list = [val] * (stop - start)

	def __setitem__(self, key, value):
		self.list[key + self.shift] = value

	def __getitem__(self, key):
		return self.list[key + self.shift]

	def __repr__(self):
		return str(self.list)

	def __iter__(self):
		return iter(self.list)

def dprint(*args, **kwargs):
	if debugging:
		print(*args, **kwargs)
debugging = 1
t = intput()
for _ in range(t):
	(n, k) = intsput()
	a = list(intsput())
	w = list(intsput())
	a.sort(reverse=True)
	w.sort()
	total = 0
	for i in range(k):
		total += a[i]
		w[i] -= 1
	check = k
	for i in range(k):
		if w[i] == 0:
			total += a[i]
		while w[i]:
			if w[i] > 1:
				w[i] -= 1
				check += 1
			elif w[i] == 1:
				w[i] -= 1
				total += a[check]
				check += 1
	print(total)


t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	lis = list(map(int, input().split()))
	arr.sort(reverse=True)
	lis.sort()
	ans = 0
	ind = -1
	for j in range(k):
		if lis[j] != 1:
			ind = j
			break
		else:
			ans += 2 * arr[j]
	if ind == -1:
		print(ans)
	else:
		l = ind
		r = n - 1
		for j in range(k - 1, ind - 1, -1):
			len1 = lis[j]
			ans += arr[l] + arr[r]
			l += 1
			r += -len1 + 1
		print(ans)


def solve(n, k, a, w):
	if n == k:
		return 2 * sum(a)
	a = sorted(a)
	w = sorted(w)
	ones = w.count(1)
	w = list(filter(lambda a: a != 1, w))
	w = w[::-1]
	ans = 0
	p2 = n - 1
	p1 = 0
	for j in range(ones):
		ans += 2 * a[p2]
		p2 -= 1
	for f in w:
		ans += a[p2]
		ans += a[p1]
		p1 += 1
		p2 -= 1
		f -= 2
		p1 += f
	return ans
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	print(solve(n, k, a, w))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split(' '))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = sorted(a, reverse=True)
	ans = 0
	x = b.count(1)
	ans = ans + sum(a1[:x]) * 2
	a.sort()
	b = sorted(b, reverse=True)
	i1 = 0
	j = n - x - 1
	for i in range(k - x):
		ans = ans + a[i1] + a[j]
		j -= 1
		i1 = i1 + (b[i] - 1)
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = [int(i) for i in input().split()]
	w = [int(i) for i in input().split()]
	arr.sort(reverse=True)
	w.sort()
	ans = 0
	for i in range(k):
		ans = ans + arr[i]
		w[i] -= 1
	l = k - 1
	for i in range(k):
		if w[i] == 0:
			ans = ans + arr[i]
			continue
		while w[i] > 0:
			l += 1
			w[i] -= 1
		ans += arr[l]
	print(ans)


import math

def tc():
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	w = [int(x) for x in input().split()]
	a.sort()
	w.sort()
	ans = 0
	(a, maxes) = (a[:n - k][::-1], a[-k:])
	n_max_mins = w.count(1)
	ans += sum(maxes)
	if n_max_mins:
		ans += sum(maxes[-n_max_mins:])
	i = -1
	for x in w:
		if x > 1:
			i += x - 1
			ans += a[i]
	return ans
T = int(input())
for _ in range(T):
	ans = tc()
	print(ans)


from collections import defaultdict as dd
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	wa = list(map(int, input().split()))
	wa.sort()
	a.sort(reverse=True)
	ind = 0
	ans = 0
	for i in range(k):
		if wa[i] == 1:
			ans += 2 * a[ind]
			wa[i] -= 1
		else:
			ans += a[ind]
			wa[i] -= 1
		ind += 1
	for i in range(k):
		if wa[i]:
			while wa[i] != 1:
				wa[i] -= 1
				ind += 1
			ans += a[ind]
			ind += 1
	print(ans)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	s = 0
	(l, j) = (k, 0)
	w.sort()
	for i in range(k):
		if w[i] == 1:
			s += 2 * a[j]
			j += 1
			continue
		s += a[j]
		l += w[i] - 2
		s += a[l]
		j += 1
		l += 1
	print(s)


import sys
input = sys.stdin.readline

def solve(n, k, dq, w):
	total = 0
	while w and w[0] == 1:
		total += 2 * dq.popleft()
		w.popleft()
	while w and w[0] == 2:
		total += dq.popleft()
		total += dq.popleft()
		w.popleft()
	while w:
		size = w.pop()
		size -= 2
		total += dq.pop()
		total += dq.popleft()
		while size > 0:
			dq.pop()
			size -= 1
	return total
from collections import deque
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	dq = deque(sorted(map(int, input().split()), reverse=True))
	w = deque(sorted(map(int, input().split())))
	print(solve(n, k, dq, w))


import sys
input = sys.stdin.readline
T = int(input())
for testcase in range(T):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	w.sort(reverse=True)
	a.sort()
	res = 0
	idx = 0
	for e in w:
		if e == 1:
			break
		res += a[idx]
		idx += e - 1
	for i in range(k - 1, -1, -1):
		if w[i] == 1:
			res += a[n - 1 - (k - 1 - i)] * 2
		else:
			res += a[n - 1 - (k - 1 - i)]
	print(res)


t = int(input())
from collections import deque
for case in range(t):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	w = [int(x) for x in input().split()]
	w.sort()
	w.reverse()
	q = deque(sorted(a))
	s = 0
	for x in w:
		if x == 1:
			s += 2 * q.pop()
	for x in w:
		if x == 1:
			continue
		s += q.popleft()
		for i in range(x - 2):
			q.popleft()
		s += q.pop()
	print(s)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	(hap, l, r, j) = (0, 0, n - 1, k)
	a.sort(reverse=True)
	w.sort()
	for i in range(k):
		if w[i] == 1:
			hap += 2 * a[i]
		else:
			j = i
			break
	l += i
	for u in range(k - 1, j - 1, -1):
		hap += a[l] + a[r]
		r -= w[u] - 1
		l += 1
	print(hap)


t = int(input())
for _ in range(0, t):
	(n, k) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	a.sort(reverse=True)
	b.sort()
	j = k - 1
	sum1 = 0
	cnt1 = 0
	for ind in b:
		if ind != 1:
			j += ind - 1
			sum1 += a[j]
		else:
			cnt1 += 1
	sum1 += sum(a[:k])
	sum1 += sum(a[:cnt1])
	print(sum1)


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, K, A, W):
	ans = 0
	A.sort()
	A = deque(A)
	W2 = []
	for w in W:
		if w == 1:
			ans += A.pop() * 2
		else:
			W2.append(w)
	W = sorted(W2, reverse=True)
	i = 0
	groups = [[] for i in range(len(W))]
	for (i, w) in enumerate(W):
		for j in range(w - 1):
			groups[i].append(A.popleft())
	for (i, w) in enumerate(W):
		groups[i].append(A.pop())
	assert not A
	for g in groups:
		ans += g[0] + g[-1]
	return ans
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(N, K) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	W = [int(x) for x in input().split()]
	ans = solve(N, K, A, W)
	print(ans)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools
from collections import deque, defaultdict, OrderedDict
import collections

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(ri()):
		(n, k) = ria()
		a = ria()
		w = ria()
		w = sorted(w)
		a = deque(sorted(a, reverse=True))
		s = 0
		c = 0
		for i in range(k):
			if w[i] == 1:
				s += a[0] * 2
				a.popleft()
				c += 1
			else:
				break
		for j in range(k - 1, c - 1, -1):
			s += a[0] + a[-1]
			a.popleft()
			a.pop()
			for x in range(w[j] - 2):
				a.pop()
		print(s)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


from collections import *
import sys

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))
t = ri()
for _ in range(t):
	(n, k) = rl()
	aa = rl()
	ww = rl()
	aa.sort()
	ww.sort()
	ans = 0
	r = n - 1
	l = 0
	nb_w_equal_one = 0
	for i in range(k):
		if ww[i] == 1:
			nb_w_equal_one += 1
			ans += 2 * aa[r]
			r -= 1
		else:
			break
	for i in range(k - 1, nb_w_equal_one - 1, -1):
		ans += aa[l] + aa[r]
		r -= 1
		l += ww[i] - 1
	print(ans)


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
for _ in range(INT()):
	(N, K) = MAP()
	A = LIST()
	B = LIST()
	A.sort(reverse=1)
	B.sort()
	j = 0
	adjli = [[] for i in range(K)]
	k = 0
	for i in range(K):
		adjli[i].append(A[i])
		B[i] -= 1
	A.reverse()
	B.reverse()
	adjli.reverse()
	j = 0
	for i in range(N - K):
		while B[j] == 0:
			j += 1
		adjli[j].append(A[i])
		B[j] -= 1
	ans = 0
	for i in range(K):
		ans += min(adjli[i]) + max(adjli[i])
	print(ans)


for test in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	w.sort(reverse=True)
	s = 0
	i = 0
	while len(w) > 0 and w[-1] == 1:
		s += a.pop() * 2
		w.pop()
	for ln in w:
		s += a.pop()
		ln -= 1
		s += a[i]
		i += ln
	print(s)


def solve(n, k, a, w):
	ones = sum((int(x == 1) for x in w))
	a.sort()
	w.sort(reverse=True)
	sol = 0
	for _ in range(ones):
		sol += 2 * a.pop()
		w.pop()
	(l, r) = (0, len(a) - 1)
	for x in w:
		sol += a[l] + a[r]
		l += x - 1
		r -= 1
	return sol
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	print(solve(n, k, a, w))


for k in range(int(input())):
	(n, m) = map(int, input().split())
	t = list(map(int, input().split()))
	t.sort()
	a = 0
	b = -1
	f = list(map(int, input().split()))
	f.sort()
	g = f.count(1)
	f = f[:g] + f[g:][::-1]
	u = 0
	for j in f:
		u += t[b]
		b -= 1
		if j - 1 > 0:
			u += t[a]
			a += j - 1
		else:
			u += t[b + 1]
	print(u)


import math
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	w.sort()
	ans = 0
	for i in range(k):
		if w[i] == 1:
			ans += a[n - i - 1] * 2
		else:
			ans += a[n - i - 1]
		w[i] -= 1
	w.sort(reverse=True)
	i = 0
	for e in w:
		if e == 0:
			break
		ans += a[i]
		i += e
	print(ans)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(k) for k in input().split()][:n]
	a.sort()
	b = [int(j) for j in input().split()][:k]
	b.sort()
	f = a[-k:]
	c = k + 1
	p = [list() for l in range(k)]
	m = 0
	gg = 0
	if n == k:
		print(2 * sum(a))
	else:
		for w in b:
			if w == 1:
				gg += 1
				p[m].append(a[-gg])
				m += 1
			else:
				for u in range(w - 1):
					p[m].append(a[-c])
					c += 1
				m += 1
		totl = sum(f)
		for q in range(len(p)):
			totl += min(p[q])
		print(totl)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def main():
	t = I()
	rr = []
	for _ in range(t):
		(n, k) = LI()
		a = LI()
		w = LI()
		a.sort(reverse=True)
		w.sort()
		r = a[:k]
		ai = k - 1
		for i in range(k):
			c = w[i]
			if c == 1:
				r[i] *= 2
			else:
				ai += c - 1
				r[i] += a[ai]
		rr.append(sum(r))
	return JA(rr, '\n')
print(main())


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	seq = list(map(int, input().split()))
	f = list(map(int, input().split()))
	seq.sort()
	seq.reverse()
	f.sort()
	ans = 0
	ind = 0
	ind2 = n
	for i in range(k):
		if f[i] == 1:
			ans += seq[ind] * 2
			ind += 1
		else:
			ind2 = i
			break
	seq.sort()
	f.reverse()
	f = f[:k - ind2]
	r = n - ind2 - 1
	seq = seq[:r + 1]
	l = 0
	for i in range(k - ind2):
		m1 = seq[l]
		m2 = seq[r]
		l += f[i] - 1
		ans += m1 + m2
		r -= 1
	print(ans)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	w = sorted(list(map(int, input().split())))
	last = n - 1
	ans = 0
	for i in w:
		if i == 1:
			ans += a[last]
		ans += a[last]
		last -= 1
	fir = 0
	for i in w[::-1]:
		if i > 1:
			ans += a[fir]
			fir += i - 1
	print(ans)


from sys import stdin
A = int(stdin.readline())
for t in range(0, A):
	B = list(map(int, stdin.readline().split()))
	C = list(map(int, stdin.readline().split()))
	D = list(map(int, stdin.readline().split()))
	C.sort(reverse=True)
	D.sort()
	count = 0
	ans = 0
	E = list()
	for k in D:
		if k == 1:
			ans += 2 * C[count]
			count += 1
		else:
			ans += C[count]
			count += 1
			E.append(k - 1)
	C = C[count:]
	count = -1
	for k in E:
		ans += C[count + k]
		count += k
	print(ans)


t = int(input())
for i in range(t):
	summ = 0
	(n, k) = map(int, input().split())
	ar = [int(i) for i in input().split()]
	lee = [int(i) for i in input().split()]
	ar.sort()
	cou = []
	for j in range(k):
		if lee[j] != 1:
			cou.append(lee[j] - 2)
		else:
			pass
	cou.sort(reverse=True)
	foi = lee.count(1)
	k -= foi
	while True:
		if foi == 0:
			break
		else:
			pass
		summ += 2 * ar[-1]
		ar.pop()
		foi -= 1
	if k > 0:
		b = ar[-k:]
	else:
		b = []
	summ += sum(b)
	if len(ar) > 0:
		summ += ar[0]
	else:
		pass
	sta = 0
	for x in range(len(cou) - 1):
		if cou[x] != 0:
			summ += ar[cou[x] + sta + 1]
			sta = cou[x] + sta + 1
		else:
			summ += ar[sta + 1]
			sta += 1
	print(summ)


t = int(input())
c = []
for i in range(t):
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	a = [int(u) for u in input().split()]
	w = [int(u) for u in input().split()]
	a.sort()
	w.sort()
	sum = 0
	for i in range(k):
		if w[i] == 1:
			sum += a.pop() * 2
			w[i] -= 1
	for i in range(k):
		if w[i] > 0:
			sum += a.pop()
			w[i] -= 1
	for i in range(k):
		if w[i] > 0:
			for j in range(w[i] - 1):
				a.pop()
			sum += a.pop()
	c.append(sum)
for k in c:
	print(k)


test = int(input())
for t in range(test):
	[n, k] = list(map(int, input().split(' ')))
	a = list(map(int, input().split(' ')))
	w = list(map(int, input().split(' ')))
	a = sorted(a)
	w = sorted(w)
	tot = 0
	hi = n - 1
	lo = 0
	for num in w:
		if num == 1:
			tot += a[hi] * 2
			hi -= 1
		else:
			break
	w = reversed(w)
	for num in w:
		if num == 1:
			break
		else:
			tot += a[hi] + a[lo]
			lo += 1
			lo += num - 2
			hi -= 1
	print(tot)


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	a.reverse()
	w.sort()
	h = len(w)
	c = 0
	for i in range(h):
		c = c + a[i]
		if w[i] == 1:
			c = c + a[i]
	i = h - 1
	for j in w:
		if j != 1:
			i = i + j - 1
			c = c + a[i]
	print(c)


for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	w = [int(x) for x in input().split()]
	q = w.count(1)
	a.sort()
	ans = 0
	w = sorted(w, reverse=True)
	if q != 0:
		ans = sum(a[-q:]) * 2
		a = a[:-q]
		w = [x for x in w if x != 1]
	ind = 0
	for x in w:
		ans += a[ind]
		ind += x - 1
	ans += sum(a[-len(w):])
	print(ans)


def list_input():
	return list(map(int, input().split()))

def multiple_input():
	return map(int, input().split())
for _ in range(int(input())):
	(n, k) = multiple_input()
	a = list_input()
	w = list_input()
	if n == k:
		ans = sum(a) * 2
	else:
		w.sort()
		ans = 0
		a.sort(reverse=True)
		for i in range(k):
			ans += a[i]
		(i, j) = (k - 1, 0)
		while i != n - 1:
			if w[j] == 1:
				ans += a[j]
			else:
				i += w[j] - 1
				ans += a[i]
			j += 1
	print(ans)


import heapq
rr = lambda : input()
rri = lambda : int(input())
rrm = lambda : list(map(int, input().split()))
INF = float('inf')

def solve(N, K, A, W):
	lo = 0
	hi = N - 1
	A.sort()
	W = sorted(W, reverse=True)
	total = 0
	ones = 0
	for c in W:
		if c == 1:
			ones += 1
	for _ in range(ones):
		total += A[hi] + A[hi]
		hi -= 1
	for count in W:
		if count == 1:
			break
		largest = 0
		smallest = 0
		if count == 1:
			largest = A[hi]
			smallest = A[hi]
			hi -= 1
		else:
			largest = A[hi]
			smallest = A[lo]
			hi -= 1
			lo += count - 1
		total += largest + smallest
	return total
t = rri()
for _ in range(t):
	(n, k) = rrm()
	arr = rrm()
	w = rrm()
	print(solve(n, k, arr, w))


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	(*a,) = map(int, input().split())
	(*w,) = map(int, input().split())
	a.sort()
	w.sort()
	idx = 0
	for i in range(n):
		if w[i] != 1:
			idx = i
			break
	w = w[:idx] + sorted(w[idx:], reverse=True)
	(i, j) = (0, n - 1)
	ans = 0
	for k in range(k):
		ans += a[j]
		if w[k] == 1:
			ans += a[j]
		else:
			ans += a[i]
		i += w[k] - 1
		j -= 1
	print(ans)


import sys
input = sys.stdin.readline

def solve():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		(*a,) = map(int, input().split())
		(*w,) = map(int, input().split())
		a.sort(reverse=True)
		w.sort()
		ans = sum(a[:k])
		pos = k - 1
		for (j, i) in enumerate(w):
			if i - 1:
				pos += i - 1
				ans += a[pos]
			else:
				ans += a[j]
		print(ans)
solve()


t = int(input())
while t:
	(n, k) = list(map(int, input().strip().split()))
	ints = list(map(int, input().strip().split()))
	fints = list(map(int, input().strip().split()))
	fintsi = [0] * k
	ints.sort(reverse=True)
	fints.sort()
	totalSum = 0
	i = 0
	while i < k:
		totalSum += ints[i]
		fintsi[i] = ints[i]
		fints[i] -= 1
		i += 1
	j = 0
	while j < k:
		if fints[j] == 0:
			totalSum += fintsi[j]
		else:
			i += fints[j] - 1
			fintsi[j] = ints[i]
			totalSum += fintsi[j]
			i += 1
		j += 1
	print(totalSum)
	t -= 1


t = int(input())

def solve():
	ai.sort(reverse=True)
	wi.sort()
	ans = 0
	j = 0
	for i in range(k):
		if wi[i] == 1:
			ans += ai[j] * 2
		else:
			ans += ai[j]
		j += 1
		wi[i] -= 1
	j -= 1
	for i in range(k):
		if wi[i]:
			ans += ai[j + wi[i]]
			j += wi[i]
	return ans
for _ in range(t):
	(n, k) = map(int, input().split())
	ai = list(map(int, input().split()))
	wi = list(map(int, input().split()))
	ans = solve()
	print(ans)


from sys import stdin
for _ in range(int(stdin.readline())):
	(n, k) = list(map(int, stdin.readline().split()))
	a = sorted(map(int, stdin.readline().split()))
	w = sorted(map(int, stdin.readline().split()), reverse=True)
	res = 0
	i = 0
	j = n - 1
	i_w = 0
	j_w = k - 1
	while j_w >= i_w and w[j_w] == 1:
		res += a[j] * 2
		j -= 1
		j_w -= 1
	while i_w <= j_w:
		v = w[i_w]
		res += a[i] + a[j]
		j -= 1
		i += v - 1
		i_w += 1
	print(res)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l_n = list(map(int, input().split()))
	l_k = list(map(int, input().split()))
	ans = 0
	ptr_st = 0
	ptr_en = n - 1
	l_n.sort()
	l_k.sort()
	x = -5
	for j in range(k):
		if l_k[j] == 1:
			ans += l_n[ptr_en] * 2
			ptr_en -= 1
		else:
			x = j
			break
	if x != -5:
		for j in range(k - 1, x - 1, -1):
			ans += l_n[ptr_en]
			ptr_en -= 1
			ans += l_n[ptr_st]
			ptr_st += l_k[j] - 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	A = sorted(list(map(int, input().split())), reverse=False)
	W = sorted(list(map(int, input().split())), reverse=True)
	left_max = 0
	index = 0
	res = 0
	cont_one = 0
	res_list = []
	for (i, w) in enumerate(W):
		if w != 1:
			res += A[index]
			res_list.append(A[index])
			left_max += 1
			index += w - 1
		else:
			cont_one = k - i
			break
	for i in range(cont_one):
		res += 2 * A[-1 - i]
		res_list.append(A[-1 - i])
	for i in range(left_max):
		res += A[-1 - cont_one - i]
		res_list.append(A[-1 - cont_one - i])
	print(res)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')

def main():
	for _ in range(N()):
		(n, k) = RL()
		arra = RLL()
		arrk = RLL()
		arra.sort(reverse=1)
		arrk.sort()
		ind = n
		res = 0
		(l, r) = (0, n - 1)
		for i in range(k):
			if arrk[i] != 1:
				ind = i
				break
			res += arra[i] * 2
			l += 1
		for i in range(k - 1, ind - 1, -1):
			num = arrk[i]
			res += arra[l] + arra[r]
			l += 1
			r -= num - 1
		print(res)
main()


from sys import stdin, stdout
input = stdin.readline
print = stdout.write
from collections import deque
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = deque(sorted(map(int, input().split())))
	w = list(map(int, input().split()))
	w.sort()
	ans = 0
	for i in w:
		if i == 1:
			ans += a.pop() * 2
		elif i == 2:
			ans += a.pop() + a.pop()
	w = w[::-1]
	for i in w:
		if i == 1 or i == 2:
			break
		else:
			ans += a.pop() + a.popleft()
			for _ in range(i - 2):
				a.popleft()
	ans = str(ans)
	print(ans + '\n')


import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n
avl = AvlTree()

class SegmentTree1:

	def __init__(self, data, default='z', func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a * a + b * b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
for ik in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	a = list(map(int, input().split()))
	ans = 0
	a.sort()
	for i in range(k):
		ans += l[i]
		if a[i] == 1:
			ans += l[i]
	l.sort()
	a.sort(reverse=True)
	t = 0
	for i in range(k):
		if a[i] == 1:
			break
		else:
			ans += l[t]
			t += a[i] - 1
	print(ans)


def main():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort(reverse=True)
	b.sort()
	ans = 0
	cnt = 0
	index = 0
	for i in range(k):
		if b[i] == 1:
			cnt += 1
			index = i + 1
		elif b[i] > 1:
			break
	for i in range(k):
		ans += a[i]
		if cnt > 0:
			ans += a[i]
			cnt -= 1
	i = k - 1
	while i < n and index < k:
		i += b[index] - 1
		if i > n - 1:
			break
		ans += a[i]
		index += 1
	print(ans)
	return

def test():
	t = int(input())
	while t:
		main()
		t -= 1
test()


import math
t = int(input())
for w in range(t):
	(n, k) = (int(i) for i in input().split())
	l = sorted([int(i) for i in input().split()], reverse=True)
	l1 = sorted([int(i) for i in input().split()])
	d = {}
	s = 0
	j = 0
	for i in range(k):
		if l1[i] == 1:
			s += 2 * l[j]
			j += 1
		else:
			s += l[j]
			j += 1
		l1[i] -= 1
	for i in range(k):
		if l1[i] > 0:
			s += l[j + l1[i] - 1]
			j += l1[i]
	print(s)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	w = list(map(int, input().split()))
	w.sort()
	a = [[] for i in range(k)]
	for i in range(k):
		a[i].append(l[len(l) - 1])
		l.pop()
	j = 0
	while j < k:
		for i in range(w[j]):
			if len(a[j]) < w[j]:
				a[j].append(l[len(l) - 1])
				l.pop()
			else:
				break
		j += 1
	su = 0
	for i in range(len(a)):
		s = max(a[i]) + min(a[i])
		su += s
	print(su)


from collections import Counter as C, defaultdict as D, deque as Q
from operator import itemgetter as I
from itertools import product as P
from bisect import bisect_left as BL, bisect_right as BR
from heapq import heappush as HPUSH, heappop as HPOP
from math import floor as MF, ceil as MC, gcd as MG, factorial as F, sqrt as SQRT, inf as INFINITY

def player1():
	print('Ashishgup')

def player2():
	print('FastestFinger')

def isPrime(n):
	for i in range(2, MC(SQRT(n)) + 1):
		if n % i == 0:
			return False
	return True

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		a = sorted(map(int, input().split()), reverse=True)
		w = sorted(map(int, input().split()))
		ans = 0
		(l, r) = (0, n - 1)
		start = k
		for i in range(k):
			if w[i] > 1:
				start = i
				break
			ans += a[l] * 2
			l += 1
		for j in range(k - 1, start - 1, -1):
			need = w[j]
			ans += a[l] + a[r]
			l += 1
			r = r - need + 1
		print(ans)
main()


from collections import deque
t = int(input())
for q in range(t):
	(n, k) = [int(f) for f in input().split()]
	a = [int(f) for f in input().split()]
	w = [int(f) for f in input().split()]
	a.sort()
	w.sort(reverse=True)
	beg = 0
	end = n - 1
	ans = 0
	count = 0
	while w[k - 1 - count] == 1:
		count += 1
		if count >= k:
			break
	for i in range(count):
		ans += 2 * a[end]
		end -= 1
	for i in range(k - count):
		ans += a[end]
		if w[i] > 1:
			ans += a[beg]
			beg += w[i] - 1
		else:
			ans += a[end]
		end -= 1
	print(ans)


import sys
input = sys.stdin.readline
for nt in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	b.sort()
	a.sort(reverse=True)
	h = []
	for i in range(k):
		h.append([-1] * b[i])
	for i in range(k):
		h[i][0] = a[i]
	x = k
	for i in range(k):
		for j in range(1, b[i]):
			h[i][j] = a[x]
			x += 1
	ans = 0
	for i in h:
		ans += i[0] + i[-1]
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = b.count(1)
	a.sort()
	a.reverse()
	b.sort()
	af = a[c:]
	bf = b[c:]
	final = 0
	for i in range(c):
		final += 2 * a[i]
	for i in range(len(bf)):
		final += af[i]
	index = len(bf) - 1
	for i in range(len(bf)):
		index += bf[i] - 1
		final += af[index]
	print(final)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	ky = list(map(int, input().split()))
	arr.sort()
	ky.sort(reverse=True)
	total = 0
	start = 0
	end = n - 1
	i = k - 1
	while ky[i] == 1:
		total += 2 * arr[end]
		end -= 1
		i -= 1
		if i <= 0:
			break
	for j in range(i + 1):
		total += arr[start] + arr[end]
		start += ky[j] - 1
		end -= 1
	print(total)


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	w.sort()
	ans = 0
	for i in range(k):
		ans += a[i]
		w[i] -= 1
		if w[i] == 0:
			ans += a[i]
	a = a[k:][::-1]
	i = 0
	k = 0
	w.sort(reverse=True)
	while i < len(a):
		ans += a[i]
		i += w[k]
		k += 1
	print(ans)


def max_happiness(n, k, a, w):
	a.sort()
	w.sort(reverse=True)
	ans = 0
	idx = 0
	cnt = 0
	for wi in w:
		if wi == 1:
			break
		cnt += 1
		ans += a[idx]
		idx += max(1, wi - 1)
	ans += sum(a[::-1][k - cnt:k]) + 2 * sum(a[::-1][:k - cnt])
	return ans
t = int(input())
for _ in range(t):
	(n, k) = [int(s) for s in input().split(' ')]
	a = [int(s) for s in input().split(' ')]
	w = [int(s) for s in input().split(' ')]
	ans = max_happiness(n, k, a, w)
	print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	w = sorted(list(map(int, input().split())))
	ans = 0
	z = 0
	for i in range(k):
		if w[i] == 1:
			ans += 2 * a.pop()
			z += 1
		else:
			break
	n = len(a)
	k -= z
	i = n - k
	while i < n:
		ans += a.pop()
		i += 1
	for i in range(z, z + k):
		x = w[i]
		while x > 1 and a:
			y = a.pop()
			x -= 1
		ans += y
	print(ans)


inp = lambda : int(input())
inpm = lambda : map(int, input().split())
inpl = lambda : list(inpm())
l2mn = lambda _n, _m: [[0 for __ in range(_m)] for _ in range(_n)]
l2n = lambda _n: l2mn(_n, _n)
INF = int(1e+18)
MOD = int(1000000000.0) + 7

def solve():
	(n, k) = inpm()
	a = inpl()
	w = inpl()
	a.sort()
	w.sort(reverse=True)
	res = 0
	ind = 0
	one = 0
	for i in range(k):
		x = w[i] - 1
		if x > 0:
			res += a[ind]
			ind += x
		else:
			one += 1
	print(res + sum(a[n - k:]) + sum(a[n - one:]))

def main():
	t = inp()
	for i in range(t):
		solve()
main()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	w.sort()
	pika = k
	(p, q) = (0, n - 1)
	ans = 0
	for i in range(k):
		if w[i] > 1:
			pika = i
			break
		ans += a[p] * 2
		p += 1
	for i in range(k - 1, pika - 1, -1):
		ans += a[p] + a[q]
		q = q - w[i] + 1
		p += 1
	print(ans)


def solve(arr, f_arr, n, k, ans):
	f_arr.sort(reverse=True)
	arr.sort()
	total = 0
	for i in range(k):
		val = arr.pop()
		total += val
		if f_arr[-1] == 1:
			total += val
			f_arr.pop()
	for f in f_arr:
		count = 0
		min_val = float('inf')
		while count != f - 1:
			val = arr.pop(0)
			min_val = min(min_val, val)
			count += 1
		total += min_val
	ans.append(total)

def main():
	t = int(input())
	ans = []
	for i in range(t):
		(n, k) = map(int, input().split())
		arr = list(map(int, input().split()))
		f_arr = list(map(int, input().split()))
		solve(arr, f_arr, n, k, ans)
	for i in ans:
		print(i)
main()


I = lambda : map(int, input().split())
for i in '*' * int(input()):
	(n, k) = I()
	(a, w, e) = (sorted(I(), reverse=1), sorted(I()), 0)
	q = sum(a[:k])
	for j in w:
		k += j - 1
		q += [a[k - 1], a[e]][j == 1]
		e += 1
	print(q)


import io
import os
from collections import deque
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = deque(sorted(list(map(int, input().split()))))
	b = deque(sorted(list(map(int, input().split()))))
	ans = 0
	while 1:
		e = b.popleft()
		if e == 1:
			ans += 2 * a.pop()
		else:
			b.appendleft(e)
			ans += a.pop() + a.popleft()
			b[-1] = b[-1] - 2
			while b[-1] > 0:
				a.popleft()
				b[-1] -= 1
			b.pop()
		if len(a) == 0:
			break
	print(ans)


test_case = int(input())
for _ in range(test_case):
	(n, k) = map(int, input().split())
	arr = sorted(list(map(int, input().split())))
	fr = sorted(list(map(int, input().split())))
	ans = []
	last = []
	count = len(arr) - 1
	for i in range(len(fr)):
		fr[i] -= 1
		if fr[i] == 0:
			ans.append([arr[count], arr[count]])
		else:
			ans.append([arr[count]])
		count -= 1
	count += 1
	sum = 0
	for i in range(len(fr)):
		if fr[i]:
			ans[i].append(arr[count - fr[i]])
			count -= fr[i]
	for i in range(len(fr)):
		sum += ans[i][0] + ans[i][1]
	print(sum)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	w.sort(reverse=True)
	s = 0
	ans = 0
	ones = 0
	ap = sorted(a)
	index = 1
	for i in range(len(w)):
		if w[i] == 1:
			ones = ones + 1
		elif w[i] > 2:
			ans = ans + sum(ap[index:index + w[i] - 2])
			index = index + w[i] - 1
	print((ones > 0) * sum(ap[-ones:]) + sum(ap) - ans)


from itertools import accumulate as a
for i in range(int(input())):
	(n, k) = list(map(int, input().split()))
	A = sorted(map(int, input().split()), reverse=True)
	W = sorted(map(int, input().split()))
	f = W.count(1)
	ans = sum(A[:k]) + sum(A[:f])
	for w in W[f:]:
		k += w - 1
		ans += A[k - 1]
	print(ans)


from sys import stdin, stdout
import math, queue, heapq
fastinput = stdin.readline
fastout = stdout.write
t = int(fastinput())
while t:
	t -= 1
	(n, k) = map(int, fastinput().split())
	intt = list((int(i) for i in fastinput().split()))
	ik = list(map(int, fastinput().split()))
	intt.sort()
	ik.sort(reverse=True)
	s = 0
	for i in range(k):
		x = intt.pop()
		if ik[-1] == 1:
			s += x * 2
			ik.pop()
		else:
			s += x
	start = 0
	for i in ik:
		s += intt[start]
		start += i - 1
	print(s)


import sys
import heapq
import math
from collections import deque
MOD = 1000000007

def primes(n):
	sieve = [True] * n
	for i in range(3, int(n ** 0.5) + 1, 2):
		if sieve[i]:
			sieve[i * i::2 * i] = [False] * ((n - i * i - 1) // (2 * i) + 1)
	return [2] + [i for i in range(3, n, 2) if sieve[i]]

def factor(n, l, d):
	F = False
	for p in l:
		if n % p == 0:
			if p in d:
				d[p] += 1
			else:
				d[p] = 1
			F = True
			break
	if F:
		factor(n // p, l, d)

def find(parent, i):
	if parent[i] != i:
		parent[i] = find(parent, parent[i])
	return parent[i]

def union(parent, rank, xx, yy):
	x = find(parent, xx)
	y = find(parent, yy)
	if rank[x] > rank[y]:
		parent[y] = x
	elif rank[y] > rank[x]:
		parent[x] = y
	else:
		parent[y] = x
		rank[x] += 1
ans = 0
n = int(sys.stdin.readline().strip())
dd = {'R': 'L', 'L': 'R'}
for testj in range(n):
	ans = 0
	c = 1.0
	pre = [0]
	AB = sys.stdin.readline().strip().split()
	nb = sys.stdin.readline().strip().split()
	for i in range(len(nb)):
		nb[i] = int(nb[i])
	nb.sort()
	wt = sys.stdin.readline().strip().split()
	wto = []
	wtt = []
	for i in range(len(wt)):
		wt[i] = int(wt[i])
		if wt[i] == 1:
			wto.append(wt[i])
		else:
			wtt.append(wt[i])
	wtt.sort(reverse=True)
	lo = 0
	hi = len(nb) - 1
	for n in wto:
		ans += nb[hi] * 2
		hi -= 1
	for n in wtt:
		ans += nb[hi]
		hi -= 1
		n -= 2
		ans += nb[lo]
		lo += 1
		while n > 0:
			lo += 1
			n -= 1
	print(ans)


import copy
import heapq
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	suba = copy.deepcopy(a)
	ans = 0
	sumofmin = 0
	sumofmax = 0
	heapq.heapify(a)
	sa = n - sum(w)
	subw = copy.deepcopy(w)
	subw = list(map(lambda x: x * -1, subw))
	heapq.heapify(subw)
	for i in range(sa):
		heapq.heappop(a)
	for i in range(k):
		temp = -heapq.heappop(subw)
		if temp > 1:
			sumofmin += heapq.heappop(a)
			for j in range(temp - 2):
				fake = heapq.heappop(a)
	suba = list(map(lambda x: x * -1, suba))
	heapq.heapify(suba)
	heapq.heapify(w)
	for i in range(k):
		x = heapq.heappop(w)
		if x > 1:
			sumofmax -= heapq.heappop(suba)
		else:
			sumofmax -= 2 * heapq.heappop(suba)
	print(sumofmax + sumofmin)


from array import array
from math import log

def solve(n, k, nums, ws):
	nums.sort()
	nums = nums[::-1]
	ws.sort()
	result = 0
	t = 0
	t2 = []
	for w in ws:
		t2 += [nums[t]]
		t += 1
	i = -1
	for w in ws:
		i += 1
		if w == 1:
			result += t2[i] * 2
			continue
		result += t2[i] + nums[t + w - 2]
		t += w - 1
	return result
test_cases = int(input())
for i in range(test_cases):
	(n, k) = [int(a) for a in input().split(' ')]
	nums = [int(a) for a in input().split(' ')]
	ws = [int(a) for a in input().split(' ')]
	print(str(solve(n, k, nums, ws)))


r = lambda : list(map(int, input().split()))
for _ in range(int(input())):
	(n, k) = r()
	a = sorted(r(), reverse=True)
	s = sorted(r())
	ans = 0
	j = k
	for i in range(k):
		s[i] -= 1
		ans += a[i]
		if s[i] == 0:
			ans += a[i]
	for i in range(k):
		if s[i] > 0:
			ans += a[j + s[i] - 1]
		j += s[i]
	print(ans)


from collections import defaultdict
import sys, math
f = None
try:
	f = open('q1.input', 'r')
except IOError:
	f = sys.stdin
if 'xrange' in dir(__builtins__):
	range = xrange
sys.setrecursionlimit(10 ** 2)

def print_case_iterable(case_num, iterable):
	print('Case #{}: {}'.format(case_num, ' '.join(map(str, iterable))))

def print_case_number(case_num, iterable):
	print('Case #{}: {}'.format(case_num, iterable))

def print_iterable(A):
	print(' '.join(A))

def read_int():
	return int(f.readline().strip())

def read_int_array():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def read_string():
	return list(f.readline().strip())

def ri():
	return int(f.readline().strip())

def ria():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def rs():
	return list(f.readline().strip())

def bi(x):
	return bin(x)[2:]
from collections import deque
import math
NUMBER = 10 ** 9 + 7

def factorial(n):
	M = NUMBER
	f = 1
	for i in range(1, n + 1):
		f = f * i % M
	return f

def mult(a, b):
	return a * b % NUMBER

def minus(a, b):
	return (a - b) % NUMBER

def plus(a, b):
	return (a + b) % NUMBER

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, y, x) = egcd(b % a, a)
		return (g, x - b // a * y, y)

def modinv(a):
	m = NUMBER
	(g, x, y) = egcd(a, m)
	if g != 1:
		raise Exception('modular inverse does not exist')
	else:
		return x % m

def choose(n, k):
	if n < k:
		assert false
	return mult(factorial(n), modinv(mult(factorial(k), factorial(n - k)))) % NUMBER
from collections import deque, defaultdict
import heapq
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

def dfs(g, timeIn, timeOut, depths, parents):
	cnt = 0
	stack = [[1, 0, 0, 0]]
	while stack:
		(v, neig_i, parent, depth) = stack[-1]
		parents[v] = parent
		depths[v] = depth
		if neig_i == 0:
			timeIn[v] = cnt
			cnt += 1
		while neig_i < len(g[v]):
			u = g[v][neig_i]
			if u == parent:
				neig_i += 1
				continue
			stack[-1][1] = neig_i + 1
			stack.append([u, 0, v, depth + 1])
			break
		if neig_i == len(g[v]):
			stack.pop()
			timeOut[v] = cnt
			cnt += 1
cnt = 0

@bootstrap
def dfs(v, adj, timeIn, timeOut, depths, parents, parent=0, depth=0):
	global cnt
	parents[v] = parent
	depths[v] = depth
	timeIn[v] = cnt
	cnt += 1
	for u in adj[v]:
		if u == parent:
			continue
		yield dfs(u, adj, timeIn, timeOut, depths, parents, v, depth + 1)
	timeOut[v] = cnt
	cnt += 1
	yield

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	return a * b / gcd(a, b)

def solution(a, n, w, k):
	w.sort(reverse=True)
	a.sort()
	sm = 0
	while w and w[-1] == 1 and a:
		sm += 2 * a[-1]
		w.pop()
		a.pop()
	k = len(w)
	n = len(a)
	sm += sum(a[n - k:n])
	w.sort()
	a.sort(reverse=True)
	while w and a:
		sm += a[-1]
		x = w[-1] - 1
		for _ in range(x):
			a.pop()
		w.pop()
	return sm

def main():
	T = ri()
	for i in range(T):
		(n, k) = ria()
		a = ria()
		w = ria()
		x = solution(a, n, w, k)
		if 'xrange' not in dir(__builtins__):
			print(x)
		else:
			(print >> output, str(x))
	if 'xrange' in dir(__builtins__):
		print(output.getvalue())
		output.close()
if 'xrange' in dir(__builtins__):
	import cStringIO
	output = cStringIO.StringIO()
main()


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	c = list(map(int, input().split()))
	d = list(map(int, input().split()))
	c = sorted(c)
	f = 0
	l = a - 1
	su = 0
	for j in range(len(d)):
		if d[j] == 1:
			su = su + 2 * c[l]
			l = l - 1
	d = sorted(d, reverse=True)
	for j in range(b):
		if d[j] != 1:
			su = su + c[l]
			l = l - 1
			su = su + c[f]
			f = f + d[j] - 1
	print(su)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	p = list(map(int, input().split()))
	l.sort(reverse=True)
	p.sort()
	ans = 0
	for i in range(m):
		ans += l[i]
	j = m
	for i in range(m):
		if p[i] == 1:
			ans += l[i]
		else:
			while p[i] - 1 > 0:
				j += 1
				p[i] -= 1
			ans += l[j - 1]
	print(ans)


from collections import OrderedDict

def solve(n, k, arr1, arr2):
	ans = 0
	arr1.sort(reverse=True)
	arr2.sort()
	(ptr, l, r) = (k, 0, n - 1)
	for i in range(k):
		if arr2[i] > 1:
			ptr = i - 1
			break
		else:
			ans += 2 * arr1[l]
			l += 1
	for i in range(k - 1, ptr, -1):
		ans += arr1[r] + arr1[l]
		l += 1
		r = r - arr2[i] + 1
	return ans

def main():
	t = int(input())
	for i in range(t):
		(n, k) = map(int, input().split())
		arr1 = list(map(int, input().split()))
		arr2 = list(map(int, input().split()))
		print(solve(n, k, arr1, arr2))
main()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	w = list(map(int, input().split()))
	l.sort()
	w.sort()
	i = 0
	ans = 0
	while len(l) != 0:
		l1 = []
		l1.append(l[-1])
		num = len(l) - (k - i) - (w[i] - 1)
		l.pop(-1)
		for j in range(w[i] - 1):
			l1.append(l[num])
			l.pop(num)
		ans = ans + (min(l1) + max(l1))
		i = i + 1
	print(ans)


import sys
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

def input():
	return fast_reader().strip()

def print(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer('\n')
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	w.sort()
	ones = w.count(1)
	ans = 2 * sum(a[:ones])
	a = a[ones:]
	w = w[ones:]
	w.sort(reverse=True)
	a.sort()
	st = 0
	en = len(a) - 1
	for i in range(len(w)):
		ans += a[en] + a[st]
		en -= 1
		st += w[i] - 1
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	wrr = list(map(int, input().split()))
	arr.sort(reverse=True)
	cnt = sum(arr[:k])
	cnt += sum(arr[:wrr.count(1)])
	arr = arr[k:]
	arr.sort()
	wrr = list(sorted(filter(lambda o: o, map(lambda o: o - 1, wrr)), reverse=True))
	idx = 0
	for w in wrr:
		cnt += arr[idx]
		idx += w
	print(cnt)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	a.reverse()
	w.sort()
	ans = 0
	for i in range(k):
		ans += a[i]
	pointer = k - 1
	for i in range(k):
		if w[i] == 1:
			ans += a[i]
			continue
		pointer += w[i] - 1
		ans += a[pointer]
	print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def op(s):
	s2 = ''
	found = False
	for i in range(len(s)):
		if found and s[i] == '0':
			continue
		elif found:
			found = False
			s2 += '01'
			continue
		if not found and s[i] == '1' and (i != len(s) - 1 and s[i + 1] == '0'):
			found = True
		else:
			s2 += s[i]
			continue
	if found:
		s2 += '0'
	if s2 == s:
		return s
	else:
		return op(s2)
from collections import deque
for _ in range(int(input()) if True else 1):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	b = sorted(b)
	a = sorted(a)
	a = deque(a)
	ans = 0
	b1 = b.count(1)
	for i in range(k):
		next = a.pop()
		ans += next
		if i < b1:
			ans += next
	for i in b:
		for j in range(i - 1):
			if j == i - 2:
				ans += a.pop()
			else:
				a.pop()
	print(ans)


t = int(input())
for z in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	ans = s = 0
	for i in range(k):
		if b[i] == 1:
			ans += 2 * a[n - s - 1]
			s += 1
		else:
			break
	p = s
	u = 0
	for i in range(k - 1, s - 1, -1):
		ans += a[u]
		ans += a[n - 1 - p]
		p += 1
		u += b[i] - 1
	print(ans)


import math
import sys
sys.setrecursionlimit(10 ** 4)

def Divisors(n):
	l = []
	i = 2
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
		i = i + 1
	return l

def SieveOfEratosthenes(n):
	l = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			l.append(p)
	return l

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(n)
	return l

def Factors(n):
	result = []
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if i == n / i:
				result.append(i)
			else:
				result.append(i)
				result.append(n // i)
	result.append(1)
	result.append(n)
	return result

def maxSubArraySum(a):
	max_so_far = 0
	max_ending_here = 0
	size = len(a)
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def longestsubarray(arr, n, k):
	current_count = 0
	max_count = 0
	for i in range(0, n, 1):
		if arr[i] % k != 0:
			current_count += 1
		else:
			current_count = 0
		max_count = max(current_count, max_count)
	return max_count

def main():
	(n, k) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	w = list(map(int, input().split()))
	l.sort()
	w.sort()
	f = []
	for j in range(0, n):
		f.append(0)
	s = 0
	p = n - 1
	for j in range(0, k):
		s += l[p]
		f[p] = 1
		p -= 1
		w[j] -= 1
		if w[j] == 0:
			s += l[p + 1]
	f1 = 0
	for j in range(0, k):
		if w[j] != 0:
			while w[j] != 0:
				w[j] -= 1
				if w[j] == 0:
					s += l[p]
					p -= 1
				else:
					p -= 1
	print(s)
t = int(input())
for i in range(0, t):
	main()


for _ in range(int(input())):
	(i_int, i_kum) = map(int, input().split())
	inty = [int(x) for x in input().split()]
	kumple = [int(x) for x in input().split()]
	wynik = 0
	kumple.sort()
	inty.sort(reverse=True)
	(sta, kon) = (0, i_int - 1)
	sta_kum = 0
	while sta_kum < i_kum and kumple[sta_kum] == 1:
		wynik += inty[sta] * 2
		sta_kum += 1
		sta += 1
	kumple = kumple[sta_kum:]
	for x in kumple[::-1]:
		wynik += inty[sta]
		wynik += inty[kon]
		sta += 1
		kon -= x - 1
	print(wynik)


from sys import stdin, stdout
int_in = lambda : int(stdin.readline())
arr_in = lambda : [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for _ in range(rows)]
str_in = lambda : stdin.readline().strip()
out = lambda o: stdout.write('{}\n'.format(o))
arr_out = lambda o: out(' '.join(map(str, o)))
bool_out = lambda o: out('YES' if o else 'NO')
tests = lambda : range(1, int_in() + 1)
case_out = lambda i, o: out('Case #{}: {}'.format(i, o))

def solve(n, k, a, w):
	a.sort(reverse=True)
	sum_of_max = sum(a[:k])
	w.sort()
	sum_of_min = sum(a[:w.count(1)])
	p1 = n - 1
	for item in sorted(map(lambda x: x - 1, filter(lambda x: x > 1, w)), reverse=True):
		sum_of_min += a[p1]
		p1 -= item
	return sum_of_max + sum_of_min
for i in tests():
	(n, k) = arr_in()
	a = arr_in()
	w = arr_in()
	out(solve(n, k, a, w))


import math
from decimal import *
for _ in range(int(input())):
	ans = 0
	(n, k) = map(int, input().split())
	ns = sorted(list(map(int, input().split())))
	p = sorted(list(map(int, input().split())))
	(p1, p2, cnt) = (0, n - 1, 0)
	while p[cnt] == 1:
		ans += ns[p2] * 2
		p2 -= 1
		cnt += 1
		if cnt == k:
			break
	p = sorted(p, reverse=True)
	for x in range(k - cnt):
		ans += ns[p2]
		ans += ns[p1]
		p2 -= 1
		for i in range(p[x] - 1):
			p1 += 1
	print(ans)


import os
import sys
from io import BytesIO, IOBase
import math
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	lf = list(map(int, input().split()))
	l.sort(reverse=True)
	sum = 0
	lf.sort()
	for i in range(k):
		if lf[i] == 1:
			sum += 2 * l[i]
		else:
			sum += l[i]
	l.sort()
	narr = list()
	ar = sorted(l)
	lf.sort(reverse=True)
	c = 0
	res = 0
	for i in range(k):
		if lf[i] == 1:
			break
		else:
			sum += l[c]
			c += lf[i] - 1
	print(sum)


import sys
input = lambda : sys.stdin.readline().rstrip()
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	A = sorted([int(i) for i in input().split()], reverse=True)
	W = sorted([int(i) for i in input().split()])
	C = [0] * k
	for (i, w) in enumerate(W):
		if i == 0:
			C[i] += w - 1
		else:
			C[i] += C[i - 1] + w - 1
	ans = 0
	for i in range(k):
		if C[i] == 0:
			ans += A[i] * 2
		else:
			ans += A[i] + A[k - 1 + C[i]]
	print(ans)


import sys
import math as mt
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	w = list(map(int, input().split()))
	l.sort(reverse=True)
	w.sort()
	i = 0
	ans = 0
	j = 0
	j1 = k
	for i in range(k):
		if w[i] == 1:
			ans += 2 * l[j]
		else:
			ans += l[j]
		w[i] -= 1
		mini = 0
		for i1 in range(w[i]):
			mini = l[j1]
			j1 += 1
		ans += mini
		j += 1
		i += 1
	print(ans)


from sys import stdin, stdout
test = int(stdin.readline())
for _ in range(test):
	(n, k) = map(int, stdin.readline().split())
	a = [int(x) for x in stdin.readline().split()]
	w = [int(x) for x in stdin.readline().split()]
	a.sort()
	w.sort(reverse=True)
	segs = [[] for i in range(k)]
	last_ind = 0
	for i in range(n - k, n):
		segs[i - (n - k)].append(a[i])
		for j in range(last_ind, last_ind + w[i - (n - k)] - 1):
			segs[i - (n - k)].append(a[j])
		last_ind = last_ind + w[i - (n - k)] - 1
	ans = 0
	for i in segs:
		ans += min(i) + max(i)
	print(ans)


from sys import stdin
input = lambda : stdin.readline().strip()
char = [chr(i) for i in range(97, 123)]
CHAR = [chr(i) for i in range(65, 91)]
mp = lambda : list(map(int, input().split()))
INT = lambda : int(input())
rn = lambda : range(INT())
from math import ceil, sqrt, factorial, gcd
for _ in rn():
	(n, k) = mp()
	l = mp()
	l = sorted(l, reverse=True)
	k_n = mp()
	k_n.sort()
	ans = [[] for i in range(k)]
	i = 0
	j = 0
	while j < k:
		if k_n[j] != 0:
			ans[j].append(l[i])
			k_n[j] -= 1
			i += 1
		j += 1
	for j in range(k):
		while k_n[j] > 0:
			ans[j].append(l[i])
			i += 1
			k_n[j] -= 1
	res = 0
	for j in ans:
		if len(j) == 1:
			res += 2 * j[0]
		elif len(j) == 2:
			res += sum(j)
		else:
			res += max(j)
			res += min(j)
	print(res)


import math
from collections import deque

def main():
	t = Iint()
	for _ in range(t):
		(n, k) = Imap()
		a = Ilist()
		a.sort()
		a = deque(a)
		w = sorted(Ilist())
		ans = 0
		just_broke_1 = True
		for (i, wi) in en(w):
			if wi == 1:
				ans += a.pop() * 2
			elif just_broke_1:
				just_broke_1 = False
				count = k - i
				for j in range(count):
					ans += a.pop()
			if not just_broke_1:
				for j in range(wi - 2):
					a.pop()
				ans += a.pop()
		print(ans)

def I():
	return input()

def Iint():
	return int(input())

def Ilist():
	return list(map(int, input().split()))

def Imap():
	return map(int, input().split())

def Plist(li, s=' '):
	print(s.join(map(str, li)))
FIO = True
if FIO:
	from io import BytesIO, IOBase
	import sys
	import os
en = enumerate
if not FIO:
	if __name__ == '__main__':
		main()
		exit()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	ai = list(map(int, input().split()))
	wi = list(map(int, input().split()))
	ai.sort()
	wi = sorted(wi, reverse=True)
	try:
		num1 = k - wi.index(1)
	except:
		num1 = -n
	ans = 0
	num = 0
	for i in range(k):
		if wi[i] == 1:
			break
		ans += ai[num]
		num += wi[i] - 1
	print(sum(ai[-num1:]) + sum(ai[-k:]) + ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	cap = list(map(int, input().split()))
	arr.sort()
	cap.sort()
	l = 0
	r = n - 1
	res = 0
	for i in range(k):
		if cap[i] == 1:
			res += 2 * arr[r]
		else:
			res += arr[r]
		r -= 1
		cap[i] -= 1
	cap.sort(reverse=True)
	for i in range(k):
		x = cap[i]
		if not x:
			continue
		res += arr[l]
		l += x
	print(res)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	ans = 0
	c = w.count(1)
	ans += 2 * sum(a[-c:]) * (c != 0)
	k -= c
	w.sort()
	ans += sum(a[-c - 1:-c - k - 1:-1])
	w = w[c:]
	a = a[-c - k - 1::-1]
	ind = -1
	for x in w:
		ind += x - 1
		ans += a[ind]
	print(ans)


from __future__ import division, print_function
from sys import stdin, stdout
import bisect
import math
import heapq
i_m = 9223372036854775807

def inin():
	return int(input())

def stin():
	return input()

def spin():
	return map(int, stin().split())

def lin():
	return list(map(int, stin().split()))

def matrix(n):
	return [list(map(int, input().split())) for i in range(n)]

def count2Dmatrix(i, list):
	return sum((c.count(i) for c in list))

def modinv(n, p):
	return pow(n, p - 2, p)

def GCD(x, y):
	x = abs(x)
	y = abs(y)
	if min(x, y) == 0:
		return max(x, y)
	while y:
		(x, y) = (y, x % y)
	return x

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l
prime = []

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j
for _ in range(inin()):
	(n, k) = spin()
	a = lin()
	w = lin()
	a = sorted(a)[::-1]
	w = sorted(w)
	s = 0
	s = sum(a[:k])
	tmp = k - 1
	for i in range(k):
		if w[i] == 1:
			s += a[i]
		else:
			tmp += w[i] - 1
			s += a[tmp]
	print(s)


t = int(input())
while t:
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	w = list(map(int, input().split()))
	l.sort()
	w.sort()
	ans = 0
	last = n - 1
	for i in range(0, k):
		ans += l[last]
		if w[i] == 1:
			ans += l[last]
		last -= 1
	for i in range(0, k):
		if w[i] != 1:
			last -= w[i] - 2
			ans += l[last]
			last -= 1
	print(ans)
	t -= 1


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	A.sort(reverse=True)
	B.sort()
	j = 0
	Ans = 0
	for i in range(len(B)):
		Ans += A[j]
		if B[i] == 1:
			Ans += A[i]
		j += 1
	for i in range(len(B)):
		if j == len(A):
			break
		j += B[i] - 1
		if B[i] > 1:
			Ans += A[j - 1]
	print(Ans)


import sys
from collections import deque
readline = sys.stdin.readline

def solve():
	(N, K) = map(int, readline().split())
	A = list(map(int, readline().split()))
	W = list(map(int, readline().split()))
	A.sort()
	W.sort(reverse=True)
	bufs = [[] for i in range(len(W))]
	mins = [None] * len(W)
	q = deque(A)
	for (i, w) in enumerate(W):
		if w == 1:
			continue
		else:
			mins[i] = q.popleft()
			for j in range(w - 2):
				q.popleft()
	ans = 0
	for i in range(len(mins)):
		if mins[i] is None:
			ans += q.pop() * 2
		else:
			ans += mins[i]
	ans += sum(q)
	print(ans)
T = int(readline())
for i in range(T):
	solve()


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def solve():
	(n, k) = num_input()
	arr = sorted(list_input())
	brr = sorted(list_input(), reverse=True)
	i = k - 1
	count = 0
	ans = 0
	(start, end) = (0, n - 1)
	while i >= 0:
		if brr[i] == 1:
			count += 1
		else:
			break
		i -= 1
	for i in range(count):
		ans += 2 * arr[end]
		end -= 1
	for i in range(k - count):
		temp = brr[i]
		ans += arr[end]
		end -= 1
		temp -= 1
		if temp > 0:
			ans += arr[start]
			start += temp
	print(ans)
t = int(input())
for _ in range(t):
	solve()


ans = []
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	u = list(map(int, input().split()))
	w = list(map(int, input().split()))
	u.sort()
	w.sort(reverse=1)
	ansi = 0
	ind = 0
	for i in range(k):
		if w[i] == 1:
			ansi += u[n - k + i] * 2
		else:
			ansi += u[ind] + u[n - k + i]
		ind += w[i] - 1
	ans.append(ansi)
print('\n'.join(map(str, ans)))


t = int(input())
for i in range(t):
	(n, m) = [int(n) for n in input().split()]
	arr = list(map(int, input().strip().split()))
	brr = list(map(int, input().strip().split()))
	arr.sort()
	brr.sort()
	arr.reverse()
	sumi = 0
	i = 0
	j = m
	count = 0
	while True:
		w = brr[i]
		sumi = sumi + arr[i]
		w = w - 1
		if w == 0:
			sumi = sumi + arr[i]
			i = i + 1
			count = count + 1
			if count == m:
				break
		else:
			t = j + w - 1
			sumi = sumi + arr[t]
			j = t + 1
			i = i + 1
			count = count + 1
			if count == m:
				break
	print(sumi)


it = lambda : list(map(int, input().strip().split()))
INF = float('inf')

def solve():
	(n, k) = it()
	H = it()
	W = it()
	H.sort(reverse=True)
	W.sort()
	max_ = [-INF] * k
	min_ = [-INF] * k
	for i in range(k):
		max_[i] = H[i]
	i = n - 1
	for j in range(k - 1, -1, -1):
		if W[j] > 1:
			assert i >= k
			min_[j] = H[i]
			i -= W[j] - 1
	ans = 0
	for j in range(k):
		ans += max_[j]
		if min_[j] == -INF:
			ans += max_[j]
		else:
			ans += min_[j]
	return ans
T = int(input())
for _ in range(T):
	print(solve())


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	gifts = sorted(map(int, input().split()))[::-1]
	friends = sorted(map(int, input().split()))[::-1]
	f = friends.count(1)
	ans = sum(gifts[:f]) * 2
	i = f
	j = n - 1
	for l in range(k - i):
		ans += gifts[i] + gifts[j]
		i += 1
		j = j - friends[l] + 1
	print(ans)


t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	ar = list(map(int, input().split()))
	frnds = list(map(int, input().split()))
	ar.sort()
	frnds.sort(reverse=True)
	ans = 0
	i = 0
	j = n - k
	for f in frnds:
		if f == 1:
			ans += 2 * ar[j]
			j += 1
		else:
			ans += ar[i] + ar[j]
			i += f - 1
			j += 1
	print(ans)
	t -= 1


production = True
import sys, math, collections

def input(input_format=0, multi=0):
	if multi > 0:
		return [input(input_format) for i in range(multi)]
	else:
		next_line = sys.stdin.readline()[:-1]
		if input_format >= 10:
			use_list = False
			input_format = int(str(input_format)[-1])
		else:
			use_list = True
		if input_format == 0:
			formatted_input = [next_line]
		elif input_format == 1:
			formatted_input = list(map(int, next_line.split()))
		elif input_format == 2:
			formatted_input = list(map(float, next_line.split()))
		elif input_format == 3:
			formatted_input = list(next_line)
		elif input_format == 4:
			formatted_input = (lambda x: [x[0], list(map(int, x[1:]))])(next_line.split())
		elif input_format == 5:
			formatted_input = (lambda x: [x[0], list(map(float, x[1:]))])(next_line.split())
		elif input_format == 6:
			formatted_input = next_line.split()
		else:
			formatted_input = [next_line]
		return formatted_input if use_list else formatted_input[0]

def out(output_line, output_format=0, newline=True):
	formatted_output = ''
	if output_format == 0:
		formatted_output = str(output_line)
	elif output_format == 1:
		formatted_output = ' '.join(map(str, output_line))
	elif output_format == 2:
		formatted_output = '\n'.join(map(str, output_line))
	print(formatted_output, end='\n' if newline else '')

def log(*args):
	if not production:
		print('$$$', end='')
		print(*args)
enum = enumerate

def solve():
	(n, k) = input(1)
	a = input(1)
	w = input(1)
	a.sort(reverse=True)
	w.sort()
	ai = 0
	t = 0
	log(a, w)
	b = 0
	for (i, j) in enum(w):
		t += a[i + b]
		if j == 1:
			t += a[i + b]
		elif j == 2:
			t += a[i + b + 1]
			b += 1
			w[i] -= 1
		w[i] -= 1
	log(t)
	log(w)
	a.reverse()
	w.reverse()
	a = a[:-k]
	log(a)
	for i in w:
		if i > 0:
			t += a[ai]
			ai += i
	out(t)
	return
for i in range(input(11)):
	solve()


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
from copy import deepcopy

def gift():
	for _ in range(t):
		(n, k) = list(map(int, input().split()))
		gifts = list(map(int, input().split()))
		friends = list(map(int, input().split()))
		gifts.sort()
		friends.sort()
		res = 0
		curr = 0
		equalfriendcount = 0
		desiredgift = 0
		calit = False
		(s, e) = (0, n - 1)
		rem = []
		for ele in friends:
			if ele == 1:
				res += gifts[e] * 2
				e -= 1
			else:
				rem.append(ele)
		rem = rem[::-1]
		for ele in rem:
			res += gifts[s]
			res += gifts[e]
			s += ele - 1
			e -= 1
		yield res
t = int(input())
ans = gift()
print(*ans, sep='\n')


from collections import Counter
import math
import sys
from bisect import bisect, bisect_left, bisect_right

def input():
	return sys.stdin.readline().strip()

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def mod():
	return 10 ** 9 + 7
for i in range(INT()):
	(n, k) = MAP()
	arr1 = LIST()
	arr2 = LIST()
	arr1.sort(reverse=True)
	arr2.sort()
	ans = 0
	s = 0
	e = n - 1
	for i in range(k):
		if arr2[i] == 1:
			ans += 2 * arr1[s]
		else:
			ans += arr1[s]
		arr2[i] -= 1
		s += 1
	for i in range(k - 1, -1, -1):
		if arr2[i] > 0:
			ans += arr1[e]
		else:
			break
		e -= arr2[i]
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	a = sorted(list(map(int, input().split())))
	w = sorted(list(map(int, input().split())))
	s = 0
	for i in range(1, k + 1):
		s += a[-i]
	ind = k
	for j in range(len(w)):
		if w[j] == 1:
			s += a[-j - 1]
		else:
			s += a[-(ind + w[j] - 1)]
			ind += w[j] - 1
	print(s)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ar = list(map(int, input().split()))
	wr = list(map(int, input().split()))
	ar.sort()
	wr.sort()
	ans = 0
	ll = 0
	rr = n - 1
	flag = True
	for i in range(k):
		if wr[i] == 1:
			ans += ar[rr] * 2
			rr -= 1
		else:
			flag = False
			break
	if not flag:
		ex = []
		for j in range(k - 1, i - 1, -1):
			ex.append(wr[j])
		for ii in range(len(ex)):
			ans += ar[ll]
			ans += ar[rr]
			rr -= 1
			ll += ex[ii] - 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	m = list(map(int, input().split()))
	a.sort(reverse=True)
	m.sort(reverse=True)
	fill = [0 for i in range(k)]
	j = 0
	for i in range(k):
		if m[i] == 1:
			fill[i] = a[j] * 2
			j += 1
	for i in range(k):
		if m[i] != 1:
			fill[i] += a[j]
			j += 1
	a = a[j:]
	a.sort()
	j = 0
	for i in range(k):
		if m[i] > 1:
			fill[i] += a[j]
			j += m[i] - 1
	print(sum(fill))


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(sorted(map(int, input().split())))
	w = list(sorted(map(int, input().split())))
	z = n - k
	ans = 0
	for j in range(k):
		if w[j] == 1:
			ans += 2 * a[n - j - 1]
		else:
			z -= w[j] - 1
			ans += a[n - j - 1] + a[z]
	print(ans)


import sys
input = sys.stdin.buffer.readline
Q = int(input())
Query = []
for _ in range(Q):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	W = list(map(int, input().split()))
	Query.append((N, K, A, W))
for (N, K, A, W) in Query:
	A.sort()
	W.sort(reverse=True)
	count1 = W.count(1)
	W = W[:K - count1]
	ans = sum(A[N - K:]) + sum(A[N - count1:])
	ind = 0
	for w in W:
		ans += A[ind]
		ind += w - 1
	print(ans)


T = int(input())
for _ in range(T):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a = sorted(a)
	w = sorted(w, key=lambda x: -x)
	ans = 0
	l = 0
	r = n - 1
	for i in range(k - 1, -1, -1):
		if w[i] == 1:
			x = a[r] * 2
		else:
			x = a[r]
		ans += x
		r = r - 1
	for i in range(k):
		if w[i] > 1:
			ans += a[l]
			l += w[i] - 1
	print(ans)


import heapq

def read_list():
	return list(map(int, input().strip().split(' ')))

def print_list(l):
	print(' '.join(map(str, l)))
N = int(input())
for _ in range(N):
	(n, k) = read_list()
	g = read_list()
	w = read_list()
	g.sort(reverse=True)
	w.sort()
	res = sum(g[:k])
	i = k
	for j in range(k):
		t = w[j]
		if t == 1:
			res += g[j]
		else:
			res += g[i + t - 2]
			i += t - 1
	print(res)


import sys
from fractions import gcd
from math import ceil, sqrt, sin, pi, tan
from collections import defaultdict
read = sys.stdin.buffer.readline
import heapq
mi = lambda : map(int, read().split())
li = lambda : list(mi())
cin = lambda : int(read())
as0 = ord('0')
as1 = ord('1')
for _ in range(cin()):
	(n, k) = mi()
	a = li()
	w = li()
	a.sort()
	w.sort()
	ans = sum(a[n - k:])
	j = n - k
	for i in range(k):
		w[i] -= 1
		if w[i] == 0:
			ans += a[n - 1 - i]
		else:
			j -= w[i]
			ans += a[j]
	print(ans)


import sys
from collections import deque

def input():
	return sys.stdin.readline()[:-1]

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		a = deque(sorted(list(map(int, input().split()))))
		w = sorted(list(map(int, input().split())))
		h = [[] for _ in range(k)]
		p = 0
		for i in range(k):
			h[i].append(a.pop())
		while len(a) > 0:
			while len(h[p % k]) < w[p % k]:
				h[p % k].append(a.pop())
			p += 1
		ans = 0
		for e in h:
			ans += e[0] + e[-1]
		print(ans)
main()


from fractions import Fraction
from collections import defaultdict
import math
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
krish = 1000
res = 900
ans = krish - res
t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	l1 = list([int(x) for x in input().split()])
	l2 = list([int(x) for x in input().split()])
	l1.sort(reverse=True)
	l2.sort()
	s = 0
	for i in range(k):
		if l2[i] == 1:
			s += 2 * l1[i]
		else:
			s += l1[i]
		res += 1
	l1.sort()
	l2.sort(reverse=True)
	pos = 0
	for j in range(k):
		if l2[j] == 1:
			break
		else:
			s += l1[pos]
			pos += l2[j] - 1
	print(s)


for _ in range(int(input())):
	a = input().split(' ')
	n = int(a[0])
	k = int(a[1])
	a = input().split(' ')
	for i in range(n):
		a[i] = int(a[i])
	a.sort(reverse=True)
	w = input().split(' ')
	for i in range(k):
		w[i] = int(w[i])
	w.sort()
	ans = 0
	wfirst = 0
	afirst = 0
	while wfirst != k and w[wfirst] < 3:
		if w[wfirst] == 1:
			ans = ans + a[afirst] + a[afirst]
			afirst += 1
			wfirst += 1
		else:
			ans = ans + a[afirst] + a[afirst + 1]
			afirst += 2
			wfirst += 1
	wlast = k - 1
	alast = n - 1
	while wlast >= wfirst:
		val = w[wlast]
		ans = ans + a[afirst] + a[alast]
		afirst += 1
		alast = alast - val + 1
		wlast -= 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = sorted(map(int, input().split()), reverse=True)
	w = sorted(map(int, input().split()))
	ans = 0
	l = 0
	r = n - 1
	u = 0
	while u < len(w) and w[u] == 1:
		ans += arr[l] * 2
		u += 1
		l += 1
	for i in range(k - 1, u - 1, -1):
		tem = w[i]
		ans += arr[l] + arr[r]
		r = r - tem + 1
		l += 1
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted([*map(int, input().split())], reverse=True)
	m = sorted([*map(int, input().split())])
	s = m.count(1)
	ans = sum(a[:k]) + sum(a[:s])
	for i in m[s:]:
		k += i - 1
		ans += a[k - 1]
	print(ans)


import sys
import math
import operator as op
from functools import reduce
from bisect import *
from collections import OrderedDict
from collections import deque

def read_line():
	return sys.stdin.readline()[:-1]

def read_int():
	return int(sys.stdin.readline())

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]

def read_float_line():
	return [float(v) for v in sys.stdin.readline().split()]

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer / denom

def index(a, x):
	i = bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	return -1

def find_lt(a, x):
	i = bisect_left(a, x)
	if i:
		return i - 1
	return -1

def find_le(a, x):
	i = bisect_right(a, x)
	if i:
		return i - 1
	return -1

def find_gt(a, x):
	i = bisect_right(a, x)
	if i != len(a):
		return i
	return -1

def find_ge(a, x):
	i = bisect_left(a, x)
	if i != len(a):
		return i
	return -1
mod = int(1000000000.0) + 7
mod2 = 998244353
t = read_int()
for i in range(t):
	(n, k) = read_int_line()
	a = read_int_line()
	c = read_int_line()
	w = [[] for i in range(k)]
	a.sort(reverse=True)
	c.sort()
	temp = -1 * 10000000000.0
	w = [[temp for i in range(k)] for j in range(max(c))]
	i = 0
	j = 0
	p = 0
	m = max(c)
	while p < n and j < k:
		w[0][j] = a[p]
		p += 1
		j += 1
	for j in range(k):
		i = 1
		while p < n and i < c[j]:
			w[i][j] = a[p]
			i += 1
			p += 1
	ans = 0
	for i in range(k):
		ans += w[0][i]
		itr = 0
		while itr + 1 < m and w[itr + 1][i] != temp:
			itr += 1
		ans += w[itr][i]
	print(ans)


t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	a.sort(reverse=True)
	b.sort(reverse=True)
	x = []
	c = 0
	for i in range(k):
		if b[i] == 1:
			c += 1
		else:
			x += [b[i]]
	sm = sum(a[:c]) * 2
	a = a[c:]
	j = 0
	m = len(a) - 1
	for i in range(len(x)):
		res = x[i]
		sm += a[j] + a[m]
		j += 1
		m -= res - 1
	print(sm)


t = int(input())
for case in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	w.sort(reverse=True)
	i = 0
	i2 = n - 1
	wi = 0
	happiness = 0
	t = w.count(1)
	while i < t:
		happiness += 2 * a[i]
		i += 1
	while wi < k - t:
		happiness += a[i] + a[i2]
		i += 1
		i2 -= w[wi] - 1
		wi += 1
	print(happiness)


t = int(input())
for tc in range(t):
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	w = sorted(list(map(int, input().split())), reverse=True)
	sol = 0
	while len(w) and w[-1] == 1:
		sol += 2 * a[-1]
		k -= 1
		w.pop()
		a.pop()
	p = 0
	sol += sum(a[-k:])
	for i in range(k):
		sol += a[p]
		p += w[i] - 1
	print(sol)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	ones = w.count(1)
	a = sorted(a, reverse=True)
	w = sorted([x for x in w if x > 1], reverse=True)
	total = sum(a[:ones]) * 2
	a = a[ones:]
	total += sum(a[:len(w)])
	a = a[len(w):]
	a = sorted(a)
	i = 0
	for x in w:
		total += a[i]
		i += x - 1
	print(total)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = [int(s) for s in input().split()]
	w = [int(s) for s in input().split()]
	w.sort()
	a.sort(reverse=True)
	i = 0
	s = 0
	r = [0] * k
	for el in w:
		s += a[i]
		if el == 1:
			s += a[i]
		i += 1
	for el in w:
		if el != 1:
			s += a[i + (el - 2)]
		i += el - 1
	print(s)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	w.sort()
	a.sort(reverse=True)
	dp = [[0, 0] for _ in range(k)]
	ct = w.count(1)
	ans = sum(a[:ct]) * 2
	bc = k - ct
	ans += sum(a[ct:ct + bc])
	j = n - 1
	for i in range(k - 1, -1, -1):
		if w[i] != 1:
			ans += a[j]
			j -= w[i] - 1
		else:
			break
	print(ans)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	w = sorted(list(map(int, input().split())), reverse=True)
	L = 0
	R = n - 1
	S = 0
	for f in w:
		if f == 1:
			S += 2 * a[R]
			R -= 1
	for f in w:
		if f >= 2:
			S += a[L] + a[R]
			L += f - 1
			R -= 1
	print(S)


import sys
from collections import deque
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = [int(_) for _ in input().split()]
	w = [int(_) for _ in input().split()]
	a.sort(reverse=True)
	w.sort(reverse=True)
	que = deque(a)
	s = w.count(1)
	ans = 0
	for i in range(s):
		p = que.popleft()
		ans += p * 2
	for i in range(k):
		if w[i] == 1:
			continue
		ans += que.popleft()
		ans += que.pop()
		for j in range(w[i] - 2):
			que.pop()
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	w = [int(i) for i in input().split()]
	a.sort()
	ans = sum(a[-k:])
	if 1 in w:
		ans += sum(a[-w.count(1):])
	w.sort(reverse=True)
	now = 0
	for i in w:
		if i > 1:
			ans += a[now]
			now += i - 1
	print(ans)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	klist = list(map(int, input().split()))
	klist.sort()
	a.sort()
	a.reverse()
	ans = 0
	j = 0
	x = n
	for i in range(k):
		if klist[i] == 1:
			ans += a[j] * 2
			j += 1
		elif klist[i] == 2:
			ans += a[j]
			ans += a[j + 1]
			j += 2
		else:
			x = i
			break
	klist = klist[x:]
	klist.reverse()
	m = n - 1
	for y in range(len(klist)):
		ans += a[j]
		ans += a[m]
		j += 1
		m -= klist[y] - 1
	print(ans)


def main():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		a = list(map(int, input().split()))
		w = list(map(int, input().split()))
		a.sort(reverse=True)
		ans = sum(a[:k])
		W = []
		cnt = 0
		for i in range(k):
			if w[i] - 1:
				W.append(w[i] - 1)
			else:
				cnt += 1
		ans += sum(a[:cnt])
		a.sort()
		now = 0
		W.sort(reverse=True)
		for x in W:
			ans += a[now]
			now += x
		print(ans)
main()


def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
entries = inp()
for i in range(entries):
	l = inlt()
	l = inlt()
	f = inlt()
	l.sort()
	f.sort()
	one = 0
	for x in f:
		if x == 1:
			one += 1
		else:
			break
	res = []
	for i in range(len(f)):
		res.append([])
	cnt = len(l) - 1
	for j in range(len(f)):
		res[j].append(l[cnt])
		cnt -= 1
	for j in range(len(f)):
		for k in range(f[j] - 1):
			res[j].append(l[cnt])
			cnt -= 1
	ans = 0
	for p in res:
		ans += max(p)
		ans += min(p)
	print(ans)


import sys
import heapq
import random
import collections
import bisect

def solve(vals, weights):
	vals = sorted(vals)
	weights = sorted(weights)
	solos = weights.count(1)
	multi = len(weights) - weights.count(1)
	res = 0
	if solos > 0:
		res += 2 * sum(vals[-solos:])
		vals = vals[:-solos]
		weights = weights[solos:]
	assert not 1 in weights
	if multi > 0:
		res += sum(vals[-multi:])
		vals = vals[:-multi]
		idx = 0
		for w in weights[::-1]:
			res += vals[idx]
			idx += w - 1
	return res

def console(*args):
	print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)
	return
for case_num in range(int(input())):
	(_, _) = list(map(int, input().split()))
	val = list(map(int, input().split()))
	ws = list(map(int, input().split()))
	res = solve(val, ws)
	print(res)


test = int(input())
while test != 0:
	(n, k) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	w = [int(x) for x in input().split()]
	arr.sort()
	w.sort()
	s = 0
	for i in range(k):
		if w[i] == 1:
			s += 2 * arr.pop()
		else:
			s += arr.pop()
		w[i] -= 1
	for i in range(k):
		if w[i] == 0:
			continue
		while w[i] != 1:
			arr.pop()
			w[i] -= 1
		s += arr.pop()
	print(s)
	test -= 1


import math as mt
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(n, k) = I()
	l = sorted(I())[::-1]
	w = sorted(I())
	ans = 0
	for i in range(k):
		if w[i] == 1:
			ans += l[i] * 2
		else:
			ans += l[i]
	w = w[::-1]
	kk = 0
	i = n - 1
	while w[kk] != 1:
		te = w[kk] - 1
		cn = 0
		mi = mt.inf
		while i >= k - 1:
			mi = min(mi, l[i])
			i -= 1
			cn += 1
			if cn == te:
				break
		ans += mi
		kk += 1
		if k == kk:
			break
	print(ans)


import sys
import bisect as b
import math
from collections import defaultdict as dd
input = sys.stdin.readline
mo = 10 ** 9 + 7

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def pref(a, n, f):
	pre = [0] * n
	if f == 0:
		pre[0] = a[0]
		for i in range(1, n):
			pre[i] = a[i] + pre[i - 1]
	else:
		pre[-1] = a[-1]
		for i in range(n - 2, -1, -1):
			pre[i] = pre[i + 1] + a[i]
	return pre

def dfs(node, ans):
	vi[node] = 1
	ans += [node + 1]
	for j in adj[node]:
		if vi[j] == 0:
			dfs(j, ans)
	return ans
for i in range(inin()):
	(n, k) = cin()
	a = ain()
	a.sort()
	w = ain()
	w.sort()
	ans = 0
	ma = a[::-1][:k]
	for i in range(k):
		w[i] -= 1
		if w[i] == 0:
			ans += ma[i] * 2
		else:
			ans += ma[i]
	h = a[:n - k]
	h = h[::-1]
	pre = pref(w, k, 0)
	for i in range(k):
		if w[i] != 0:
			ans += h[pre[i] - 1]
	print(ans)


tt = int(input())
for loop in range(tt):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	w.sort()
	ans = 0
	ind = 0
	two = 0
	up = 0
	down = 0
	rem = 0
	for i in range(k):
		if w[i] == 1:
			two += 1
		else:
			up += 1
			down += 1
			rem += w[i] - 2
	while two > 0:
		ans += 2 * a[-1]
		del a[-1]
		two -= 1
	while up > 0:
		ans += a[-1]
		del a[-1]
		up -= 1
	for i in range(k):
		if w[i] == 1:
			continue
		for j in range(w[i] - 1):
			if j == w[i] - 2:
				ans += a[-1]
			del a[-1]
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	w_arr = [int(x) for x in input().split()]
	ans = 0
	temp = []
	w_arr = sorted(w_arr)
	arr = sorted(arr)[::-1]
	it = 0
	var = 0
	for i in w_arr:
		if i == 1:
			ans += 2 * arr[it]
			it += 1
			var += 1
		elif i == 2:
			ans += arr[it] + arr[it + 1]
			it += 2
			var += 1
		else:
			break
	else:
		print(ans)
		continue
	w_arr = w_arr[var:]
	x = len(w_arr)
	arr = arr[it:]
	for i in range(x):
		ans += arr[i]
	arr = arr[x:]
	count = 0
	for i in w_arr:
		count += i - 1
		ans += arr[count - 1]
	print(ans)


t = int(input())
while t != 0:
	t = t - 1
	(n, k) = [int(x) for x in input().split()]
	arr = list(map(int, input().strip().split()))[:n]
	w = list(map(int, input().strip().split()))[:k]
	arr.sort(reverse=True)
	w.sort()
	ans = 0
	j = k - 1
	for i in range(0, k):
		if w[i] == 1:
			ans = ans + 2 * arr[i]
		else:
			ans = ans + arr[i]
	for i in range(0, k):
		if w[i] > 1:
			j = j + (w[i] - 1)
			ans = ans + arr[j]
	print(ans)


t = int(input())
while t:
	t = t - 1
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort(reverse=True)
	b.sort()
	out = 0
	j = 0
	for i in range(k):
		out += a[i]
		if b[i] == 1:
			out += a[i]
	a = a[k:]
	j = 0
	for i in range(k):
		if b[i] == 1:
			continue
		else:
			out += a[j + b[i] - 1 - 1]
			j += b[i] - 1
	print(out)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
sys.setrecursionlimit(int(pow(10, 6)))
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
term = l()[0]
for _ in range(term):
	(n, k) = l()
	A = l()
	w = l()
	d = [[w[i], []] for i in range(k)]
	d.sort()
	A.sort(reverse=True)
	for i in range(k):
		d[i][1].append(A[i])
	j = 0
	i = k
	while i < n and j < k:
		while i < n and j < k and (len(d[j][1]) < d[j][0]):
			d[j][1].append(A[i])
			i += 1
		j += 1
	ans = 0
	for i in range(k):
		ans += min(d[i][1]) + max(d[i][1])
	print(ans)


from collections import *
from bisect import *
from math import *
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = [*map(int, input().split())]
	w = [*map(int, input().split())]
	l.sort()
	w.sort()
	i = 0
	j = n - 1
	ans = 0
	for x in range(k):
		if w[x] == 1:
			ans += 2 * l[j]
			j -= 1
		else:
			ans += l[j]
			j -= 1
	for x in range(k):
		if w[x] != 1:
			for r in range(1, w[x] - 1, 1):
				j -= 1
			ans += l[j]
			j -= 1
	print(ans)


import sys
t = int(input())
for _t in range(t):
	(n, k) = map(int, sys.stdin.readline().split())
	a_arr = list(map(int, sys.stdin.readline().split()))
	w_arr = map(int, sys.stdin.readline().split())
	a_arr.sort()
	clear_w = []
	single = 0
	for w in w_arr:
		if w == 1:
			single += 1
		else:
			clear_w.append(w)
	clear_w.sort(reverse=True)
	l = 0
	r = n - 1
	out = 0
	for i in range(n - 1, n - 1 - single, -1):
		r -= 1
		out += a_arr[i] * 2
	for w in clear_w:
		out += a_arr[r]
		r -= 1
		out += a_arr[l]
		l += w - 1
	print(out)


tc = int(input())
for i in range(tc):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	w.sort(reverse=True)
	x = w.count(1)
	y = n - 1
	s = 2 * sum(a[:x])
	for i in range(k - x):
		s += a[x] + a[y]
		x += 1
		y = y - w[i] + 1
	print(s)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def fi():
	return float(input())

def si():
	return input()

def msi():
	return map(str, input().split())

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
mod = 1000000007
from math import log, sqrt, factorial, cos, tan, sin, radians, ceil, floor
import bisect
from decimal import *
abc = 'abcdefghijklmnopqrstuvwxyz'
pi = 3.141592653589793

def main():
	for _ in range(ii()):
		(n, k) = mi()
		a = li()
		w = li()
		a.sort(reverse=True)
		w.sort(reverse=True)
		g = w.count(1)
		c = g
		d = n - 1
		mx = []
		mn = []
		for i in range(k):
			if w[i] == 1:
				break
			mx.append(a[c])
			c += 1
			mn.append(a[d])
			d -= w[i] - 1
		for i in range(g):
			mx.append(a[i])
			mn.append(a[i])
		ans = sum(mx) + sum(mn)
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def find_ans(n, k):
	nums = list(map(int, input().split()))
	nums.sort()
	friends = list(map(int, input().split()))
	friends.sort()
	l = 0
	i = 0
	j = n - 1
	ans = 0
	try:
		while friends[l] == 1:
			ans += nums[j] * 2
			j -= 1
			l += 1
	except IndexError:
		print(ans)
		return
	for o in range(k - 1, l - 1, -1):
		ans += nums[i] + nums[j]
		i += friends[o] - 1
		j -= 1
	print(ans)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	find_ans(n, k)


t = int(input())
for i in range(t):
	nk = list(map(int, input().split()))
	n = nk[0]
	k = nk[1]
	nums = list(map(int, input().split()))
	friends = list(map(int, input().split()))
	nums.sort()
	friends.sort(reverse=True)
	res = 0
	po = 0
	po2 = n - k
	for i in friends:
		res += nums[po2]
		if i == 1:
			res += nums[po2]
		else:
			res += nums[po]
		po += i - 1
		po2 += 1
	print(res)


tc = int(input())
for t in range(tc):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	w.sort()
	(_sum, l, r, ii, flag) = (0, 0, n - 1, 0, 0)
	for num in w:
		if num == 1:
			_sum += a[ii] * 2
			ii += 1
		else:
			break
	w.reverse()
	for num in w:
		if num == 1:
			break
		else:
			_sum += a[ii] + a[r]
			r = r - num + 1
			ii += 1
	print(_sum)


for i in range(int(input())):
	(n, k) = [int(k) for k in input().split()]
	arr = [int(k) for k in input().split()]
	arr.sort(reverse=True)
	warr = [int(k) for k in input().split()]
	warr.sort()
	ans = 0
	one = warr.count(1)
	for ii in range(k):
		ans += arr[ii]
	for iii in range(one):
		ans += arr[iii]
	index = k - 1
	for ele in warr[one:]:
		index += ele - 1
		ans += arr[index]
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = [int(item) for item in input().split()]
	w = [int(item) for item in input().split()]
	ones = w.count(1)
	ans = 0
	a.sort()
	for _ in range(ones):
		ans += a.pop() * 2
	for item in w:
		if item == 1:
			continue
		else:
			ans += a.pop()
	w.sort()
	for item in w:
		item -= 1
		minima = 0
		for i in range(item):
			minima = a.pop()
		ans += minima
	print(ans)


from sys import stdin
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	(n, k) = [int(x) for x in inp().split()]
	a = [int(x) for x in inp().split()]
	w = [int(x) for x in inp().split()]
	a.sort()
	w.sort()
	ans = 0
	h = n - 1
	l = 0
	start = k
	minimum = float('inf')
	maximum = float('-inf')
	for i in range(k):
		if w[i] != 1:
			start = i
			break
		ans += a[h] * 2
		h -= 1
	for i in range(k - 1, start - 1, -1):
		for j in range(w[i]):
			x = a[l]
			if j == 0:
				x = a[h]
				h -= 1
			else:
				l += 1
			minimum = min(minimum, x)
			maximum = max(maximum, x)
		ans += minimum + maximum
		minimum = float('inf')
		maximum = float('-inf')
	print(ans)


from collections import OrderedDict
from heapq import heapify, heappush, heappop
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	Ans = 0
	p = k
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	b.sort(reverse=True)
	a.sort()
	s1 = 0
	ind = 0
	for i in range(k):
		if b[i] > 1:
			s1 += a[ind]
			ind += b[i] - 1
	p = 0
	for i in range(ind, n):
		s1 = s1 + a[i]
		if b[p] == 1:
			s1 += a[i]
		p += 1
	print(s1)


t = int(input())
for _i in range(t):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	w = [int(i) for i in input().split()]
	a.sort()
	w.sort()
	(e, res) = (n - k, sum(a[n - k:]))
	j = 0
	for i in w:
		if i == 1:
			j += 1
			res += a[-j]
			continue
		e -= i - 1
		res += a[e]
	print(res)


import os
import sys
debug = True
if debug and os.path.exists('input.in'):
	input = open('input.in', 'r').readline
else:
	debug = False
	input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
test_count = int(input())
for t in range(test_count):
	if debug:
		print('Test Case #', t + 1)
	(n, k) = invr()
	a = inlt()
	b = inlt()
	a.sort(reverse=True)
	b.sort()
	ans = sum(a[0:k])
	index = k - 1
	for i in range(k):
		if b[i] == 1:
			ans += a[i]
		else:
			index += b[i] - 1
			ans += a[index]
	print(ans)


def main():
	t = int(input())
	for _ in range(t):
		(n, k) = tuple(map(int, input().split()))
		a = list(map(int, input().split()))
		a.sort()
		w = list(map(int, input().split()))
		w.sort()
		s = 0
		used = 0
		high_pos = -1
		low_pos = 0
		stop_index = 0
		for (i, weight) in enumerate(w):
			if weight == 1:
				s += 2 * a[high_pos]
				high_pos -= 1
				continue
			elif weight == 2:
				s += a[high_pos] + a[high_pos - 1]
				high_pos -= 2
				continue
			break
		stop_index = i if weight != 1 and weight != 2 else i + 1
		for i in range(-1, -len(w) + stop_index - 1, -1):
			s += a[high_pos]
			high_pos -= 1
			s += a[low_pos]
			low_pos += w[i] - 1
		print(s)
main()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	v = list(map(int, input().split()))
	w = list(map(int, input().split()))
	ans = 0
	v.sort()
	w.sort()
	for i in range(n - k, n):
		ans += v[i]
	j = n - k
	for i in range(k):
		j -= w[i] - 1
		if w[i] == 1:
			ans += v[n - i - 1]
		else:
			ans += v[j]
	print(ans)


import sys
from collections import defaultdict as dd
from collections import deque
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from itertools import permutations

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def li():
	return [int(x) for x in input().split()]

def fi():
	return int(input())

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)

def bo(i):
	return ord(i) - ord('a')
t = fi()
while t > 0:
	t -= 1
	(n, k) = mi()
	a = li()
	w = li()
	a.sort(reverse=True)
	p = c = 0
	d = []
	for i in w:
		if i > 2:
			d.append(i)
	d.sort(reverse=True)
	q = n - 1
	w.sort()
	for i in range(k):
		if w[i] == 1:
			c += 2 * a[p]
			p += 1
		elif w[i] == 2:
			c += a[p] + a[p + 1]
			p += 2
	for i in range(len(d)):
		c += a[p] + a[q]
		p += 1
		q -= d[i] - 1
	print(c)


def minDifferenceAmongMaxMin(arr, N, K):
	arr.sort()
	res = 2147483647
	for i in range(N - K + 1):
		curSeqDiff = arr[i + K - 1] - arr[i]
		res = min(res, curSeqDiff)
	return res
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	li = list(map(int, input().split()))
	sizes = list(map(int, input().split()))
	li.sort()
	sizes.sort(reverse=True)
	sumi = 0
	count = 0
	for i in sizes:
		if i == 1:
			count = count + 1
			sumi = sumi + 2 * li.pop()
	for i in sizes:
		if i == 1:
			continue
		else:
			sumi = sumi + li.pop()
			sumi = sumi + li.pop(0)
			for k in range(0, i - 2):
				li.pop(0)
	print(sumi)


t = int(input())
while t:
	t -= 1
	size = list(map(int, input().strip().split()))[:2]
	(n, m) = (size[0], size[1])
	v = list(map(int, input().strip().split()))[:n]
	w = list(map(int, input().strip().split()))[:m]
	v.sort()
	w.sort()
	ans = 0
	i = n - 1
	j = 0
	while j < m:
		ans += v[i - j]
		j += 1
	x = 0
	for i in w:
		if i == 1:
			x += 1
		else:
			break
	j = 0
	i = n - 1
	while j < x:
		ans += v[i - j]
		j += 1
	y = n - m
	j = x
	while j < m:
		y -= w[x] - 1
		x += 1
		ans += v[y]
		j += 1
	print(ans)


from sys import stdin as cin
from itertools import takewhile, accumulate
lmap = lambda f, v: list(map(f, v))

def max_joy(a, w):
	a.sort()
	w.sort()
	ones_n = len(list(takewhile(lambda x: x == 1, w)))
	if ones_n:
		ones_sum = sum(a[-ones_n:])
		w = w[ones_n:]
		a = a[:-ones_n]
	else:
		ones_sum = 0
	if a:
		max_sum = sum(a[-len(w):])
		w = [x - 1 for x in reversed(w)]
		min_idx = [0] + list(accumulate(w[:-1]))
		min_sum = sum((a[i] for i in min_idx))
	else:
		max_sum = 0
		min_sum = 0
	return ones_sum * 2 + max_sum + min_sum

def main():
	t = int(next(cin).strip())
	for i in range(t):
		next(cin)
		a = lmap(int, next(cin).strip().split())
		w = lmap(int, next(cin).strip().split())
		print(max_joy(a, w))
main()


for x in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	w.sort()
	a.sort(reverse=True)
	p = 0
	j = k - 1
	for i in range(k):
		if w[i] == 1:
			p += 2 * a[i]
		else:
			p += a[i] + a[j + w[i] - 1]
			j += w[i] - 1
	print(p)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	w.sort()
	j = 0
	sum = 0
	l = 0
	v = k
	r = n - 1
	for i in range(len(w)):
		if w[i] > 1:
			v = i
			break
		sum += a[l] * 2
		l += 1
	for i in range(k - 1, v - 1, -1):
		b = w[i]
		sum += a[l] + a[r]
		r = r - b + 1
		l += 1
	print(sum)


from sys import stdin, stdout
LI = lambda : list(map(int, input().split()))
MAP = lambda : map(int, input().split())
IN = lambda : int(input())
S = lambda : input()
import math

def p(a):
	print(' '.join(list(map(str, a))))
from collections import Counter

def solve():
	(n, k) = MAP()
	a = LI()
	w = LI()
	a.sort()
	w.sort()
	ind = -1
	ans = 0
	i = 0
	for x in range(k):
		if w[x] == 1:
			ans += 2 * a[-1]
			a.pop()
			ind = x + 1
		else:
			ans += a[-1]
			a.pop()
	w.reverse()
	for x in range(k):
		if w[x] != 1:
			ans += a[i]
			i += w[x] - 1
	print(ans)
for i in range(IN()):
	solve()


def happiness(n, k, array, distribution):
	array.sort()
	distribution.sort(reverse=True)
	(a, b, c) = (0, 0, 0)
	h = sum(array)
	for m in distribution:
		if m == 1:
			a += 1
		elif m == 2:
			b += 1
		else:
			c += 1
	cur = 0
	for i in range(c):
		cur += 1
		for j in range(distribution[i] - 2):
			h -= array[cur]
			cur += 1
	return h + sum(array[n - a:n])
t = int(input())
for i in range(t):
	(n, k) = [int(s) for s in input().split()]
	array = [int(s) for s in input().split()]
	distribution = [int(s) for s in input().split()]
	print(happiness(n, k, array, distribution))


import sys
input = lambda : sys.stdin.readline().strip('\r\n')
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())), reverse=True)
	w = sorted(list(map(int, input().split())))
	ans = 0
	for i in range(k):
		if w[i] == 1:
			ans += 2 * a[i]
		else:
			ans += a[i]
		w[i] -= 1
	j = k - 1
	for i in range(k):
		if w[i] != 0:
			j += w[i]
			ans += a[j]
	print(ans)


t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	s = list(map(int, input().split()))
	f = list(map(int, input().split()))
	s.sort(reverse=True)
	f.sort()
	start = 0
	end = k - 1
	result = 0
	for j in f:
		if j == 1:
			result += s[start] * 2
		else:
			end += j - 1
			result += s[start] + s[end]
		start += 1
	print(result)


def main():
	for case in range(int(input().strip())):
		input()
		vs = [int(t) for t in input().strip().split()]
		ws = [int(t) for t in input().strip().split()]
		vs = sorted(vs)
		ws = sorted(ws)[::-1]
		result = 0
		sum_w = 0
		for w in ws:
			if w > 1:
				result += vs[sum_w]
			sum_w += w - 1
		for i in range(sum((1 for w in ws if w == 1))):
			result += vs[-i - 1]
		print(result + sum(vs[-len(ws):]))
main()


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l1 = list(map(int, input().split()))
	l.sort()
	l1.sort()
	a = l1.count(1)
	l1 = l1[a:]
	l1.sort(reverse=True)
	ans = 0
	for j in range(a):
		ans += 2 * l[-1]
		l.pop()
	for j in range(len(l1)):
		ans += l[-1]
		l.pop()
	p = 0
	for j in range(len(l1)):
		ans += l[p]
		p += l1[j] - 1
	print(ans)


t = int(input())
for _ in range(0, t):
	(n, k) = map(int, input().strip().split(' '))
	arr = list(map(int, input().strip().split(' ')))
	f = list(map(int, input().strip().split(' ')))
	arr.sort()
	f.sort(reverse=True)
	ans = 0
	j = n - 1
	for i in range(k - 1, -1, -1):
		if f[i] == 1:
			ans += 2 * arr[j]
			j -= 1
		else:
			break
	p = 0
	if f.count(1) != k:
		for m in range(0, i + 1):
			ans += arr[p] + arr[j]
			p += f[m] - 1
			j -= 1
	print(ans)


import sys
input = sys.stdin.buffer.readline

def prog():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		nums = list(map(int, input().split()))
		friends = list(map(int, input().split()))
		friends.sort(reverse=True)
		nums.sort()
		total = 0
		for i in range(len(friends) - 1, -1, -1):
			friends[i] -= 1
			if friends[i] == 0:
				total += 2 * nums.pop()
			else:
				total += nums.pop()
		while len(friends) > 0 and friends[-1] == 0:
			friends.pop()
		while friends:
			total += nums[-friends[-1]]
			for i in range(friends.pop()):
				nums.pop()
		sys.stdout.write(str(total) + '\n')
prog()


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	(n, k) = value()
	a = sorted(array(), reverse=True)
	at = a[:]
	w = sorted(array(), reverse=True)
	need = 0
	have = 0
	for i in w:
		if i > 1:
			need += 1
		else:
			have += 1
	ans = 2 * sum(a[:have])
	a = a[have:]
	start = 0
	end = len(a) - 1
	for i in range(need):
		ans += a[start] + a[end]
		start += 1
		end -= w[i] - 1
	print(ans)


import sys
input = sys.stdin.readline
(inp, ip) = (lambda : int(input()), lambda : [int(w) for w in input().split()])
for _ in range(inp()):
	(n, k) = ip()
	x = ip()
	y = ip()
	x.sort(reverse=True)
	y.sort(reverse=True)
	ct = y.count(1)
	sm = x[:ct]
	x = x[ct:]
	sm = 2 * sum(sm)
	d = k - ct
	sm += sum(x[:d])
	x = x[d:]
	y = [i - 1 for i in y]
	x = x[::-1]
	ind = 0
	for i in y:
		if i:
			sm += x[ind]
			ind += i
	print(sm)


t = int(input())
while t > 0:
	t -= 1
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	happiness = 0
	x = n - k
	for i in range(k):
		happiness += a[n - 1 - i]
		if b[i] == 1:
			happiness += a[n - 1 - i]
		else:
			for j in range(b[i] - 1):
				x -= 1
			happiness += a[x]
	print(happiness)


t = int(input())

def solve():
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	ws = list(map(int, input().split()))
	arr.sort(reverse=True)
	ws.sort(reverse=True)
	ones = ws.count(1)
	ans = 2 * sum(arr[:ones])
	(start, end) = (ones, n - 1)
	for i in range(k - ones):
		ans += arr[start] + arr[end]
		start += 1
		end -= ws[i] - 1
	return ans
for _ in range(t):
	print(solve())


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	w.sort()
	ans = 0
	for j in range(k):
		ans += a[j]
		if w[j] == 1:
			ans += a[j]
	ind = k
	for j in range(k):
		if w[j] - 1 <= 0:
			continue
		ind += w[j] - 1
		ans += a[ind - 1]
	print(ans)


import sys
RI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
from collections import defaultdict as df
from math import *
t = int(input().strip())
for _ in range(t):
	(n, k) = RI()
	l = RI()
	w = RI()
	ans = 0
	l.sort()
	l = l[::-1]
	for i in range(k):
		ans += l[i]
	w.sort()
	for j in range(k):
		if w[j] == 1:
			ans += l[j]
	i = k
	for j in w:
		if j == 1:
			continue
		ans += l[i + (j - 1) - 1]
		i = i + (j - 1)
	print(ans)


def solve(n, k, a, w):
	a.sort(reverse=True)
	w.sort()
	answ = 0
	left = 0
	right = n - 1
	for i in range(k):
		if w[i] == 1:
			answ += a[left] * 2
			left += 1
		else:
			break
	for i in range(k - 1, left - 1, -1):
		answ += a[left] + a[right]
		left += 1
		right -= w[i] - 1
	print(answ)
t = int(input())
while t:
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	solve(n, k, a, w)
	t -= 1


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	A = sorted(map(int, input().split()))
	W = sorted(map(int, input().split()), reverse=True)
	r = 0
	while W and W[-1] == 1:
		r += 2 * A.pop()
		W.pop()
	i = 0
	for w in W:
		r += A[i] + A.pop()
		i += w - 1
	print(r)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	ll = list(map(int, input().split()))
	l.sort()
	l.reverse()
	ll.sort()
	one_num = 0
	while one_num < n and ll[one_num] == 1:
		one_num += 1
	sol = 0
	sol += sum(l[:one_num]) * 2
	sol += sum(l[one_num:k])
	i = k - 1
	for x in ll[one_num:]:
		i += x - 1
		sol += l[i]
	print(sol)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	arr.sort()
	arr = arr[-1::-1]
	q = list(map(int, input().split()))
	q.sort()
	(ans, l, r) = (0, 0, 0)
	temp = []
	for i in q:
		if i - 1 == 0:
			ans += 2 * arr[r]
			r += 1
		else:
			ans += arr[r]
			l += 1
			temp.append(i - 1)
			r += 1
	temp.sort()
	temp = temp[-1::-1]
	lt = n - 1
	for i in temp:
		ans += arr[lt]
		lt -= i
	print(ans)


import sys
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(buff_readline())

def read_int_n():
	return list(map(int, buff_readline().split()))

def read_float():
	return float(buff_readline())

def read_float_n():
	return list(map(float, buff_readline().split()))

def read_str():
	return readline().strip()

def read_str_n():
	return readline().strip().split()

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

def slv(N, K, A, W):
	from collections import deque
	W.sort(reverse=True)
	A.sort()
	A = deque(A)
	ans = 0
	while W and W[-1] == 1:
		W.pop()
		b = A.pop()
		ans += 2 * b
	for w in W:
		b = A.pop()
		c = A.popleft()
		for _ in range(w - 2):
			A.popleft()
		ans += b + c
	return ans

def main():
	T = read_int()
	for _ in range(T):
		(N, K) = read_int_n()
		A = read_int_n()
		W = read_int_n()
		print(slv(N, K, A, W))
main()


t = int(input())
for i in range(t):
	(n, k) = [int(x) for x in input().split(' ')]
	a = [int(x) for x in input().split(' ')]
	w = [int(x) for x in input().split(' ')]
	ans = 0
	j = 0
	allotment = []
	a = sorted(a, reverse=True)
	w = sorted(w)
	while j < k:
		allotment.append([a[j]])
		j += 1
	for (p, ww) in enumerate(w):
		if ww > 1:
			j += ww - 2
			allotment[p].append(a[j])
			j += 1
		if j == len(a):
			break
	for aa in range(len(allotment)):
		if len(allotment[aa]) == 1:
			allotment[aa].append(allotment[aa][0])
	ans = sum([sum(x) for x in allotment])
	print(ans)


a = int(input())
for i in range(a):
	(b, c) = map(int, input().split())
	l = list(map(int, input().split()))
	k = list(map(int, input().split()))
	l.sort(reverse=True)
	k.sort()
	s = 0
	d = c
	r = b - 1
	ll = 0
	for j in range(c):
		if k[j] > 1:
			d = j
			break
		s += l[ll] * 2
		ll += 1
	for j in range(c - 1, d - 1, -1):
		f = k[j]
		s += l[ll] + l[r]
		ll += 1
		r = r - f + 1
	print(s)


t = int(input())
ans = []
for i in range(t):
	(n, k) = map(int, input().split())
	arr = sorted(map(int, input().split()))
	w = sorted(map(int, input().split()), reverse=True)
	curr = 0
	ns = 0
	od = w.count(1)
	for i in range(k - od):
		ns += arr[curr]
		curr += w[i] - 1
	for i in range(k - od):
		ns += arr[n - i - 1 - od]
	for i in range(od):
		ns += 2 * arr[n - 1 - i]
	ans.append(ns)
for el in ans:
	print(el)


from sys import stdin, stdout

def INI():
	return int(stdin.readline())

def INL():
	return [int(_) for _ in stdin.readline().split()]

def INS():
	return stdin.readline()

def MOD():
	return pow(10, 9) + 7

def OPS(ans):
	stdout.write(str(ans) + '\n')

def OPL(ans):
	[stdout.write(str(_) + ' ') for _ in ans]
	stdout.write('\n')
for _ in range(INI()):
	ans = 0
	(n, k) = INL()
	A = sorted(INL(), reverse=True)
	W = sorted(INL())
	for _ in range(k):
		ans += A[_]
		if W[_] == 1:
			ans += A[_]
		W[_] -= 1
	i = k - 1
	for _ in range(k):
		if W[_] != 0:
			ans += A[i + W[_]]
			i += W[_]
	OPS(ans)


for _ in range(int(input())):
	(n, f) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	w.sort()
	ans = 0
	j = n - 1
	for i in range(f):
		if w[i] == 1:
			ans += a[j]
		ans += a[j]
		j -= 1
		w[i] -= 1
	for i in range(f):
		while w[i] > 0:
			if w[i] == 1:
				ans += a[j]
			j -= 1
			w[i] -= 1
	print(ans)


for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	goo = list(map(int, input().split()))
	goo.sort()
	fr = list(map(int, input().split()))
	fr.sort()
	num = [[] for i in range(k)]
	po = n - 1
	for i in range(k):
		num[i].append(goo[n - i - 1])
	i = 0
	j1 = n - k - 1
	while i < k:
		if len(num[i]) < fr[i]:
			num[i].append(goo[j1])
			j1 -= 1
		else:
			i += 1
	su = 0
	for i in num:
		su += i[0] + i[-1]
	print(su)


import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
tc = int(input())
for zzz in range(tc):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	v = list(map(int, input().split()))
	w = []
	for i in range(k):
		w.append((i, v[i]))
	arr.sort(key=lambda x: -x)
	w.sort(key=lambda x: x[1])
	cur = [0] * k
	maxi = [0] * k
	mini = [0] * k
	j = 0
	for i in range(k):
		maxi[w[i][0]] = arr[j]
		cur[i] += 1
		j += 1
	j -= 1
	for ele in w:
		pos = ele[0]
		needed = ele[1] - cur[pos]
		j += needed
		if needed == 0:
			mini[pos] = maxi[pos]
		else:
			mini[pos] = arr[j]
	sumi = 0
	for i in range(k):
		sumi += mini[i] + maxi[i]
	print(sumi)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = [int(i) for i in input().split()]
	w = [int(i) for i in input().split()]
	arr.sort()
	w.sort()
	hap = 0
	index = 0
	count = 0
	for i in range(k):
		if w[i] == 1:
			count += 1
			hap += arr[n - 1 - i] * 2
	for i in range(k - count):
		hap += arr[n - 1 - i - count]
		hap += arr[index]
		index += w[k - i - 1] - 1
	print(hap)


from sys import stdin
input = stdin.readline

def main():
	test = int(input())
	for _ in range(test):
		(n, k) = [int(i) for i in input().split(' ')]
		l = [int(i) for i in input().split(' ')]
		w = [int(i) for i in input().split(' ')]
		l.sort()
		w.sort(reverse=True)
		i = 0
		j = n - 1
		ans = 0
		for t in range(k):
			if w[t] == 1:
				ans += 2 * l[j]
				j -= 1
		for t in range(k):
			if w[t] > 1:
				ans += l[j] + l[i]
				j -= 1
				i += w[t] - 1
		print(ans)
main()


def solution(arr1, arr2):
	h = 0
	k = len(arr2)
	j = 0
	arr1.sort(reverse=True)
	arr2.sort()
	for i in range(len(arr1)):
		if i < k:
			h = h + arr1[i]
			if arr2[i] == 1:
				h = h + arr1[i]
			arr2[i] = arr2[i] - 1
		else:
			if arr2[j] == 0:
				while arr2[j] == 0:
					j = (j + 1) % k
			if arr2[j] == 1:
				h = h + arr1[i]
			arr2[j] = arr2[j] - 1
	return h
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr1 = [int(x) for x in input().split()]
	arr2 = [int(x) for x in input().split()]
	print(solution(arr1, arr2))


t = int(input())
for tc in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort(reverse=True)
	b.sort()
	(c, l, r) = (k, 0, n - 1)
	ans = 0
	for i in range(k):
		if b[i] > 1:
			c = i
			break
		ans = ans + a[l] * 2
		l = l + 1
	for j in range(k - 1, c - 1, -1):
		i = b[j]
		ans = ans + a[l] + a[r]
		r = r - i + 1
		l = l + 1
	print(ans)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	w.sort()
	a.sort()
	a = a[::-1]
	sum = 0
	y = 0
	flag = k - 1
	for z in range(k):
		if w[z] == 1:
			sum = sum + 2 * a[y]
			y = y + 1
		else:
			sum = sum + a[y]
			flag = flag + w[z] - 1
			sum = sum + a[flag]
			y = y + 1
	print(sum)


import os
import gc
import sys
from io import BytesIO, IOBase
from collections import Counter
from collections import deque
import heapq
import math
import statistics

def sin():
	return input()

def ain():
	return list(map(int, sin().split()))

def sain():
	return input().split()

def iin():
	return int(sin())
MAX = float('inf')
MIN = float('-inf')

def readTree(n, m):
	adj = [deque([]) for _ in range(n + 1)]
	for _ in range(m):
		(u, v) = ain()
		adj[u].append(v)
		adj[v].append(u)
	return adj

def solve():
	pass

def main():
	for _ in range(iin()):
		(n, k) = ain()
		a = ain()
		w = ain()
		a.sort(reverse=True)
		c = 0
		h = 0
		w.sort()
		idx = 0
		for i in range(k):
			w[i] -= 1
			h += a[idx]
			if w[i] == 0:
				h += a[idx]
			idx += 1
		for i in range(k):
			if w[i] > 0:
				idx += w[i]
				h += a[idx - 1]
		print(h)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ai = list(map(int, input().split()))
	wi = list(map(int, input().split()))
	ai.sort()
	wi.sort()
	answer = 0
	i = 0
	j = k - 1
	while j >= 0 and i < n - k:
		answer += ai[i]
		i += wi[j] - 1
		j -= 1
	x = 0
	for i in range(n - 1, n - k - 1, -1):
		m = 1
		if wi[x] == 1:
			m = 2
		answer += ai[i] * m
		x += 1
	print(answer)


t = int(input())
for i in range(t):
	[n, k] = list(map(int, input().split()))
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	w.sort()
	w0 = len(w)
	ret = sum(a[:w0]) + sum(a[:w.count(1)])
	for j in w:
		if j == 1:
			continue
		w0 += j - 1
		ret += a[w0 - 1]
	print(ret)


import os
import sys
from io import BytesIO, IOBase
profile = 0
pypy = 1

def iin():
	return int(input())

def lin():
	return list(map(int, input().split()))

def main():
	T = iin()
	while T:
		T -= 1
		(n, k) = lin()
		a = lin()
		a.sort()
		a1 = [[j - 1, i] for (i, j) in enumerate(lin())]
		a1.sort()
		ans = [[] for i in range(k)]
		for i in range(k):
			ans[a1[i][1]].append(a[-i - 1])
		a1 = a1[::-1]
		ch = 0
		for (i, j) in a1:
			for l in range(i):
				ans[j].append(a[ch])
				ch += 1
		sol = [max(ans[i]) + min(ans[i]) for i in range(k)]
		print(sum(sol))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if pypy:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')
if profile:
	import cProfile
	cProfile.run('main()')
else:
	main()


import sys
import math
from sys import stdin, stdout

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def main():
	for t in range(int(input())):
		(n, k) = get_ints()
		a = get_list()
		b = get_list()
		a.sort(reverse=True)
		b.sort()
		j = 0
		s = 0
		v = n - 1
		i = 0
		while i < k and b[i] == 1:
			s = s + a[i] + a[i]
			i += 1
		f = i
		j = i
		c = 0
		for j in range(i, k, 1):
			s = s + a[j]
			c += 1
		j = i + c
		for h in range(i, k, 1):
			s = s + a[j + b[h] - 1 - 1]
			j += b[h] - 1
		print(s)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


input_length = int(input())
while input_length != 0:
	nk_string = str(input())
	(n, k) = tuple(nk_string.split())
	(n, k) = (int(n), int(k))
	array_now_string = str(input())
	array_now = array_now_string.split()
	array_now = [int(x) for x in array_now]
	weight_string = str(input())
	weightlist = weight_string.split()
	weightlist = [int(x) for x in weightlist]
	input_length -= 1
	weightlist = sorted(weightlist)
	array_now = sorted(array_now, reverse=True)
	numones = 0
	for value in weightlist:
		if value == 1:
			numones += 1
	sum_happy = 0
	numfriend = 1
	for i in range(0, n):
		if i < k and numones > 0:
			sum_happy += 2 * array_now[i]
			numones -= 1
		elif i < k and numones == 0:
			sum_happy += array_now[i]
	del array_now[0:k]
	for value in weightlist:
		if value != 1:
			sum_happy += array_now[value - 2]
			del array_now[0:value - 1]
	print(sum_happy)


for q in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	j = 0
	w = list(map(int, input().split()))
	w.sort()
	ans = 0
	anz = [0] * k
	for i in range(k):
		ans += a[j]
		anz[i] = a[j]
		w[i] -= 1
		j += 1
	for i in range(k):
		while w[i] != 0:
			w[i] -= 1
			anz[i] = a[j]
			j += 1
		ans += anz[i]
	print(ans)


t = int(input())
from collections import Counter
for _ in range(t):
	(n, k) = map(int, input().split())
	arr2 = list(map(int, input().strip().split()))[:n]
	arr1 = list(map(int, input().strip().split()))[:k]
	arr1.sort(reverse=True)
	arr2.sort()
	ans = 0
	i = 0
	for num in arr1[::-1]:
		if num == 1:
			ans += arr2[-1] * 2
			arr2.pop()
		else:
			ans += arr2[-1]
			arr2.pop()
	for num in arr1:
		if num == 1:
			continue
		else:
			ans += arr2[i]
			i += num - 1
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	friends = list(map(int, input().split()))
	friends.sort()
	l.sort()
	start = n - k - 1
	end = n - 1
	ans = 0
	for i in friends:
		maxi = l[end]
		if i == 1:
			mini = l[end]
		else:
			remained = i - 1
			mini = l[start - remained + 1]
			start = start - remained
		end = end - 1
		ans += maxi + mini
	print(ans)


from math import *
z = int(input())
for q in range(z):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	w.sort()
	sum = 0
	for i in range(k):
		if w[i] == 1:
			sum += 2 * a[n - 1]
			a.pop(n - 1)
			n -= 1
		else:
			break
	w = w[::-1]
	h = 0
	for i in range(k):
		if w[i] == 1:
			break
		sum += a[n - 1] + a[h]
		a.pop(n - 1)
		n -= 1
		h += w[i] - 1
	print(sum)


for _ in range(int(input())):
	(n, k) = [int(__) for __ in input().split()]
	integers = [int(___) for ___ in input().split()]
	friends = [int(____) for ____ in input().split()]
	integers.sort(reverse=True)
	friends.sort()
	ans = 0
	shit = k - 1
	for i in range(k):
		if friends[i] == 1:
			ans += 2 * integers[i]
		else:
			shit += friends[i] - 1
			ans += integers[i] + integers[shit]
	print(ans)


import sys

def scanint():
	return int(sys.stdin.readline().rstrip())

def scanints():
	return map(int, sys.stdin.readline().rstrip().split())

def scanarr():
	return list(map(int, sys.stdin.readline().rstrip().split()))
from queue import PriorityQueue
import heapq
import math
t = scanint()
for _ in range(t):
	(n, k) = scanints()
	a = sorted(scanarr())
	w = sorted(scanarr(), reverse=True)
	happiness = sum(a[-k:])
	i = 0
	for idx in range(k):
		if w[idx] == 1:
			remain = k - idx
			happiness += sum(a[-remain:])
			break
		else:
			happiness += a[i]
			i += w[idx] - 1
	print(happiness)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	w.sort()
	s = 0
	j = n - 1
	for i in range(k):
		s += a[j]
		w[i] -= 1
		j -= 1
	z = n - 1
	j += 1
	for i in range(k):
		if w[i] == 0:
			s += a[z]
			z -= 1
		else:
			j -= w[i]
			s += a[j]
	print(s)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	w.sort(reverse=True)
	i = 0
	j = n - k
	s = 0
	for m in range(k):
		s += a[j]
		if w[m] > 1:
			s += a[i]
			i += w[m] - 1
		else:
			s += a[j]
		j += 1
	print(s)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	w = list(map(int, input().split()))
	next = []
	ans = []
	arr.sort()
	w.sort()
	l = 0
	r = n - 1
	j = 0
	for i in range(k):
		if w[i] == 1:
			ans.append([arr[r]])
			r -= 1
			j += 1
		else:
			break
	for i in range(k - 1, j - 1, -1):
		curr = []
		x = w[i]
		curr.append(arr[r])
		r -= 1
		x -= 1
		while x:
			curr.append(arr[l])
			l += 1
			x -= 1
		ans.append(curr)
	sum = 0
	for i in ans:
		sum += max(i)
		sum += min(i)
	print(sum)


t = int(input())
for _ in range(t):
	l1 = input().split(' ')
	n = int(l1[0])
	k = int(l1[1])
	l = input().split(' ')
	w = input().split(' ')
	for i in range(len(l)):
		l[i] = int(l[i])
	for i in range(len(w)):
		w[i] = int(w[i])
	l.sort()
	w.sort(reverse=True)
	p = 0
	j = len(l) - 1
	for i in range(k - 1, -1, -1):
		if w[i] == 1:
			p += 2 * l[j]
			j -= 1
		else:
			p += l[j]
			j -= 1
	j = 0
	for i in range(k):
		if w[i] - 1 > 0:
			p += l[j]
			j += w[i] - 1
		else:
			break
	print(p)


from sys import stdin, setrecursionlimit, stdout
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
from heapq import heapify, heappop, heappush, heappushpop, heapreplace

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline().rstrip()

def lsi():
	return list(si())
mod = 1000000007
res = ['Yes', 'No']
test_case = ii()
while test_case:
	test_case -= 1
	(n, m) = mi()
	a = li()
	a.sort(reverse=True)
	ans = [[a[i]] for i in range(m)]
	l = [1] * m
	b = li()
	b.sort()
	j = 0
	k = m - 1
	for i in b:
		if i < 2:
			j += 1
			continue
		k += i - 1
		ans[j].append(a[k])
		j += 1
	s = 0
	for i in ans:
		i.sort()
		s += i[0] + i[-1]
	print(s)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	w = list(map(int, input().split()))
	l.sort(reverse=True)
	w.sort()
	i = 0
	j = 0
	r = n - 1
	p = k
	ans = 0
	while i < k and w[i] == 1:
		ans += l[j] * 2
		j += 1
		i += 1
	p = i
	for i in range(k - 1, p - 1, -1):
		ans += l[j] + l[r]
		r = r - w[i] + 1
		j += 1
	print(ans)


for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	w = [int(i) for i in input().split()]
	a.sort(reverse=True)
	w.sort()
	cnt = w.count(1)
	w = [1] * cnt + w[::-1]
	for i in range(cnt):
		w.pop()
	front = 0
	ans = 0
	for i in w:
		if i == 1:
			ans += a[front]
		ans += a[front]
		if i - 1:
			ans += a[-1]
			for j in range(i - 1):
				a.pop()
		front += 1
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ints = list(map(int, input().split()))
	dist = list(map(int, input().split()))
	ints.sort(reverse=True)
	dist.sort()
	ans = sum(ints[:k])
	ind = k - 1
	start = 0
	while start < k and dist[start] == 1:
		ans += ints[start]
		start += 1
	for i in range(start, k):
		ind += dist[i] - 1
		ans += ints[ind]
	print(ans)


from sys import stdin
input = stdin.readline
from collections import deque

def f(a, frnd):
	a = sorted(a, reverse=True)
	frnd = sorted(frnd)
	frnd = deque(frnd)
	hi = len(a) - 1
	lo = 0
	ans = 0
	i = 0
	while frnd:
		tf = frnd.popleft()
		if tf == 1:
			tf -= 1
			mx = a[lo]
			ans += 2 * mx
			lo += 1
		else:
			frnd.appendleft(tf)
			frnd.reverse()
			for num in frnd:
				ans += a[hi] + a[lo]
				hi = hi - num + 1
				lo += 1
			break
	return ans
for _ in range(int(input())):
	(n, m) = map(int, input().strip().split())
	t = list(map(int, input().strip().split()))
	frnd = list(map(int, input().strip().split()))
	print(f(t, frnd))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	W = list(map(int, input().split()))
	A.sort(reverse=True)
	ans = 0
	W.sort()
	(j, l, r) = (k, 0, n - 1)
	for i in range(n):
		if W[i] > 1:
			j = i
			break
		ans += 2 * A[i]
		l += 1
	for u in range(k - 1, j - 1, -1):
		i = W[u]
		ans = ans + A[l] + A[r]
		r = r - i + 1
		l = l + 1
	print(ans)


t = int(input())
for j in range(0, t):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	w = [int(x) for x in input().split()]
	a = sorted(a)
	if k == 1:
		print(a[0] + a[n - 1])
	elif k == n:
		print(2 * sum(a))
	elif 1 not in w:
		w = sorted(w)
		w = list(reversed(w))
		q = [0] * k
		q[0] = 0
		for i in range(1, k):
			q[i] = q[i - 1] + w[i - 1] - 1
		s = 0
		for i in range(0, k):
			s += a[q[i]] + a[n - 1 - i]
		print(s)
	else:
		x = w.count(1)
		s = 0
		for i in range(0, x):
			s += 2 * a[n - i - 1]
		w = sorted(w)
		w = list(reversed(w))
		if k - x >= 2:
			q = [0] * (k - x)
			q[0] = 0
			for i in range(1, k - x):
				q[i] = q[i - 1] + w[i - 1] - 1
			for i in range(0, k - x):
				s += a[q[i]] + a[n - x - 1 - i]
			print(s)
		else:
			s += a[0] + a[n - x - 1]
			print(s)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	ar = list(map(int, input().split()))
	frnd = list(map(int, input().split()))
	ar.sort()
	frnd.sort()
	ans = 0
	for i in range(len(frnd)):
		if frnd[i] == 1:
			ans += 2 * ar[-1]
			ar.pop()
		else:
			ans += ar[-1]
			ar.pop()
	c = len(ar) - 1
	for i in range(len(frnd)):
		if frnd[i] != 1:
			ans += ar[c - frnd[i] + 2]
			c = c - frnd[i] + 1
	print(ans)


from collections import defaultdict, deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, itertools, math
sys.setrecursionlimit(10 ** 5)
input = sys.stdin.readline
sqrt = math.sqrt

def LI():
	return list(map(int, input().split()))

def LF():
	return list(map(float, input().split()))

def LI_():
	return list(map(lambda x: int(x) - 1, input().split()))

def II():
	return int(input())

def IF():
	return float(input())

def S():
	return input().rstrip()

def LS():
	return S().split()

def IR(n):
	res = [None] * n
	for i in range(n):
		res[i] = II()
	return res

def LIR(n):
	res = [None] * n
	for i in range(n):
		res[i] = LI()
	return res

def FR(n):
	res = [None] * n
	for i in range(n):
		res[i] = IF()
	return res

def LIR(n):
	res = [None] * n
	for i in range(n):
		res[i] = IF()
	return res

def LIR_(n):
	res = [None] * n
	for i in range(n):
		res[i] = LI_()
	return res

def SR(n):
	res = [None] * n
	for i in range(n):
		res[i] = S()
	return res

def LSR(n):
	res = [None] * n
	for i in range(n):
		res[i] = LS()
	return res
mod = 1000000007
inf = float('INF')

def solve():
	for i in range(II()):
		(n, k) = LI()
		a = LI()
		a.sort()
		ans = sum(a[-k:])
		w = LI()
		w.sort()
		i = 0
		x = 0
		for wi in w[::-1]:
			if wi - 1:
				ans += a[i]
			else:
				x += 1
			i += wi - 1
		if x:
			print(ans + sum(a[-x:]))
		else:
			print(ans)
	return
solve()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	invalid = sum([(i - 1) // 2 for i in w])
	s = 0
	r = n - 1
	for i in w:
		if i == 1:
			s += a[r] * 2
			r -= 1
	w.sort(reverse=True)
	l = 0
	for i in w:
		if i != 1:
			s += a[r]
			s += a[l]
			l += i - 1
			r -= 1
	print(s)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	(*a,) = map(int, input().split())
	(*w,) = map(int, input().split())
	a.sort()
	w.sort()
	i = n - 1
	i1 = 0
	j = res = 0
	while i >= 0 and j < k and (w[j] == 1):
		res += a[i] << 1
		i -= 1
		j += 1
	w = sorted(w[j:], reverse=True)
	for wi in w:
		res += a[i1] + a[i]
		i -= 1
		i1 += wi - 1
	print(res)


t = int(input())
import math
for i in range(t):
	(n, k) = map(int, input().strip().split())
	a = list(map(int, input().strip().split()))
	w = list(map(int, input().strip().split()))
	a.sort(reverse=True)
	w.sort()
	l = 0
	r = n - 1
	sumi = 0
	indi = k
	for i in range(k):
		if w[i] != 1:
			indi = i
			break
		sumi += a[l] * 2
		l += 1
	for j in range(k - 1, indi - 1, -1):
		i = w[j]
		sumi += a[l] + a[r]
		r = r - i + 1
		l += 1
	print(sumi)


from sys import stdin, stdout

class SOLVE:

	def solve(self):
		R = stdin.readline
		W = stdout.write
		ans = []
		for i in range(int(input())):
			(n, k) = [int(x) for x in R().split()]
			a = [int(x) for x in R().split()]
			w = [int(x) for x in R().split()]
			a.sort(reverse=True)
			w.sort()
			total = sum(a[:len(w)])
			total += sum(a[:w.count(1)])
			pos = len(w) - 1
			for j in range(len(w)):
				if w[j] > 1:
					pos += w[j] - 1
					total += a[pos]
			ans.append(str(total))
		W('\n'.join(ans))

def main():
	s = SOLVE()
	s.solve()
main()


import os
import sys
from io import BytesIO, IOBase
import threading
from math import floor
from bisect import bisect_right
from collections import Counter
from math import gcd
mod = 998244353

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		arr = list(map(int, input().split()))
		ark = list(map(int, input().split()))
		arr.sort()
		ark.sort()
		s = arr.copy()
		t = sum(arr[n - k:])
		arr = arr[:n - k]
		for i in range(k):
			ark[i] -= 1
		loc = 0
		pos = n - 1
		for i in ark:
			if i == 0:
				t += s[pos]
				pos -= 1
			else:
				loc += i
				t += arr[-loc]
		print(t)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from fractions import Fraction
tests = int(input())
for i in range(tests):
	numbers = input().split()
	n = int(numbers[0])
	k = int(numbers[1])
	a = [int(x) for x in input().split(' ')]
	w = [int(x) for x in input().split(' ')]
	a.sort()
	one_count = 0
	w2 = []
	for x in range(k):
		if w[x] == 1:
			one_count += 1
		else:
			w2.append(w[x])
	w2.sort(reverse=True)
	first = 0
	last = n - 1
	result = 0
	for x in range(one_count):
		result += a[last] * 2
		last = last - 1
	for x in range(len(w2)):
		result += a[last] + a[first]
		last = last - 1
		first += w2[x] - 1
	print(result)


from sys import stdin, stdout
from math import gcd, ceil, sqrt
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
tc = ii1()
for _ in range(tc):
	(n, k) = iia()
	arr = sorted(iia())
	arr1 = sorted(iia(), reverse=True)
	res = 0
	while len(arr1) and arr1[-1] == 1:
		res += 2 * arr.pop()
		arr1.pop()
	j = 0
	k = -1
	for i in arr1:
		big = arr[k]
		small = arr[j]
		j += i - 1
		k -= 1
		res += big + small
	print(res)


def testcase():
	import sys
	import heapq
	input = sys.stdin.readline
	(n, k) = [int(x) for x in input().strip().split()]
	A = sorted([int(x) for x in input().strip().split()])
	W = sorted([int(x) for x in input().strip().split()], reverse=True)
	ans = 0
	ones = W.count(1)
	if ones:
		ans += sum(A[-ones:]) * 2
		A = A[:-ones]
	(l, r) = (0, len(A) - 1)
	for w in W:
		if w == 1:
			break
		ans += A[l] + A[r]
		l += w - 1
		r -= 1
	print(ans)

def main():
	import sys
	input = sys.stdin.readline
	t = int(input())
	for _ in range(t):
		testcase()
main()


for i in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	w = [int(i) for i in input().split()]
	w.sort(reverse=True)
	arr.sort(reverse=True)
	dist = []
	for i in range(k):
		w[i] -= 1
		dist.append([arr[i], arr[i]])
	arr = arr[k:n][::-1]
	dist = dist[::-1]
	ptr = 0
	for i in range(k):
		if ptr >= len(arr):
			break
		if w[i]:
			dist[i][1] = arr[ptr]
			ptr += w[i]
	sm = 0
	for i in dist:
		sm += i[0] + i[1]
	print(sm)


def solve(n, k, a, w):
	ans = 0
	i = 0
	j = n - 1
	count = 0
	while i < k:
		if w[i] == 1:
			count += 1
			ans += 2 * a[i]
		else:
			ans += a[i]
		i += 1
	a = a[i:]
	if count < k:
		i = count
		j = w[i] - 2
		pos = 0
		while i < k:
			ans += a[j]
			i += 1
			if i < k:
				j += w[i] - 1
	return ans
t = int(input())
for we in range(t):
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())))[::-1]
	w = sorted(list(map(int, input().split())))
	print(solve(n, k, a, w))


for _ in range(int(input())):
	(n, k) = [int(a) for a in input().split()]
	k -= 1
	arr = [int(a) for a in input().split()]
	lis = [int(a) for a in input().split()]
	arr.sort()
	lis.sort()
	i = 0
	j = n - 1
	s = 0
	h = 0
	while i <= j:
		ss = lis[s]
		if ss == 1:
			h += arr[j] * 2
			s += 1
			j -= 1
		else:
			break
	while i <= j:
		ss = lis[k]
		h += arr[i] + arr[j]
		j -= 1
		i += ss - 1
		k -= 1
	print(h)


t = int(input())
for test in range(t):
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	w = [int(x) for x in input().split()]
	a.sort(reverse=True)
	w.sort()
	j = 0
	ans = 0
	for i in range(k):
		if w[i] == 1:
			ans += a[j]
		ans += a[j]
		j += 1
	for i in range(k):
		if w[i] != 1:
			j += w[i] - 2
			ans += a[j]
			j += 1
	print(ans)


t = int(input())
resposta = []
for k in range(t):
	(n, m) = map(str, input().split())
	n = int(n)
	m = int(m)
	a = input().split()
	vec_a = []
	vec_a2 = []
	for i in range(n):
		vec_a.append(int(a[i]))
		vec_a2.append(int(a[i]))
	vec_a = sorted(vec_a)
	vec_a2 = sorted(vec_a2)
	w = input().split()
	vec_w = []
	vec_w2 = []
	for i in range(m):
		vec_w.append(int(w[i]))
		vec_w2.append(int(w[i]))
	vec_w = sorted(vec_w)
	vec_w2 = sorted(vec_w2)
	for i in range(m):
		vec_w2[i] = vec_w[m - 1 - i]
	for i in range(n):
		vec_a[i] = vec_a2[n - 1 - i]
	punt = 0
	n1 = vec_w.count(1)
	nelse = m - n1
	for i in range(n1):
		punt += 2 * vec_a[i]
	for i in range(n1, n1 + nelse):
		punt += vec_a[i]
	compt = 0
	for i in range(m):
		if vec_w2[i] > 1:
			punt += vec_a2[compt]
			compt += vec_w2[i] - 1
	resposta.append(punt)
for i in range(t):
	print(resposta[i])


from os import path
import sys
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')

def solve():
	for _ in range(ii()):
		(n, k) = mi()
		a = li()
		w = li()
		a.sort(reverse=True)
		w.sort()
		ans = 0
		for i in range(k):
			ans += a[i]
			if w[i] == 1:
				ans += a[i]
			w[i] -= 1
		i = k
		c = 0
		while i < n and c < k:
			f = 1e+18
			for j in range(w[c]):
				f = a[i]
				i += 1
			if f != 1e+18:
				ans += f
			c += 1
		print(ans)
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = sys.stdin.readline
solve()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort(reverse=True)
	b.sort()
	i = 0
	c = [[] for j in range(k)]
	for j in range(k):
		c[j].append(a[i])
		b[j] -= 1
		i += 1
	for j in range(k):
		for l in range(b[j]):
			c[j].append(a[i])
			i += 1
	ans = 0
	for elem in c:
		ans += max(elem) + min(elem)
	print(ans)


nb_cases = int(input())
answer = []
while nb_cases > 0:
	nb_cases -= 1
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	w = [int(x) for x in input().split()]
	w.sort()
	a.sort(reverse=True)
	ami = 0
	happiness = 0
	nb_w_un = w.count(1)
	for x in range(nb_w_un):
		happiness += 2 * a[x]
	w = w[nb_w_un:]
	a = a[nb_w_un:]
	a.sort()
	w.sort(reverse=True)
	p_debut = 0
	p_fin = n - nb_w_un - 1
	while p_debut <= p_fin:
		if w[ami] == 1:
			min_val = a[p_fin]
			max_val = a[p_fin]
			p_fin -= 1
		else:
			min_val = a[p_debut]
			max_val = a[p_fin]
			p_debut += w[ami] - 1
			p_fin -= 1
		ami += 1
		happiness += min_val + max_val
	answer.append(happiness)
for x in answer:
	print(x)


import math as mt
import sys, string
input = sys.stdin.readline
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
from collections import defaultdict
t = I()
for _ in range(t):
	(n, k) = M()
	l = L()
	w = L()
	w.sort()
	l.sort(reverse=True)
	d = defaultdict(int)
	for i in l:
		d[i] += 1
	y = list(d.keys())
	y.sort()
	wmax = [-10 ** 10] * k
	wmin = [10 ** 10] * k
	ans = 0
	for i in range(k):
		w[i] -= 1
		d[l[i]] -= 1
		wmax[i] = max(l[i], wmax[i])
		wmin[i] = min(l[i], wmin[i])
	ind = 0
	i = k - 1
	while i >= 0 and ind < len(y):
		if w[i] < d[y[ind]]:
			wmax[i] = max(y[ind], wmax[i])
			wmin[i] = min(y[ind], wmin[i])
			d[y[ind]] -= w[i]
			if d[y[ind]] == 0:
				ind += 1
			w[i] = 0
			i -= 1
		else:
			if d[y[ind]] != 0:
				wmax[i] = max(y[ind], wmax[i])
				wmin[i] = min(y[ind], wmin[i])
				w[i] -= d[y[ind]]
				if w[i] == 0:
					i -= 1
				d[y[ind]] = 0
			ind += 1
	for i in range(k):
		ans += wmax[i] + wmin[i]
	print(ans)


T = int(input())
for t in range(T):
	(n, k) = [int(i) for i in input().split()]
	A = sorted([int(i) for i in input().split()])
	w = sorted([int(i) for i in input().split()], reverse=True)
	cum_w = [0]
	one_count = 0
	for i in range(k):
		if w[i] == 1:
			one_count += 1
		else:
			cum_w.append(cum_w[-1] + w[i] - 1)
	ans = sum(A[n - k:]) + sum(A[n - one_count:])
	for i in range(len(cum_w) - 1):
		ans += A[cum_w[i]]
	print(ans)


t = int(input())
for testcase in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	w.sort()
	(m, l, r) = (k, 0, n - 1)
	ans = 0
	for i in range(k):
		if w[i] > 1:
			m = i
			break
		ans += a[l] * 2
		l += 1
	for p in range(k - 1, m - 1, -1):
		ans = ans + a[l] + a[r]
		l = l + 1
		r = r - w[p] + 1
	print(ans)


t = int(input())
for j in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort(reverse=True)
	b.sort()
	ans = 0
	for i in range(k):
		ans += a[i]
	c = 0
	for i in range(k):
		if b[i] == 1:
			ans += a[i]
			c += 1
	start = k
	k = k - c
	i = 0
	while i < k:
		ans += a[start + b[c] - 1 - 1]
		start += b[c] - 1
		c += 1
		i += 1
	print(ans)


t = int(input())
for i2 in range(t):
	z = input().split()
	n = int(z[0])
	k = int(z[1])
	a = input().split()
	w = input().split()
	for i in range(len(a)):
		a[i] = int(a[i])
	for i in range(len(w)):
		w[i] = int(w[i])
	a.sort()
	w.sort(reverse=True)
	t = 0
	j = n - 1
	for i in range(k - 1, -1, -1):
		t += a[j]
		w[i] -= 1
		if w[i] == 0:
			t += a[j]
		j -= 1
	g = 0
	for i in range(k):
		if w[i] <= 0:
			break
		t += a[g]
		g += w[i]
	print(t)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
import random
from queue import PriorityQueue
from collections import Counter as cc
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
import sys
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l1 = list(map(int, input().split()))
	l.sort(reverse=True)
	l1.sort()
	for i in range(k):
		l1[i] -= 1
	i = 0
	j = k
	x = 0
	ans = sum(l[:k])
	while x < k:
		cnt = 1
		z = l1[x]
		while z > cnt:
			j += 1
			cnt += 1
		if z == 0:
			ans += l[i]
			i += 1
		else:
			ans += l[j]
			i += 1
			j += 1
		x += 1
	print(ans)


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
cases = int(input())
for t in range(cases):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	b = []
	w = sorted(w)
	a = sorted(a)
	for i in range(k):
		v = a.pop()
		b.append(v + v)
		w[i] -= 1
	s = 0
	for i in range(k):
		wi = w[i]
		for j in range(w[i]):
			v = a.pop()
		if wi > 0:
			b[i] = b[i] // 2 + v
		s += b[i]
	print(s)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = sorted(list(map(int, input().split())))
	w = sorted(list(map(int, input().split())))
	(last, first, s) = (n - 1, n - k, 0)
	for i in w:
		if i == 1:
			s += l[last] * 2
			last -= 1
		else:
			first -= i - 1
			s += l[last] + l[first]
			last -= 1
	print(s)


t = int(input())
for T in range(t):
	[n, k] = list(map(int, input().split()))
	a = sorted(list(map(int, input().split())))
	w = sorted(list(map(int, input().split())))
	w.reverse()
	c = w.count(1)
	j = 0
	s = 0
	for i in range(-1, -k - 1, -1):
		s += a[i]
	for i in range(-1, -c - 1, -1):
		s += a[i]
	for i in range(k - c):
		s += a[j]
		j += w[i] - 1
	print(s)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	frienddemand = list(map(int, input().split()))
	l.sort(reverse=True)
	frienddemand.sort(reverse=True)
	ans = 0
	top = 0
	bottom = n - 1
	for i in range(k):
		if frienddemand[i] == 1:
			ans += 2 * l[top]
			top += 1
	for i in range(k):
		d = frienddemand[i]
		if d == 1:
			continue
		ans += l[top]
		d -= 1
		if d == 0:
			ans += l[top]
		else:
			ans += l[bottom]
		bottom -= d
		top += 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	nums = map(int, input().split())
	ws = map(int, input().split())
	nums = sorted(nums)
	ws = sorted(ws, reverse=True)
	happiness = 0
	min_index = 0
	max_index = -k
	for i in range(k):
		happiness += nums[max_index]
		max_index += 1
		if ws[i] == 1:
			happiness += nums[max_index - 1]
		else:
			happiness += nums[min_index]
			min_index += ws[i] - 1
	print(happiness)


import math
import datetime
import collections
import statistics
import itertools

def is_prime(num):
	for i in range(2, int(math.sqrt(num)) + 1):
		if num % i == 0:
			return False
	return True

def input_list():
	ll = list(map(int, input().split(' ')))
	return ll
tc = int(input())
for _ in range(tc):
	(num, fr) = map(int, input().split())
	nlist = sorted(input_list(), reverse=True)
	frlist = sorted(input_list())
	su = 0
	for i in range(fr):
		su += nlist[i]
		if frlist[i] == 1:
			su += nlist[i]
	cc = fr
	for i in range(fr):
		frlist[i] -= 1
		if frlist[i] > 0:
			su += nlist[cc + frlist[i] - 1]
			cc += frlist[i]
	print(su)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	w = [int(i) for i in input().split()]
	a.sort()
	w.sort()
	ans = 0
	index = 0
	count = 0
	for i in range(k):
		if w[i] == 1:
			count += 1
			ans += a[n - 1 - i] * 2
		else:
			break
	for i in range(k - count):
		ans += a[n - 1 - i - count]
		ans += a[index]
		index += w[k - i - 1] - 1
	print(ans)


from sys import stdin, stdout
import sys
from math import *
for __ in range(int(input())):
	(n, k) = map(int, input().split())
	ar = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ar.sort()
	one = []
	non = []
	for i in range(k):
		if b[i] == 1:
			one.append(1)
		else:
			non.append(b[i])
	non.sort(reverse=True)
	for i in range(len(non)):
		one.append(non[i])
	b = one
	y = n - 1
	x = 0
	ans = 0
	for i in range(k):
		if b[i] == 1:
			ans += ar[y] * 2
			y -= 1
		else:
			ans += ar[y] + ar[x]
			x += b[i] - 1
			y -= 1
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort(reverse=True)
	b.sort()
	c = [[-10 ** 9, 10 ** 9] for i in range(k)]
	i = 0
	while i < k:
		b[i] -= 1
		c[i][0] = max(c[i][0], a[i])
		c[i][1] = min(c[i][1], a[i])
		i += 1
	i = k
	j = 0
	while i < n:
		if b[j]:
			b[j] -= 1
			c[j][0] = max(c[j][0], a[i])
			c[j][1] = min(c[j][1], a[i])
			i += 1
		else:
			j += 1
	s = 0
	for x in c:
		s += sum(x)
	print(s)


from collections import deque
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	a.sort()
	a = deque(a)
	w = [int(x) for x in input().split()]
	w.sort()
	ones = w.count(1)
	w = deque(w)
	ans = 0
	for i in range(ones):
		tmp = a.pop()
		w.popleft()
		ans += 2 * tmp
	w.reverse()
	for i in range(len(w)):
		ans += a.popleft()
		ans += a.pop()
		j = 2
		while j < w[i]:
			j += 1
			a.popleft()
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l1.sort()
	l2.sort()
	i = 0
	ans = 0
	l3 = [0] * k
	while i < k:
		l2[i] -= 1
		y = l1.pop()
		ans += y
		l3[i] = y
		i += 1
	for (i, x) in enumerate(l2):
		for j in range(x - 1):
			l1.pop()
		if x > 0:
			ans += l1.pop()
		else:
			ans += l3[i]
	print(ans)


def cin():
	return map(int, input().split())
for t in range(int(input())):
	(n, k) = cin()
	a = list(cin())
	w = list(cin())
	a.sort()
	w.sort()
	ans = 0
	idx = k
	for i in range(k):
		if w[i] > 1:
			idx = i
			break
		ans += a.pop() * 2
	j = 0
	for i in range(k - 1, idx - 1, -1):
		ans += a.pop() + a[j]
		j += w[i] - 1
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted(map(int, input().split()))
	w = sorted(map(int, input().split()))
	happy = 0
	(start, end) = (0, -1)
	j = -1
	for i in range(k):
		if w[i] == 1:
			happy += 2 * a[end]
			end -= 1
		else:
			happy += a[start] + a[end]
			end -= 1
			start += w[j] - 1
			j -= 1
	print(happy)


for _ in range(0, int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	b = list(map(int, input().split()))
	arr.sort()
	arr.reverse()
	b.sort()
	j = 0
	result = 0
	for i in range(0, k):
		if b[i] == 1:
			result += arr[j] * 2
			j += 1
			b[i] -= 1
		else:
			result += arr[j]
			j += 1
			b[i] -= 1
	for i in range(0, k):
		if b[i] == 0:
			continue
		else:
			result += arr[j + b[i] - 1]
			j += b[i]
	print(result)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	w = list(map(int, input().split()))
	w.sort()
	arr.sort(reverse=True)
	m = 0
	ans = 0
	minn = -1
	for i in range(k):
		if w[i] == 1:
			ans += arr[m] * 2
			m += 1
	w = w[::-1]
	for i in range(k):
		if w[i] > 1:
			ans += arr[m] + arr[minn]
			m += 1
			minn -= w[i] - 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l1.sort(reverse=True)
	l2 = list(map(int, input().split()))
	l2.sort()
	sum = 0
	temp2 = []
	for i in range(k):
		if l2[i] - 1 == 0:
			sum = sum + l1[i] + l1[i]
		else:
			sum = sum + l1[i]
	for i in range(k, n):
		temp2.append(l1[i])
	j = 0
	i = 0
	while i < len(temp2):
		if l2[j] - 1 != 0:
			sum = sum + temp2[i + l2[j] - 2]
			i = i + l2[j] - 2 + 1
		j = j + 1
	print(sum)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	ppl = list(map(int, input().split()))
	arr.sort(reverse=True)
	ppl.sort()
	total = 0
	i = k - 1
	ans = [x for x in arr[:k]]
	for l in range(k):
		if ppl[l] == 1:
			ans[l] += ans[l]
		else:
			i += ppl[l] - 1
			ans[l] += arr[i]
	print(sum(ans))


t = int(input())
for testcase in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	w.sort()
	sum = 0
	for i in range(k):
		if w[i] == 1:
			sum += a[i] * 2
		else:
			sum += a[i]
		w[i] -= 1
	w.reverse()
	j = n - 1
	indx = 0
	for i in range(k):
		if w[i] == 0:
			break
		sum += a[j]
		j -= w[i]
	print(sum)


import sys

def input():
	return sys.stdin.readline().rstrip()

def input_split():
	return [int(i) for i in input().split()]
testCases = int(input())
answers = []
for _ in range(testCases):
	(n, k) = input_split()
	arr = input_split()
	arr.sort()
	ans = 0
	dist = input_split()
	dist.sort()
	till = k
	for i in range(k):
		if dist[i] > 1:
			till = i
			break
	single = dist[:till]
	more_than_one = dist[till:]
	more_than_one.reverse()
	left_ptr = 0
	right_ptr = n - 1
	for w in single:
		ans += 2 * arr[right_ptr]
		right_ptr -= 1
	for w in more_than_one:
		ans += arr[left_ptr]
		left_ptr += 1
		ans += arr[right_ptr]
		right_ptr -= 1
		left_ptr += w - 2
	answers.append(ans)
print(*answers, sep='\n')


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	tot = 0
	ma = n - 1
	mi = 0
	no = 0
	a.sort()
	b.sort(reverse=True)
	c = b.count(1)
	d = b.count(2)
	for i in range(c):
		tot += 2 * a[ma]
		ma -= 1
	for i in range(d):
		tot += a[ma] + a[ma - 1]
		ma -= 2
	e = k - c - d
	for i in range(e):
		tot += a[ma] + a[mi]
		ma -= 1
		mi += b[i] - 1
	print(tot)


t = int(input())
for i in range(t):
	line = input().split()
	int_line = [int(x) for x in line]
	(n, k) = int_line
	ns = input().split()
	ns = [int(x) for x in ns]
	ws = input().split()
	ws = [int(x) for x in ws]
	ns.sort()
	ws.sort()
	result = 0
	num_one = ws.count(1)
	if num_one:
		result += 2 * sum(ns[-num_one:])
		ns = ns[:-num_one]
		ws = ws[num_one:]
	ws.reverse()
	start = 0
	end = len(ns) - 1
	for i in range(len(ws)):
		result += ns[end]
		end -= 1
		result += ns[start]
		start += ws[i] - 1
	print(result)


def satisfaction(gift, num, n, k):
	sum = 0
	while len(num) > 0 and num[-1] == 1:
		sum += gift[-1] * 2
		gift.pop()
		num.pop()
	for i in num:
		sum += gift[0]
		for j in range(i - 1):
			gift.pop(0)
		sum += gift[-1]
		gift.pop()
	return sum
t = int(input())
for _ in range(t):
	nk = input().split()
	n = nk[0]
	k = nk[1]
	gift = list(map(int, input().split()))
	gift.sort()
	num = list(map(int, input().split()))
	num.sort()
	num.reverse()
	print(satisfaction(gift, num, n, k))


from sys import stdin
for _ in ' ' * int(stdin.readline()):
	(a, b) = map(int, stdin.readline().split())
	z = sorted(map(int, stdin.readline().split()), reverse=1 == 1)
	k = sorted(map(int, stdin.readline().split()))
	(i1, i, j, s) = (0, 0, a - 1, 0)
	while i1 < b and k[i1] == 1:
		s += 2 * z[i]
		i += 1
		i1 += 1
	for x in range(b - 1, i1 - 1, -1):
		s += z[i] + z[j]
		j += 1 - k[x]
		i += 1
	print(s)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	n_list = list(map(int, input().split()))
	f_list = list(map(int, input().split()))
	list.sort(n_list)
	list.sort(f_list)
	ans = 0
	start = 0
	end = len(n_list) - 1
	for x in f_list:
		if x == 1:
			ans += 2 * n_list[end]
		else:
			ans += n_list[end]
		end -= 1
	end += 1
	for x in f_list:
		if x == 1:
			continue
		end -= x - 1
		ans += n_list[end]
	print(ans)


def solve():
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	W = list(map(int, input().split()))
	ans = 0
	A = sorted(A)
	W = sorted(W)
	maxes = sum(A[-K:])
	mins = 0
	idx_low = 0
	idx_top = N - 1
	for w in reversed(W):
		if w - 1 == 0:
			mins += A[idx_top]
			idx_top -= 1
		else:
			mins += A[idx_low]
			use = w - 1
			idx_low += use
	print(maxes + mins)
T = int(input())
for _ in range(T):
	solve()


for _ in range(int(input())):
	(_, _) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	w.sort()
	k = len(a) - 1
	i = 0
	ans = 0
	while i < len(w) and w[i] == 1:
		ans += a[k] * 2
		k -= 1
		i += 1
	j = i
	while j < len(w):
		ans += a[k]
		k -= 1
		j += 1
	while i < len(w):
		ans += a[k - w[i] + 2]
		k = k - w[i] + 1
		i += 1
	print(ans)


t = int(input())
for isc in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	w = list(map(int, input().split()))
	w.sort()
	l.sort()
	ret = [[]] * k
	retsum = 0
	for i in range(k):
		if w[i] == 1:
			retsum += 2 * l.pop()
		else:
			retsum += l.pop()
		w[i] -= 1
	for i in range(k):
		temp = 0
		while w[i] != 0:
			temp = l.pop()
			w[i] -= 1
		retsum += temp
	print(retsum)


import sys, io, os, time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
input = sys.stdin.readline
for ii in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	w = list(map(int, input().split()))
	arr.sort(reverse=True)
	w.sort()
	l = 0
	ii = 0
	ans = 0
	while ii < n and w[ii] == 1:
		ans += arr[l] * 2
		ii += 1
		l += 1
	r = n - 1
	for i in range(k - 1, ii - 1, -1):
		offset = w[i]
		ans += arr[l] + arr[r]
		r -= offset - 1
		l += 1
	print(ans)


t = int(input())
while t != 0:
	(n, m) = map(int, input().split())
	arrN = list(map(int, input().split()))
	arrN.sort(reverse=True)
	arrF = list(map(int, input().split()))
	arrF.sort()
	sumResult = 0
	lastIndexOne = -1
	for i in range(len(arrF) - 1, -1, -1):
		if arrF[i] == 1:
			lastIndexOne = i
			break
	partialArr = arrF[lastIndexOne + 1:m]
	partialArr.sort(reverse=True)
	newArrF = arrF[0:lastIndexOne + 1] + partialArr
	i = 0
	j = 0
	k = len(arrN) - 1
	while i < len(newArrF) and j < len(arrN) and (j <= k):
		if arrF[i] == 1:
			sumResult += arrN[j] * 2
			i += 1
			j += 1
			continue
		else:
			sumResult += arrN[j] + arrN[k]
			k -= newArrF[i] - 1
			i += 1
			j += 1
			continue
	print(sumResult)
	t -= 1


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a = sorted(list(map(int, input().split())), reverse=True)
	w = sorted(list(map(int, input().split())))
	s = 0
	no = -1
	for i in range(k):
		if w[i] != 1:
			no = i
			break
		s += 2 * a[i]
	if no == -1:
		print(s)
		continue
	s += sum(a[no:k])
	ind = k
	ce = ind - 1
	for i in range(no, k):
		s += a[ce + w[i] - 1]
		ce += w[i] - 1
	print(s)


t = int(input())
for test in range(t):
	(n, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	w = [int(i) for i in input().split()]
	ans = 0
	a.sort()
	w.sort()
	final = [0 for i in range(k)]
	for i in range(k):
		temp = a.pop()
		final[k - i - 1] = temp
		ans += temp
	index = 0
	while w:
		temp = w.pop()
		if temp == 1:
			ans += final.pop()
		else:
			ans += a[index]
			index += temp - 1
	print(ans)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	w.sort()
	res = 0
	j = 0
	m = 0
	for i in w:
		if i == 1:
			res += a[j]
		res += a[j]
		j += 1
	a.sort()
	w.sort(reverse=True)
	for i in w:
		if i != 1:
			res += a[m]
		m += i - 1
	print(res)


from sys import stdin as inp
from math import gcd, sqrt, floor, ceil, log2
for _ in range(int(inp.readline())):
	(n, k) = map(int, inp.readline().split())
	arr = list(map(int, inp.readline().split()))
	w = list(map(int, inp.readline().split()))
	arr.sort()
	temp = []
	ans = 0
	for i in w:
		if i == 1:
			ans += 2 * arr.pop()
		else:
			temp.append(i)
	j = len(arr) - 1
	s = 0
	temp.sort(reverse=True)
	for i in range(len(temp)):
		ans += arr[j] + arr[s]
		s += temp[i] - 1
		j -= 1
	print(ans)


import os, sys, atexit
from io import BytesIO, StringIO
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
_OUTPUT_BUFFER = StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
t = int(input())
while t:
	t += -1
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	w = list(map(int, input().split()))
	l.sort(reverse=True)
	w.sort()
	ans = []
	for i in range(k):
		ans.append([l[i]])
	j = k
	for i in range(k):
		tmp = w[i] - 1
		if tmp == 0:
			ans[i].append(ans[i][0])
		else:
			j += tmp
			ans[i].append(l[j - 1])
	sm = 0
	for i in ans:
		sm += i[0] + i[1]
	print(sm)


t = int(input())
for x in range(t):
	(n, k) = map(int, input().split(' '))
	arr = list(map(int, input().split(' ')))
	w = list(map(int, input().split(' ')))
	arr.sort()
	w.sort()
	summ = sum(arr[n - k:])
	idx = k - 1
	for (i, j) in enumerate(w):
		if j == 1:
			summ += arr[n - i - 1]
		else:
			idx += j - 1
			summ += arr[n - idx - 1]
	print(summ)


from collections import deque
import sys

def inp():
	return sys.stdin.readline().strip()
for _ in range(int(inp())):
	(n, k) = map(int, inp().split())
	a = list(map(int, inp().split()))
	w = list(map(int, inp().split()))
	mx = [-float('inf')] * k
	mn = [float('inf')] * k
	a.sort()
	i = n - 1
	pos = 0
	ll = [i for i in range(k)]
	ll.sort(key=lambda i: w[i])
	while pos < k:
		if w[ll[pos]] > 0:
			mx[ll[pos]] = max(mx[ll[pos]], a[i])
			mn[ll[pos]] = min(mn[ll[pos]], a[i])
			w[ll[pos]] -= 1
		i = i - 1
		pos = pos + 1
	pos = 0
	while i >= 0:
		while w[ll[pos]] > 0:
			mx[ll[pos]] = max(mx[ll[pos]], a[i])
			mn[ll[pos]] = min(mn[ll[pos]], a[i])
			w[ll[pos]] -= 1
			i = i - 1
		pos = pos + 1
	ans = 0
	for i in range(k):
		if mn[i] != float('inf'):
			ans += mn[i] + mx[i]
	print(ans)


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	(n, k) = inputnums()
	a = inputlist()
	w = inputlist()
	a.sort()
	w.sort(reverse=True)
	ans = 0
	zeros = 0
	for i in range(k):
		if w[i] == 1:
			zeros += 1
		w[i] -= 1
	for i in reversed(range(n - k, n)):
		ans += a[i]
		if n - i - 1 < zeros:
			ans += a[i]
	i = 0
	j = 0
	while i < n - k:
		ans += a[i]
		i += w[j]
		j += 1
	print(ans)


rw = int(input())
for ewq in range(rw):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	a.reverse()
	w.sort()
	d = [[] for i in range(k)]
	p = 0
	for i in range(k):
		d[i].append(a[p])
		p += 1
	for i in range(k):
		for j in range(w[i] - 1):
			d[i].append(a[p])
			p += 1
	p = 0
	for i in range(k):
		p += max(d[i])
		p += min(d[i])
	print(p)


def solve():
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	x = list(map(int, input().split()))
	x.sort(reverse=True)
	c = l[::-1]
	l.sort()
	a = x.count(1)
	(j, s) = (0, 0)
	for i in range(a):
		s += 2 * c[i]
	for i in range(k):
		if x[i] != 1:
			s += l[j] + c[a]
			a += 1
			j += x[i] - 1
		else:
			continue
	print(s)
for _ in range(int(input())):
	solve()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
testcases = int(input())
for j in range(testcases):
	(n, k) = map(int, input().split())
	vals = list(map(int, input().split()))
	nums = list(map(int, input().split()))
	nums.sort()
	vals.sort()
	unique = [vals[0]]
	freq = [1]
	for s in range(1, len(vals)):
		if vals[s] == vals[s - 1]:
			freq[-1] += 1
		else:
			unique.append(vals[s])
			freq.append(1)
	total = 0
	max1 = 0
	for s in range(k):
		max1 += unique[-1]
		if nums[s] == 1:
			max1 += unique[-1]
		freq[-1] -= 1
		if freq[-1] == 0:
			unique.pop()
			freq.pop()
	min1 = 0
	for s in range(k):
		count = nums[s] - 1
		if nums[s] - 1 > 0:
			last = 0
			while count > 0:
				last = unique[-1]
				freq[-1] -= 1
				if freq[-1] == 0:
					unique.pop()
					freq.pop()
				count -= 1
			min1 += last
	print(min1 + max1)


def solve():
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	w.sort()
	a.sort(reverse=True)
	s = 0
	wp = 0
	curr = k - 1
	for (ind, ele) in enumerate(a):
		if wp >= k:
			break
		if w[wp] == 1:
			s += 2 * ele
		else:
			curr += w[wp] - 1
			s += ele + a[curr]
		wp += 1
	print(s)
t = 1
t = int(input())
for _ in range(t):
	solve()


def solve(n, k, ar, w):
	dp = [0] * k
	ar.sort(reverse=True)
	w.sort()
	ans = 0
	l = 0
	ptr_i = k
	r = n - 1
	for i in range(k):
		if w[i] > 1:
			ptr_i = i
			break
		else:
			ans += ar[l] * 2
			l += 1
	for u in range(k - 1, ptr_i - 1, -1):
		i = w[u]
		ans += ar[l] + ar[r]
		l += 1
		r = r - i + 1
	print(ans)
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	ar = list(map(int, input().split()))
	w = list(map(int, input().split()))
	solve(n, k, ar, w)


t = int(input())
D = []
for i in range(0, t):
	(n, k) = [int(x) for x in input().split(' ')]
	A = [int(x) for x in input().split(' ')]
	W = [int(x) for x in input().split(' ')]
	c_1 = W.count(1)
	A.sort()
	s = 0
	for j in range(c_1):
		s += 2 * A[n - 1 - j]
		A.pop(n - 1 - j)
	W.sort()
	a = len(A)
	if a > 0:
		for j in range(k - c_1):
			s += A[0]
			s += A[-1]
			A.pop(-1)
			for k in range(W[-1] - 1):
				A.pop(0)
			W.pop(-1)
	D.append(s)
for i in D:
	print(i)


t = int(input())
while t > 0:
	(n, k) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	arr.sort(reverse=True)
	weight = [int(i) for i in input().split()]
	count1 = weight.count(1)
	weight.sort(reverse=True)
	summ = 0
	i = 0
	st = 0
	for i in range(count1):
		summ += 2 * arr[i]
	st = count1
	end = n - 1
	for i in weight:
		if i == 1:
			break
		else:
			summ += arr[st] + arr[end]
			st += 1
			end = end - i + 1
	print(summ)
	t -= 1


from sys import stdin
import heapq

def main():
	for _ in range(int(stdin.readline())):
		(n, k) = [int(i) for i in stdin.readline().split()]
		num_heap = [-1 * int(i) for i in stdin.readline().split()]
		heapq.heapify(num_heap)
		counts = sorted([int(i) for i in stdin.readline().split()])
		sum_ = 0
		for bla in range(k):
			counts[bla] -= 1
			if counts[bla] == 0:
				sum_ -= 2 * heapq.heappop(num_heap)
			else:
				sum_ -= heapq.heappop(num_heap)
		for bla in range(len(counts)):
			if counts[bla] == 0:
				continue
			while counts[bla] != 0:
				num = heapq.heappop(num_heap)
				counts[bla] -= 1
			sum_ -= num
		print(sum_)
main()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	w = list(map(int, input().split()))
	l = sorted(l)[::-1]
	w = sorted(w)[::-1]
	t = w.count(1)
	z = t
	ans = 2 * sum(l[:t])
	b = n - 1
	for i in range(k - z):
		ans += l[t] + l[b]
		t += 1
		b = b - w[i] + 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	integ = list(map(int, input().split()))
	frnum = list(map(int, input().split()))
	happiness = 0
	integ.sort()
	frnum.sort()
	r = n - 1
	l = 0
	while l < k and frnum[l] == 1:
		happiness += 2 * integ[r]
		r -= 1
		l += 1
	k -= l
	left = 0
	for i in range(k):
		happiness += integ[r] + integ[left]
		left += frnum[-1 - i] - 1
		r -= 1
	print(happiness)


from collections import Counter
import string
import math
import sys

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(arrber_of_variables):
	if arrber_of_variables == 1:
		return int(sys.stdin.readline())
	if arrber_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))
for _ in range(vary(1)):
	(n, k) = vary(2)
	num = array_int()
	num.sort(reverse=True)
	friends = array_int()
	friends.sort()
	ans = 0
	j = 0
	for i in range(k):
		if friends[i] == 1:
			ans += num[j] * 2
			j += 1
			friends[i] -= 1
		else:
			ans += num[j]
			j += 1
			friends[i] -= 1
	num.sort()
	j = 0
	friends.sort(reverse=True)
	for i in range(k):
		if friends[i] > 0:
			ans += num[j]
			j += friends[i]
	print(ans)


import bisect
for t in range(int(input())):
	(n, k) = map(int, input().split())
	(*a,) = map(int, input().split())
	(*w,) = map(int, input().split())
	a.sort()
	w.sort()
	ans = 0
	(l, r) = (0, n - 1)
	i = 0
	while i < len(w) and w[i] == 1:
		ans += a[r] * 2
		r -= 1
		i += 1
	i = len(w) - 1
	while i >= 0 and w[i] > 1:
		ans += a[l] + a[r]
		l += w[i] - 1
		r -= 1
		i -= 1
	print(ans)


import sys, math, cmath, time
start_time = time.time()

def solve():
	(n, k) = invr()
	a = inlt()
	b = inlt()
	a.sort()
	b.sort()
	b.reverse()
	q = 0
	w = len(a) - b.count(1) - 1
	s = 0
	qw = a[len(a) - b.count(1):]
	a = a[:len(a) - b.count(1)]
	for i in range(len(b)):
		if b[i] != 1:
			s = s + a[q] + a[w]
			q = q + b[i] - 1
			w = w - 1
	print(s + sum(qw) * 2)

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = inp()
	for tt in range(t):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	return input().strip()

def invr():
	return map(int, input().split())

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = (q[a[i] - 1], 1)
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = (q[ord(a[i]) - 97], 1)
	return q

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	count = []
	a.sort(reverse=True)
	w.sort()
	max = []
	min = []
	for i in range(k):
		max.append(a[i])
	j = k - 1
	for i in range(k):
		if w[i] - 1 == 0:
			min.append(max[i])
		else:
			j = j + (w[i] - 1)
			min.append(a[j])
	sum = 0
	for i in range(k):
		sum += max[i] + min[i]
	print(sum)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a = sorted(a)
	w = sorted(w)
	a = a[::-1]
	ans = 0
	for i in range(k):
		ans += a[i]
		if w[i] == 1:
			ans += a[i]
	j = k - 1
	for i in range(k):
		if w[i] != 1:
			ans += a[j + w[i] - 1]
		j += w[i] - 1
	print(ans)


from sys import stdin
import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	b.sort()
	a.sort()
	c = []
	d = []
	j = 0
	i = n - 1
	z = k - 1
	m = 0
	while 1:
		if b[j] == 1:
			c.append(a[i])
			d.append(a[i])
			i -= 1
			j += 1
			if j == k:
				break
		else:
			c.append(a[i])
			d.append(a[m])
			m = m + (b[z] - 1)
			i -= 1
			z -= 1
			if z < j:
				break
	su = 0
	for i in range(k):
		su += c[i] + d[i]
	print(su)


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	(n, k) = map(int, stdin.readline().strip().split())
	a = list(map(int, stdin.readline().strip().split()))
	w = list(map(int, stdin.readline().strip().split()))
	w = sorted(w, reverse=True)
	a = sorted(a)
	i = 0
	j = n - 1
	ans = 0
	temp = len(w) - 1
	while temp >= 0 and w[temp] == 1:
		ans = ans + a[j] * 2
		j -= 1
		temp -= 1
	for ii in range(temp + 1):
		x = w[ii]
		ans += a[j]
		ans += a[i]
		j = j - 1
		i = i + (x - 1)
	print(ans)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a = sorted(a)
	w = sorted(w)
	li = [[] for i in range(len(w))]
	for i in range(len(w)):
		if w[i] != 0:
			m = a.pop()
			w[i] -= 1
			li[i].append(m)
	idx = 0
	for i in range(len(w) - 1, -1, -1):
		if w[i] != 0:
			li[i].append(a[idx])
			idx += w[i]
	sum_ = 0
	for i in li:
		sum_ += i[0]
		sum_ += i[-1]
	print(sum_)


def read_int():
	return int(input())

def read_string_array():
	return input().split()

def read_int_array():
	return [int(_) for _ in read_string_array()]

def read_line():
	return input()

def solve(n, k, a, w):
	w = sorted(w)
	a = sorted(a)
	numbers = [[] for _ in w]
	for (i, item) in enumerate(w):
		numbers[i].append(a.pop())
	for i in range(len(w)):
		while len(numbers[i]) != w[i]:
			numbers[i].append(a.pop())
	return sum((max(_) + min(_) for _ in numbers))
T = read_int()
for _ in range(T):
	(N, K) = read_int_array()
	A = read_int_array()
	W = read_int_array()
	print(solve(N, K, A, W))


t = int(input())
for testcase in range(t):
	(n, k) = map(int, input().split())
	prices = list(map(int, input().split()))
	frnds = list(map(int, input().split()))
	prices = sorted(prices, reverse=True)
	frnds = sorted(frnds, reverse=False)
	c = -1
	sum = 0
	for i in range(len(frnds)):
		sum += prices[i]
		c = c + 1
	for i in range(len(frnds)):
		if frnds[i] == 1:
			sum += prices[i]
		else:
			c = c + frnds[i] - 1
			sum += prices[c]
	print(sum)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	w.sort(reverse=True)
	ans = sum(a[-k:])
	t = 0
	p = n - 1
	for x in w:
		if x > 1:
			ans += a[t]
			t += x - 1
		else:
			ans += a[p]
			p -= 1
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ints = list(map(int, input().split()))
	ints.sort(reverse=True)
	ans = 0
	hpines = list(map(int, input().split()))
	hpines.sort()
	r = 0
	for i in range(k):
		if hpines[i] == 1:
			ans += ints[r] * 2
		else:
			ans += ints[r]
		r += 1
	for i in range(k):
		if hpines[i] == 1:
			continue
		r += hpines[i] - 1
		ans += ints[r - 1]
	print(ans)


def answer(n, k, A, B):
	A.sort()
	B.sort()
	ans = 0
	l = 0
	r = n - 1
	for i in B:
		if i == 1:
			ans += A[r] * 2
			r -= 1
		elif i == 2:
			ans += A[r] + A[r - 1]
			r -= 2
		else:
			break
	for i in range(k - 1, -1, -1):
		if B[i] > 2:
			ans += A[r] + A[l]
			r -= 1
			l += B[i] - 1
		else:
			break
	return ans
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	w = list(map(int, input().split()))
	print(answer(n, k, A, w))


from collections import defaultdict, Counter
import math
from functools import reduce, lru_cache
from heapq import heapify, heappush, heappop
import sys
from sys import stdin, stdout
from random import seed
from random import randint
mod = 10 ** 9 + 7

def mul_mod(a, b):
	return a % mod * (b % mod) % mod

def add_mod(a, b):
	return (a % mod + b % mod) % mod

def sub_mod(a, b):
	return (a % mod - b % mod + mod) % mod

def modInverse(b):
	return pow(b, mod - 2, mod)

def div_mod(a, b):
	a = a % mod
	inv = modInverse(b)
	return inv * a % mod

class Graph:

	def __init__(self, vertices):
		self.V = vertices + 1
		self.graph = defaultdict(set)
		self.Time = 0
		self.P = 0
		self.Q = 0

	def addEdge(self, u, v):
		self.graph[u].add(v)
		self.graph[v].add(u)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort(reverse=True)
	distribution = [[] for i in range(k)]
	start = 0
	end = n - k
	ans = 0
	for i in range(k):
		distribution[i].append(a[end])
		end += 1
		count = 1
		while count <= b[i] - 1:
			count += 1
			distribution[i].append(a[start])
			start += 1
		ans += max(distribution[i]) + min(distribution[i])
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	w.sort()
	res = 0
	i = 0
	j = n - 1
	p = 0
	while p < k and w[p] == 1:
		res = res + 2 * a[j]
		j -= 1
		p += 1
	q = k - 1
	while q >= p:
		res += a[i] + a[j]
		i += 1
		j -= 1
		w[q] -= 2
		while w[q] > 0:
			i += 1
			w[q] -= 1
		q -= 1
	print(res)


import math
import sys
from itertools import permutations
input = sys.stdin.readline
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	wlist = list(map(int, input().split()))
	arr.sort(reverse=True)
	wlist.sort()
	ans = 0
	cur = 0
	for j in range(k):
		ans += arr[cur]
		if wlist[j] == 1:
			ans += arr[cur]
		cur += 1
	for j in range(k):
		if wlist[j] > 1:
			cur += wlist[j] - 1
			ans += arr[cur - 1]
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	w.sort()
	ans = 0
	c = 0
	c1 = w.count(1)
	for i in range(k):
		if w[i] == 1:
			ans += a[i] * 2
		else:
			ans += a[i]
	w = w[c1:]
	w.sort(reverse=True)
	for j in range(len(w)):
		ans += a[n - c - 1]
		c += w[j] - 1
	print(ans)


n = int(input())
for _ in range(n):
	(n_integers, n_friends) = list(map(int, input().split()))
	integers = list(map(int, input().split()))
	gifts = list(map(int, input().split()))
	integers = sorted(integers, reverse=True)
	gifts = sorted(gifts)
	happiness_total = 0
	for i in range(n_friends):
		happiness_total += integers[i]
		if gifts[i] == 1:
			happiness_total += integers[i]
	i = n_friends - 1
	for gift in gifts:
		if gift != 1:
			i += gift - 1
			happiness_total += integers[i]
	print(happiness_total)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def bs(a, l, h, x):
	while l < h:
		mid = (l + h) // 2
		if a[mid] == x:
			return mid
		if a[mid] < x:
			l = mid + 1
		else:
			h = mid
	return l

def sieve(a):
	for i in range(3, 10 ** 6 + 1, 2):
		a[i] = 1
	for i in range(3, 10 ** 6 + 1, 2):
		for j in range(i * i, 10 ** 6 + 1, i):
			a[j] = 0
	a[2] = 1
	return a

def solve():
	(n, k) = sep()
	a = sorted(lis())[::-1]
	w = sorted(lis())
	st = 0
	end = n - 1
	ans = 0
	used = 0
	for i in range(0, k):
		if w[i] == 1:
			ans += 2 * a[st]
			st += 1
		elif w[i] == 2:
			ans += a[st] + a[st + 1]
			st += 2
		else:
			temp = k - i + (w[i] - 1 - 1) + used
			ans += a[st] + a[st + temp]
			st += 1
			end -= w[i] - 1
			used += w[i] - 1
	print(ans)
testcase(int(inp()))


import os
os_input = os.read(0, int(10000000.0)).split()
os_input_pos = -1
answer_list = []

def read_s():
	global os_input_pos
	os_input_pos += 1
	return os_input[os_input_pos].decode()

def read_i():
	return int(read_s())

def write_s(v):
	answer_list.append(v)

def write_i(v):
	write_s(str(v))

def print_ans():
	os.write(1, '\n'.join(answer_list).encode())
	os.write(1, '\n'.encode())
T = read_i()
while T:
	T -= 1
	n = read_i()
	k = read_i()
	a = sorted([read_i() for i in range(n)])
	w = sorted([read_i() for i in range(k)])
	ones = w.count(1)
	ans = sum(a[-k:])
	if ones:
		ans += sum(a[-ones:])
	pos = 0
	for i in reversed(w):
		if i == 1:
			break
		ans += a[pos]
		pos += i - 1
	write_i(ans)
print_ans()


import sys
import math
input = sys.stdin.readline
from collections import deque
from queue import LifoQueue
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	w.sort()
	c = []
	p = 0
	i = 0
	while i < k:
		if w[i] == 1:
			c.append(2 * a[p])
			p += 1
			w[i] -= 1
		elif w[i] == 2:
			c.append(a[p])
			c.append(a[p + 1])
			p += 2
			w[i] -= 2
		else:
			c.append(a[p])
			p += 1
			w[i] -= 1
		i += 1
	p = len(c)
	for i in range(k):
		if w[i]:
			c.append(min(a[p:p + w[i]]))
			p += w[i]
	print(sum(c))


t = int(input())
while t:
	t = t - 1
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	w.sort()
	(lef, rit, g1) = (0, n - 1, k)
	happiness = 0
	for i in range(k):
		if w[i] > 1:
			g1 = i
			break
		happiness = happiness + a[lef] * 2
		lef = lef + 1
	for x in range(k - 1, g1 - 1, -1):
		s = w[x]
		happiness = happiness + a[lef] + a[rit]
		lef = lef + 1
		rit = rit - s + 1
	print(happiness)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	w.sort()
	a.sort()
	ans = [[] for i in range(k)]
	for i in range(k):
		ans[i].append(a.pop())
	for i in range(k):
		for j in range(w[i] - 1):
			ans[i].append(a.pop())
	tot = 0
	for i in range(k):
		tot += ans[i][0]
		tot += ans[i][-1]
	print(tot)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	w.sort()
	w.reverse()
	x = 0
	t = 0
	for i in range(k - 1, -1, -1):
		if w[i] == 1:
			x += 2 * a[n - t - 1]
			t += 1
		else:
			break
	n = n - t
	k = k - t
	if n == 0:
		print(x)
	else:
		x = x + a[0]
		for i in range(n - 1, n - 1 - k, -1):
			x += a[i]
		y = 0
		for j in range(k - 1):
			y += w[j]
			x += a[y - j - 1]
		print(x)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l1 = list(map(int, input().split()))
	l.sort()
	l1.sort()
	num = [[] for i in range(k)]
	total_happiness = 0
	for i in range(k):
		num[i].append(l[n - i - 1])
	x = n - k - 1
	for i in range(k):
		if l1[i] > 0:
			for j in range(l1[i] - 1):
				num[i].append(l[x])
				x -= 1
	for i in num:
		total_happiness += i[0] + i[-1]
	print(total_happiness)


import sys
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	W = [int(x) for x in input().split()]
	arr.sort()
	W.sort(reverse=True)
	b = k // 2
	oneStartIndex = -1
	while b:
		while oneStartIndex + b < k and W[oneStartIndex + b] > 1:
			oneStartIndex += b
		b //= 2
	oneStartIndex += 1
	W = W[oneStartIndex:] + W[:oneStartIndex]
	total = 0
	topPointer = len(arr) - 1
	bottomPoiner = 0
	for w in W:
		if w > 1:
			total += arr[topPointer] + arr[bottomPoiner]
			topPointer -= 1
			bottomPoiner += w - 1
		else:
			total += 2 * arr[topPointer]
			topPointer -= 1
	print(total)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def sieve_of_eratosthenes(n):
	ans = []
	arr = [1] * (n + 1)
	(arr[0], arr[1], i) = (0, 0, 2)
	while i * i <= n:
		if arr[i] == 1:
			j = i + i
			while j <= n:
				arr[j] = 0
				j += i
		i += 1
	for k in range(n):
		if arr[k] == 1:
			ans.append(k)
	return ans

def nc2(x):
	if x == 1:
		return 0
	else:
		return x * (x - 1) // 2
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	w.sort()
	(g_one, l, r) = (k, 0, n - 1)
	ans = 0
	for i in range(k):
		if w[i] > 1:
			g_one = i
			break
		ans += a[l] * 2
		l += 1
	for i in range(k - 1, g_one - 1, -1):
		jump = w[i] - 1
		ans += a[l] + a[r]
		r -= jump
		l += 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a_sort = sorted(a, key=int)
	w_sort = sorted(w, key=int)
	happiness = 0
	curr_ind = 0
	ind1 = 0
	while ind1 < k and w_sort[ind1] == 1:
		happiness += 2 * a_sort.pop()
		ind1 += 1
	for i in range(k - ind1):
		happiness += a_sort[curr_ind] + a_sort[-i - 1]
		curr_ind += w_sort[-i - 1] - 1
	print(happiness)


t = int(input())
for _ in range(t):
	(n, k) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	w = [int(i) for i in input().split()]
	arr.sort()
	w.sort()
	ans = 0
	for i in range(n - 1, n - k - 1, -1):
		ans += arr[i]
	start = n - k
	end = n - 1
	for i in range(k):
		if w[i] == 1:
			ans += arr[end]
			end -= 1
			continue
		else:
			temp = w[i] - 1
			ans += arr[start - temp]
			start -= temp
	print(ans)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	z = list(map(int, input().split()))
	z.sort(reverse=1)
	x = [int(i) - 1 for i in input().split() if i != '1']
	ans = sum(z[:k]) + sum(z[:k - len(x)])
	x.sort()
	a = k - 1
	for j in x:
		ans += z[a + j]
		a = a + j
	print(ans)


import sys
input = sys.stdin.readline
read = lambda : map(int, input().split())
read_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(div, n):
	if div == 0:
		return True
	return n % div == 0
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
from itertools import permutations
import math
import bisect as bis
import random
import sys

def solve():
	(n, k) = read()
	a = list(read())
	w = list(read())
	a.sort(reverse=True)
	w.sort()
	c = w.count(1)
	ans = sum(a[:k]) + sum(a[:c])
	for i in w[c:]:
		k += i - 1
		ans += a[k - 1]
	print(ans)
for _ in range(int(input())):
	solve()


for i in range(int(input())):
	(n, x) = map(int, input().split())
	a = [int(i) for i in input().strip().split(' ')]
	b = [int(i) for i in input().strip().split(' ')]
	a.sort()
	b.sort(reverse=True)
	l = b.count(1)
	ans = sum(a[n - x:]) + sum(a[n - l:])
	i = 0
	for e in b:
		if e == 1:
			break
		else:
			ans += a[i]
			i += e - 1
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a = sorted(a)
	w = sorted(w, reverse=True)
	piche = n - 1
	aage = 0
	ans = 0
	i = k - 1
	while w[i] == 1:
		ans += 2 * a[piche]
		piche -= 1
		i -= 1
		if i <= 0:
			break
	for j in range(i + 1):
		ans += a[aage] + a[piche]
		aage += w[j] - 1
		piche -= 1
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	cap = list(map(int, input().split()))
	cap.sort()
	out = 0
	j = 0
	broke = False
	for i in range(k):
		if cap[i] == 1:
			out += arr.pop() * 2
		else:
			broke = True
			break
	if not broke:
		i += 1
	cap = list(reversed(cap[i:]))
	for i in cap:
		out += min(arr[j:j + i - 1]) + arr.pop()
		j += i - 1
	print(out)


input = __import__('sys').stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	lis = sorted(map(int, input().split()))
	wan = sorted(map(int, input().split()))
	ans = 0
	j = n - 1
	for i in range(k):
		if wan[i] == 1:
			ans += 2 * lis[j]
		else:
			ans += lis[j]
		j -= 1
		wan[i] -= 1
	j = 0
	wan.sort(reverse=True)
	for i in range(k):
		aa = wan[i]
		if aa != 0:
			ans += lis[j]
		j += aa
	print(ans)


import sys, collections, math
from collections import deque

def in_out():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	arr = deque(arr)
	w = list(map(int, input().split()))
	w.sort(reverse=True)
	w = deque(w)
	ans = []
	while w and w[-1] == 1:
		ans.append(2 * arr[-1])
		w.pop()
		arr.pop()
	for i in range(len(w)):
		if w[i] > 1:
			ans.append(arr[-1])
			arr.pop()
			ans.append(arr[0])
			arr.popleft()
			rem = w[i] - 2
			while rem > 0:
				arr.popleft()
				rem -= 1
	print(sum(ans))


t_ = int(input())
for t in range(t_):
	line = input()
	tmp = line.split(' ')
	(n, k) = (int(tmp[0]), int(tmp[1]))
	line = input()
	tmp = line.split(' ')
	integers = []
	for i in tmp:
		integers.append(int(i))
	integers.sort(reverse=True)
	line = input()
	tmp = line.split(' ')
	w = list(map(int, tmp))
	w.sort()
	result = 0
	ind = 0
	for i in range(k):
		tmp = integers[ind]
		ind += 1
		result += tmp
		if w[i] == 1:
			result += tmp
		w[i] -= 1
	for i in range(k):
		if w[i] == 0:
			continue
		ind += w[i]
		result += integers[ind - 1]
	print(result)


n = int(input())
while n > 0:
	_ = input()
	ints = list(reversed(sorted([int(i) for i in input().split(' ')])))
	frnd = list(reversed(sorted([int(i) for i in input().split(' ')])))
	j = 0
	sums = 0
	while len(frnd) > 0 and frnd[-1] == 1:
		sums += 2 * ints[j]
		j += 1
		frnd.pop()
	i = len(ints) - 1
	for w in frnd:
		sums += ints[j] + ints[i]
		j += 1
		i -= w - 1
	print(sums)
	n -= 1


import sys
input = sys.stdin.readline
from collections import *
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	w.sort(reverse=True)
	one = w.count(1)
	ans = 0
	q = deque([])
	for i in range(n):
		if i < one:
			ans += 2 * a[i]
		else:
			q.append(a[i])
	for wi in w:
		if wi == 1:
			break
		ans += q.popleft() + q.pop()
		for _ in range(wi - 2):
			q.pop()
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	w = list(map(int, input().split()))
	l.sort(reverse=True)
	w.sort()
	i = 0
	a = w.count(1)
	b = w.count(2)
	ans = 0
	for i in range(a):
		ans += l[i] * 2
	for i in range(a, a + 2 * b):
		ans += l[i]
	for i in range(a + 2 * b, k + b):
		ans += l[i]
	i = k + b - 1
	for j in range(a + b, k):
		i += w[j] - 1
		ans += l[i]
	print(ans)


import sys, math, os
from io import BytesIO, IOBase
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write('\n'.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
INF = float('inf')
mod = 998244353
for t in range(int(data())):
	(n, k) = mdata()
	a = mdata()
	w = mdata()
	a.sort()
	w.sort(reverse=True)
	l = 0
	ans = 0
	for i in range(k):
		if w[i] == 1:
			ans += sum(a[n - k + i:])
			break
		ans += a[l]
		l += w[i] - 1
	ans += sum(a[n - k:])
	out(ans)


t = int(input())
while t > 0:
	(n, k) = [int(ele) for ele in input().split()]
	a = [int(ele) for ele in input().split()]
	w = [int(ele) for ele in input().split()]
	K = k
	a.sort(reverse=True)
	w.sort()
	start = 0
	end = n - 1
	ans = 0
	for i in range(k):
		w[i] -= 1
		ans += a[start]
		if w[i] == 0:
			ans += a[start]
		start += 1
	for i in range(k - 1, -1, -1):
		if w[i] > 0:
			ans += a[end]
		else:
			break
		end -= w[i]
	print(ans)
	t -= 1


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	w = list(map(int, input().split()))
	l.sort()
	w.sort(reverse=True)
	low = 0
	high = n - 1
	total = 0
	count1 = 0
	for j in range(k - 1, -1, -1):
		if w[j] == 1:
			total += 2 * l[high]
			high -= 1
			count1 += 1
	for j in range(0, k - count1):
		total += l[low] + l[high]
		low += w[j] - 1
		high -= 1
	print(total)


for t in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	w = [int(x) for x in input().split()]
	count = 0
	a.sort()
	w.sort()
	(l, r) = (0, n - 1)
	s = 0
	for i in range(k):
		if w[i] == 1:
			count += 2 * a[r]
			r -= 1
			if i == k - 1:
				s = k
		else:
			s = i
			break
	for i in range(k - 1, s - 1, -1):
		count += a[l]
		l += w[i] - 1
	for i in range(l, r + 1):
		count += a[i]
	print(count)


def solve(n, k, a, w):
	a.sort(reverse=True)
	w.sort(reverse=True)
	happiness = 0
	friend = []
	one = w.count(1)
	no = k - one
	ans = sum(a[:one]) * 2 + sum(a[one:one + no])
	j = -1
	for i in w:
		if i == 1:
			break
		ans += a[j]
		j -= i - 1
	return ans
n = int(input())
for i in range(n):
	(n, k) = tuple(map(int, input().split()))
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	print(solve(n, k, a, w))


testCases = int(input())
while testCases > 0:
	(nNumbers, nFriends) = list(map(int, input().split()))
	numbers = list(map(int, input().split()))
	numbers.sort()
	friends = list(map(int, input().split()))
	friends.sort()
	smallest = 0
	biggest = nNumbers - 1
	sum = 0
	for friend in friends:
		if friend >= 3:
			break
		if friend == 1:
			sum += 2 * numbers[biggest]
			biggest -= 1
		if friend == 2:
			sum += numbers[biggest]
			biggest -= 1
			sum += numbers[biggest]
			biggest -= 1
	friends.reverse()
	for friend in friends:
		if friend <= 2:
			break
		sum += numbers[biggest] + numbers[smallest]
		biggest -= 1
		smallest += friend - 1
	print(sum)
	testCases -= 1


import sys
input = sys.stdin.readline

def getInt():
	return int(input())

def getVars():
	return map(int, input().split())

def getList():
	return list(map(int, input().split()))

def getStr():
	return input().strip()
q = getInt()
for _ in range(q):
	(n, k) = getVars()
	a = getList()
	w = getList()
	a.sort()
	w.sort()
	res = 0
	lastI = -1
	for i in range(k):
		if w[i] == 1:
			res += 2 * a[-1]
			a.pop(-1)
		else:
			lastI = i
			break
	if lastI > -1:
		x = 0
		z = -1
		for i in range(k - lastI):
			res += a[z]
			z -= 1
			res += a[x]
			x += w[k - i - 1] - 1
	print(res)


from collections import deque
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l1.sort(reverse=True)
	l2 = list(map(int, input().split()))
	l2.sort()
	r = 0
	ans = 0
	q = [[j, l2[j], float('-inf'), float('inf')] for j in range(len(l2))]
	q = deque(q)
	j = 0
	while j < len(l2):
		r = list(q.popleft())
		r[1] = r[1] - 1
		r[2] = max(l1[j], r[2])
		r[3] = min(l1[j], r[3])
		if r[1] == 0:
			ans = ans + r[2] + r[3]
		q.append(r)
		j = j + 1
	j = j - 1
	while j < len(l1) - 1:
		r = q.popleft()
		if r[1] == 0:
			continue
		else:
			j = r[1] + j
			r[3] = l1[j]
			ans = ans + r[2] + r[3]
	print(ans)


import sys
import math
from sys import stdin, stdout
from collections import deque, defaultdict
from math import ceil, floor, inf, sqrt, factorial, gcd, log2
from copy import deepcopy
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
for _ in range(ii1()):
	(n, k) = iia()
	arr = iia()
	ar = iia()
	arr.sort(reverse=True)
	ar.sort()
	ans = 0
	i = 0
	while i < k and ar[i] == 1:
		ans += 2 * arr[i]
		i += 1
	end = n - 1
	start = i
	for j in range(k - 1, i - 1, -1):
		a = ar[j]
		ans += arr[start] + arr[end]
		end += 1 - a
		start += 1
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = list(map(int, input().split()))
	k = list(map(int, input().split()))
	k.sort(reverse=True)
	ans = 0
	s.sort()
	ch = 0
	chh = len(k) - 1
	r = n - 1
	while chh >= 0 and k[chh] == 1:
		ans += s[r] * 2
		r -= 1
		chh -= 1
	for i in range(len(k) - (len(k) - 1 - chh)):
		ans += s[r]
		ans += s[ch]
		ch += k[i] - 1
		r -= 1
	print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def inin():
	return int(input())

def inar():
	return list(map(int, input().split()))
Testcase = inin()
for _ in range(Testcase):
	(n, k) = inar()
	a = inar()
	a.sort(reverse=True)
	w = inar()
	w.sort()
	idx = 0
	sm = 0
	for i in range(k):
		if w[i] == 1:
			sm += 2 * a[idx]
			idx += 1
	for i in range(k):
		if w[i] == 1:
			continue
		else:
			sm += a[idx]
			idx += 1
	for i in range(k):
		e = 0
		for j in range(w[i] - 1):
			e = a[idx]
			idx += 1
		sm += e
	print(sm)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = [int(v) for v in input().split()]
	w = [int(v) for v in input().split()]
	a.sort()
	s = 0
	x = n - 1
	j = 0
	w.sort()
	for j in range(k):
		if w[j] == 1:
			s = s + 2 * a[x]
		else:
			s = s + a[x]
		x = x - 1
	p = 0
	w = w[::-1]
	for j in range(0, k):
		if w[j] > 1:
			s = s + a[p]
			p = p + w[j] - 1
	print(s)


t = int(input())
while t:
	(n, k) = map(int, input().split(' '))
	na = sorted([i for i in map(int, input().split(' '))])
	ka = sorted([i for i in map(int, input().split(' '))], reverse=True)
	co1 = ka.count(1)
	t -= 1
	i = 0
	(lp, rp) = (0, n - 1 - co1)
	ans = 2 * sum((j for j in na[n - co1:n]))
	while i < k - co1:
		ans += na[lp] + na[rp]
		lp += ka[i] - 1
		rp -= 1
		i += 1
	print(ans)


for _ in range(int(input())):
	input()
	numbers = sorted(list(map(int, input().rstrip().split())))
	friends = sorted(list(map(int, input().rstrip().split())))
	(happiness, n) = (0, friends.count(1))
	if n != 0:
		happiness += 2 * sum(numbers[-n:])
		(numbers, friends) = (numbers[:-n], friends[n:])
	(l, r) = (0, len(numbers) - 1)
	for val in reversed(friends):
		happiness += numbers[l] + numbers[r]
		l += val - 1
		r -= 1
	print(happiness)


import math as ma
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort(reverse=True)
	b.sort()
	d = [[] for i in range(k)]
	for i in range(k):
		d[i].append(a[i])
	s = k - 1
	for i in range(k):
		if b[i] - 1 == 0:
			d.append(a[i])
		else:
			s += b[i] - 1
			d[i].append(a[s])
	s = 0
	for i in range(k):
		if len(d[i]) == 1:
			s += d[i][0] * 2
		else:
			s += sum(d[i])
	print(s)


import sys
input = sys.stdin.readline
t = int(input())
for test in range(t):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	w.sort(reverse=True)
	min_sum = 0
	max_sum = 0
	start = 0
	end = len(a) - 1
	for i in range(len(w) - 1, -1, -1):
		if w[i] == 1:
			min_sum += a[end]
			max_sum += a[end]
			end -= 1
		else:
			break
	for i in range(len(w)):
		if w[i] > 1:
			min_sum += a[start]
			start += 1
			max_sum += a[end]
			end -= 1
			rem = w[i] - 2
			start += rem
		else:
			break
	print(min_sum + max_sum)


for _ in range(int(input())):
	(n, k) = input().split(' ')
	arr = input().split(' ')
	f = input().split(' ')
	(n, k, arr, f) = (int(n), int(k), [int(i) for i in arr], [int(j) for j in f])
	arr.sort(reverse=True)
	f.sort(reverse=False)
	art = [[] for i in range(k)]
	ans = 0
	j = 0
	l = -1
	xn = n - 1
	for i in range(0, k):
		val = arr[i]
		if f[i] == 1:
			ans = ans + val * 2
		else:
			ans = ans + val
		f[i] = f[i] - 1
	for i in range(k - 1, -1, -1):
		x = f[i]
		if x > 0:
			ans += arr[xn]
			xn = xn - x
	print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	res = sum(a[:k])
	w = [w[i] - 1 for i in range(k)]
	count = 0
	for i in range(k):
		if w[i] == 0:
			res += a[count]
			count += 1
	a = a[k:]
	id = 0
	w.sort()
	id = 0
	for i in range(k):
		if w[i] != 0:
			res += a[id + w[i] - 1]
			id += w[i]
	print(res)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	w.sort(reverse=True)
	c = a[n - k:n]
	s = sum(c)
	l = 0
	for j in range(k):
		if w[j] == 1:
			s += c[j]
		else:
			s += a[l]
			l += w[j] - 1
	print(s)


cases = int(input())
for t in range(cases):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	b = []
	w = sorted(w)
	a = sorted(a)
	for i in range(k):
		v = a.pop()
		b.append(v + v)
		w[i] -= 1
	s = 0
	for i in range(k):
		wi = w[i]
		for j in range(w[i]):
			v = a.pop()
		if wi > 0:
			b[i] = b[i] // 2 + v
		s += b[i]
	print(s)


a = int(input())
for x in range(a):
	(b, c) = map(int, input().split())
	d = list(map(int, input().split()))
	e = list(map(int, input().split()))
	d.sort(reverse=True)
	e.sort(reverse=True)
	n = [d[y] for y in range(c - 1, -1, -1)]
	d.sort()
	if b == c:
		print(2 * sum(n))
	else:
		ss = 0
		for y in range(c):
			if e[y] == 1:
				n[y] = 2 * n[y]
			elif ss == 0:
				n[y] += d[ss]
				ss += e[y] - 1
			else:
				n[y] += d[ss]
				ss += e[y] - 1
		print(sum(n))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	fri = list(map(int, input().split()))
	s1 = 0
	l = []
	c = 0
	for i in fri:
		if i == 1:
			s1 += 1
		else:
			l.append(i - 1)
			c += i - 1
	l.sort(reverse=True)
	ans = 0
	if s1 > 0:
		for i in range(s1):
			ans += arr[n - i - 1] * 2
			del arr[n - i - 1]
	d = 0
	i = 0
	n = len(arr)
	while d < len(l):
		ans += arr[i] + arr[n - d - 1]
		i += l[d]
		d += 1
	print(ans)


for lo in range(int(input())):
	(n, k) = map(int, input().split())
	ls = [int(x) for x in input().split()]
	ls1 = [int(x) for x in input().split()]
	ls.sort(reverse=True)
	ls1.sort()
	s = 0
	for i in range(k):
		if ls1[i] == 1:
			s += 2 * ls[i]
		else:
			s += ls[i]
		ls1[i] -= 1
	j = k - 1
	for i in range(k):
		if ls1[i] != 0:
			j += ls1[i]
			s += ls[j]
	print(s)


import sys

def ii():
	return sys.stdin.readline().strip()

def idata():
	return [int(x) for x in ii().split()]

def solve():
	(n, k) = idata()
	a = idata()
	w = idata()
	count = 0
	a.sort()
	w.sort()
	(l, r) = (0, n - 1)
	s = 0
	for i in range(k):
		if w[i] == 1:
			count += 2 * a[r]
			r -= 1
			if i == k - 1:
				s = k
		else:
			s = i
			break
	for i in range(k - 1, s - 1, -1):
		count += a[l]
		l += w[i] - 1
	for i in range(l, r + 1):
		count += a[i]
	print(count)
	return
for t in range(int(ii())):
	solve()


import math, sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda : int(input())
li = lambda : list(map(int, input().split()))

def solve():
	(n, k) = li()
	a = li()
	b = li()
	b.sort(reverse=True)
	a.sort()
	s = sum(a[n - k:])
	c = 0
	p = 0
	for i in range(k):
		if b[i] == 1:
			c += 1
			continue
		s += a[p]
		p += b[i] - 1
	s += sum(a[n - c:])
	print(s)
for _ in range(I()):
	solve()


def cont(k, A, w):
	res = 0
	A.sort()
	w.sort(reverse=True)
	while w and w[-1] == 1:
		res = res + 2 * A.pop()
		w.pop()
	if not A or not w:
		return res
	for i in w:
		res += A.pop()
		res += A[0]
		if len(A) == i - 1:
			return res
		for j in range(i - 1):
			A.pop(0)
t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	w = list(map(int, input().split()))
	print(cont(k, A, w))


t = int(input())
while t:
	t -= 1
	(n, e) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	wr = [0] * len(w)
	a.sort(reverse=True)
	w.sort()
	sort1out = 0
	for all1 in w:
		if all1 == 1:
			sort1out += 1
		else:
			break
	no1w = w[sort1out:]
	no1w.sort(reverse=True)
	ans = 0
	cur = 0
	k = 0
	i = 0
	while i < sort1out:
		ans += 2 * a[i]
		i += 1
		k += 1
	while i < e:
		ans += a[i]
		ans += a[len(a) - 1 - i + k]
		stop = no1w[i - sort1out] - 2
		y = 0
		while y < stop:
			k -= 1
			y += 1
		i += 1
	print(ans)


for i in range(int(input())):
	(n, k) = (int(i) for i in input().split())
	ns = [int(i) for i in input().split()]
	ks = [int(i) for i in input().split()]
	ns.sort(reverse=True)
	ks.sort()
	K = [0] * k
	ans = sum(ns[:k])
	ni = 0
	kcum = 0
	Ni = -1
	Ns = ns[k:]
	for i in range(k):
		if ks[i] == 1:
			ans += ns[i]
		else:
			Ni += ks[i] - 1
			ans += Ns[Ni]
	print(ans)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	c = sorted(map(int, input().split()))
	p = sorted(map(int, input().split()))
	o = p.count(1)
	u = p[o:]
	u.sort(reverse=True)
	d = p[:o] + u
	(w, r, e, t) = (-1, 0, 0, 0)
	for i in range(b):
		if d[i] == 1:
			r += c[-1 - i] * 2
		else:
			r += c[-1 - i]
			r += c[e]
			e += d[i] - 1
	print(r)


n = int(input())
for _ in range(n):
	(k, l) = map(int, input().split())
	g = list(map(int, input().split()))[:k]
	j = list(map(int, input().split()))[:l]
	g.sort(reverse=True)
	j.sort()
	sam = sum(g[:l]) + sum(g[:j.count(1)])
	z = 0
	for i in j:
		if i != 1:
			l += i - 1
			sam += g[l - 1]
	print(sam)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted(map(int, input().split()))
	b = sorted(map(int, input().split()))
	ans = 0
	i = 0
	j = n - k
	while b:
		w = b.pop()
		ans += a[i] + a[j]
		j += 1
		i += w - 1
		if i >= n - k:
			i = j
	print(ans)


from collections import deque
for i in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	arr.sort()
	arr2.sort()
	arr1 = deque()
	for jj in arr:
		arr1.append(jj)
	ans = 0
	for j in arr2:
		if j == 1:
			ans += arr1[-1] + arr1[-1]
			arr1.pop()
	for j in arr2[::-1]:
		if j >= 2:
			ans += arr1[0]
			arr1.popleft()
			ans += arr1[-1]
			arr1.pop()
			while j > 2:
				arr1.popleft()
				j -= 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	numeros = list(map(int, input().split()))
	amigos = list(map(int, input().split()))
	numeros.sort(reverse=True)
	amigos.sort(reverse=True)
	maximos = [0 for i in range(k)]
	minimos = [float('inf') for i in range(k)]
	for i in range(k):
		maximos[k - i - 1] = numeros[i]
		minimos[k - i - 1] = numeros[i]
		amigos[k - i - 1] -= 1
	amigo = 0
	j = n - 1
	while j >= k:
		while amigos[amigo] == 0:
			amigo += 1
		minimos[amigo] = min(minimos[amigo], numeros[j])
		j -= 1
		amigos[amigo] -= 1
	print(sum(maximos) + sum(minimos))


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	(n, k) = map(int, stdin.readline().split())
	ls = sorted(list(map(int, stdin.readline().split())))
	w = sorted(list(map(int, stdin.readline().split())))
	l = n - k
	r = n - 1
	sm = 0
	for i in range(k):
		if w[i] == 1:
			sm += ls[r] * 2
			r -= 1
		else:
			l -= w[i] - 1
			sm += ls[l]
			sm += ls[r]
			r -= 1
	stdout.write(str(sm) + '\n')


def main():
	for t in range(int(input())):
		(n, k) = [int(j) for j in input().split()]
		l = [int(j) for j in input().split()]
		cap = [int(j) for j in input().split()]
		l.sort()
		cap.sort(reverse=True)
		st = [[0, 0, 0] for i in range(k)]
		for i in range(k):
			st[k - i - 1][2] = l[n - i - 1]
			st[k - i - 1][1] = l[n - i - 1]
			st[k - i - 1][0] = 1
		tmp = l[0]
		j = 0
		i = 0
		while i < n:
			if l[i] == tmp and st[j][0] < cap[j]:
				st[j][0] += 1
				st[j][1] = min(st[j][1], l[i])
				i += 1
			else:
				j += 1
				if j >= k:
					break
			tmp = l[i]
		ans = 0
		for i in range(k):
			ans += st[i][1] + st[i][2]
		print(ans)
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


T = int(input())
for _ in range(T):
	(N, K) = map(int, input().split(' '))
	a = [int(x) for x in input().split(' ')]
	w = [int(x) for x in input().split(' ')]
	a.sort()
	w.sort(reverse=True)
	ans = 0
	while w and w[-1] == 1:
		ans += 2 * a.pop()
		w.pop()
	i = 0
	for x in w:
		ans += a[i]
		i += x - 1
		ans += a.pop()
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	r = n - 1
	w.sort()
	ans = 0
	l = 0
	for x in w:
		if x == 1:
			ans += a.pop() * 2
		else:
			break
	for x in w[::-1]:
		if x == 1:
			break
		ans += a.pop()
		x -= 1
		ans += a[l]
		l += x
	print(ans)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())), reverse=True)
	w = sorted(list(map(int, input().split())))
	res = 0
	for i in range(k):
		w[i] -= 1
		if w[i] == 0:
			res += 2 * a[i]
		else:
			res += a[i]
	pos = k
	for i in range(k):
		if w[i] == 0:
			continue
		pos += w[i]
		res += a[pos - 1]
	print(res)


import sys
input = sys.stdin.readline
f = lambda : list(map(int, input().split()))
for _ in range(int(input())):
	(n, k) = f()
	a = sorted(f(), reverse=True)
	w = sorted(f())
	ans = 0
	for i in range(k):
		ans += a[i]
		if w[i] == 1:
			ans += a[i]
	cur = k
	for i in range(k):
		w[i] -= 1
		if w[i] > 0:
			ans += a[cur + w[i] - 1]
			cur += w[i]
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	w.sort()
	a.sort()
	ans = 0
	for i in range(k):
		w[i] -= 1
		if w[i] == 0:
			ans += a[n - i - 1]
		ans += a[n - i - 1]
	count = 0
	for i in range(k - 1, -1, -1):
		if w[i] != 0:
			ans += a[count]
			count += w[i]
	print(ans)


from sys import stdin, stdout
for query in range(int(stdin.readline())):
	nk = stdin.readline().split()
	n = int(nk[0])
	k = int(nk[1])
	a = sorted([int(x) for x in stdin.readline().split()])
	w = [int(x) for x in stdin.readline().split()]
	pointer1 = 0
	pointer2 = n - 1
	total = 0
	numones = 0
	for friend in range(k):
		if w[friend] == 1:
			numones += 1
			total += 2 * a[pointer2]
			pointer2 -= 1
	w = sorted(w, reverse=True)
	for friend in range(0, k - numones):
		total += a[pointer2] + a[pointer1]
		pointer2 -= 1
		pointer1 += w[friend] - 1
	stdout.write(str(total) + '\n')


import sys
import math
from collections import defaultdict, deque
import heapq
mod = 998244353
t = int(sys.stdin.readline())
for _ in range(t):
	(n, k) = map(int, sys.stdin.readline().split())
	arr = list(map(int, sys.stdin.readline().split()))
	arr.sort()
	w = list(map(int, sys.stdin.readline().split()))
	ans = 0
	w.sort()
	(l, r) = (0, n - 1)
	lim = -1
	for i in range(k):
		if w[i] == 1:
			ans += arr[r] * 2
			r -= 1
			lim = i
		else:
			break
	for i in range(k - 1, lim, -1):
		cnt = w[i]
		ans += arr[r]
		r -= 1
		ans += arr[l]
		while cnt > 1:
			l += 1
			cnt -= 1
	print(ans)


from sys import stdin, stdout, exit
import math, cmath

def get_ints():
	return map(int, input().split())

def get_list():
	return list(map(int, input().split()))
t = int(input())
for i in range(t):
	(n, k) = get_ints()
	a = get_list()
	w = get_list()
	a.sort(reverse=True)
	w.sort()
	(iF, r, l, ans) = (k, n - 1, 0, 0)
	for i in range(k):
		if w[i] > 1:
			iF = i
			break
		ans += a[l] * 2
		l += 1
	for j in range(k - 1, iF - 1, -1):
		i = w[j]
		ans += a[l] + a[r]
		r -= i - 1
		l += 1
	print(ans)


for _ in range(int(input())):
	(n, k) = [int(c) for c in input().split()]
	arr = [int(c) for c in input().split()]
	w = [int(c) for c in input().split()]
	arr.sort()
	w.sort(reverse=True)
	ans = [0 for i in range(k)]
	j = 0
	l = -1
	for i in range(k):
		if w[i] == 1:
			continue
		else:
			ans[i] += arr[j]
			j += w[i] - 1
	w.reverse()
	for i in range(k):
		if w[i] == 1:
			ans[i] += arr[l] * 2
		else:
			ans[i] += arr[l]
		l -= 1
	print(sum(ans))


import math
import sys
input = sys.stdin.readline
t = int(input())
result = []
for cs in range(t):
	(n, k) = map(int, input().split())
	a = sorted([int(_) for _ in input().split()], reverse=True)
	w = sorted([int(_) for _ in input().split()])
	answer = 0
	for i in range(k):
		if w[i] == 1:
			answer += a[i] + a[i]
		else:
			answer += a[i]
	cur = k
	for i in range(k):
		w[i] -= 1
		if w[i] > 0:
			answer += a[cur + w[i] - 1]
			cur += w[i]
	result.append(answer)
print('\n'.join(map(str, result)))


from sys import stdin, stdout
from math import gcd, sqrt
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
N = 10 ** 6 + 7
for _ in range(I()):
	(n, k) = R()
	a = sorted(L(), reverse=True)
	v = sorted(L(), reverse=True)
	ans = 0
	l = 0
	r = -1
	for i in v[::-1]:
		if i == 1:
			ans += a[l] * 2
			l += 1
		else:
			break
	if l:
		v = v[:-l]
	for i in v:
		if i == 1:
			ans += a[l] * 2
			l += 1
		else:
			ans += a[l] + a[r]
			l += 1
			r -= 1
			for p in range(i - 2):
				r -= 1
	print(ans)


import atexit
import io
import sys
import math
from collections import defaultdict, Counter
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	w.sort()
	start1 = -1
	s = 0
	end = n - 1
	for j in range(k):
		if w[j] == 1:
			s += 2 * a[end]
			end -= 1
			start1 = j
		elif w[j] == 2:
			s += a[end] + a[end - 1]
			end -= 2
			start1 = j
		else:
			break
	start = 0
	for j in range(k - 1, start1, -1):
		flag = 0
		while w[j]:
			if flag == 0:
				ma = a[end]
				mi = a[end]
				end -= 1
				flag = 1
			elif flag == 1:
				mi = min(a[start], mi)
				start += 1
			w[j] -= 1
		s += ma + mi
	print(s)


import sys
input = sys.stdin.buffer.readline

def solution():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		l = list(map(int, input().split()))
		w = list(map(int, input().split()))
		l.sort(reverse=True)
		w.sort()
		z = []
		beg = 0
		s = 0
		for i in range(k):
			if w[i] == 1:
				s += 2 * l[beg]
				beg += 1
			else:
				z.append(w[i])
		z.sort(reverse=True)
		end = n - 1
		for i in range(len(z)):
			s += l[beg] + l[end]
			beg += 1
			end -= z[i] - 1
		print(s)
solution()


T = int(input())
for _ in range(T):
	(n, k) = map(int, input().strip().split())
	a = list(map(int, input().strip().split()))
	w = list(map(int, input().strip().split()))
	a.sort(reverse=True)
	more_than_ones = [i for i in w if i > 1]
	ones = k - len(more_than_ones)
	res = 0
	if ones > 0:
		res += sum(a[:ones]) * 2
	if len(more_than_ones) > 0:
		res += sum(a[ones:ones + len(more_than_ones)])
	a = a[ones + len(more_than_ones):]
	more_than_ones.sort()
	curr_i = 0
	for i in more_than_ones:
		curr_i += i - 1
		res += a[curr_i - 1]
	print(res)


for _ in range(int(input())):
	(n, k) = map(int, input('').split())
	A = list(map(int, input('').split()))
	w = list(map(int, input('').split()))
	w.sort()
	y = w[:]
	A.sort(reverse=True)
	num = []
	ans = 0
	for i in range(k):
		w[i] -= 1
		num.append(A[0] + 2)
		ans += A[i]
	j = 0
	i = k
	while i < len(A) and j < k:
		if w[j] > 0:
			i += w[j]
			ans += A[i - 1]
		j += 1
	for i in range(k):
		if w[i] == 0:
			ans += A[i]
	print(ans)


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return [int(i) for i in input().split()]

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True
arr = []
for _ in range(ii()):
	(n, k) = mi()
	a = sorted(li(), reverse=True)
	w = sorted(li())
	sum_ = 0
	for i in range(k):
		if w[i] == 1:
			sum_ += a[i] * 2
		else:
			sum_ += a[i]
	if w[-1] == 1:
		arr.append(sum_)
	else:
		j = k - 2
		pos = -1
		sum_ += a[pos]
		while j > -1 and w[j] != 1:
			pos -= w[j + 1] - 1
			sum_ += a[pos]
			j -= 1
		arr.append(sum_)
print(*arr, sep='\n')


import sys
import math

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
t = int(input())
for _ in range(t):
	(n, k) = get_ints()
	arr = get_array()
	w = get_array()
	arr.sort()
	ans = 0
	mxarr = []
	mnarr = [math.inf for i in range(k)]
	for i in range(n - k, n):
		ans += arr[i]
		mxarr.append(arr[i])
	for i in range(k):
		w[i] -= 1
	w.sort(reverse=True)
	lptr = 0
	for i in range(k):
		if w[i] == 0:
			break
		else:
			mnarr[i] = arr[lptr]
			lptr += w[i]
	tot_ans = 0
	for i in range(k):
		if mnarr[i] == math.inf:
			tot_ans += 2 * mxarr[i]
		else:
			tot_ans += mxarr[i] + mnarr[i]
	print(tot_ans)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from math import sqrt, floor, factorial, gcd, log
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
from math import gcd
from bisect import bisect
input = lambda : sys.stdin.readline().rstrip('\r\n')
read = lambda : list(map(int, input().strip().split(' ')))

def solve():
	for _ in range(int(input())):
		(n, k) = read()
		arr = sorted(read())
		frnds = read()
		frnds.sort()
		init = 0
		fin = n - 1
		ans = 0
		for i in frnds:
			if i == 1:
				ans += arr[fin] * 2
				fin -= 1
			else:
				ans += arr[fin]
				fin -= 1
		for i in range(k - 1, -1, -1):
			if frnds[i] > 1:
				ans += arr[init]
				init += frnds[i] - 1
		print(ans)
solve()


import sys
import math
import collections
from sys import stdin, stdout, setrecursionlimit
import bisect as bs
setrecursionlimit(2 ** 20)
M = 10 ** 9 + 7
T = int(stdin.readline())
for _ in range(T):
	(n, k) = list(map(int, stdin.readline().split()))
	a = list(map(int, stdin.readline().split()))
	w = list(map(int, stdin.readline().split()))
	o = 0
	ex = []
	ans = 0
	for i in range(k):
		if w[i] != 1:
			ex.append(w[i] - 2)
		else:
			o += 1
	a.sort()
	for i in range(o):
		ans += 2 * a[-i - 1]
	a = a[:n - o].copy()
	if len(a) == 0:
		print(ans)
		continue
	m = k - o
	for i in range(m):
		ans += a[-i - 1]
	j = 0
	ex.sort(reverse=True)
	for g in ex:
		ans += a[j]
		j += g + 1
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	w = [int(i) for i in input().split()]
	s = sorted(a)[::-1]
	w = sorted(w)
	cur = 0
	ans = 0
	for i in w:
		if i == 1:
			ans += 2 * s[cur]
		else:
			ans += s[cur]
		cur += 1
	for i in w:
		if i == 1:
			pass
		else:
			ans += s[cur + i - 2]
		cur += i - 1
	print(ans)


for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	w = [int(x) for x in input().split()]
	a.sort()
	a = a[::-1]
	w.sort()
	ksum = []
	t = k - 1
	s = 0
	for i in range(k):
		ksum.append([])
		ksum[i].append(a[i])
	for i in range(k):
		if w[i] == 1:
			ksum[i].append(a[i])
		else:
			mn = a[t + w[i] - 1]
			t += w[i] - 1
			ksum[i].append(mn)
	for i in ksum:
		s += i[0] + i[1]
	print(s)


from collections import defaultdict as dd
import math
import sys
input = sys.stdin.readline

def nn():
	return int(input())

def li():
	return list(input())

def mi():
	return map(int, input().split())

def lm():
	return list(map(int, input().split()))
q = nn()
for _ in range(q):
	(n, k) = lm()
	ints = lm()
	w = lm()
	ints.sort()
	w.sort(reverse=True)
	place = 0
	hap = 0
	nums = [[0] * w[i] for i in range(k)]
	for i in range(len(w)):
		for j in range(w[i]):
			if j == w[i] - 1:
				nums[i][j] = ints[n - k + i]
				continue
			nums[i][j] = ints[place]
			place += 1
	for num in nums:
		hap += num[0]
		hap += num[-1]
	print(hap)


t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	a = sorted([int(x) for x in input().split()])
	w = sorted([int(x) for x in input().split()])
	max_id = n - 1
	min_id = 0
	res = 0
	for i in range(k):
		res += a[max_id]
		w[i] -= 1
		if w[i] == 0:
			res += a[max_id]
		max_id -= 1
	for i in range(k - 1, -1, -1):
		if w[i] != 0:
			res += a[min_id]
			min_id += w[i]
	print(res)


from bisect import *
from collections import *
from math import *
from heapq import *
from typing import List
from itertools import *
from operator import *
from functools import *

@lru_cache(None)
def fact(x):
	if x < 2:
		return 1
	return fact(x - 1) * x

@lru_cache(None)
def per(i, j):
	return fact(i) // fact(i - j)

@lru_cache(None)
def com(i, j):
	return per(i, j) // fact(j)

def linc(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t > f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rinc(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t < f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def ldec(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t < f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rdec(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t > f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def power2(n):
	while not n & 1:
		n >>= 1
	return n == 1
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	w = list(map(int, input().split()))
	arr.sort()
	w.sort(reverse=True)
	ans = 0
	while w and w[-1] == 1:
		ans += arr.pop() * 2
		w.pop()
	mi = 0
	if w:
		ans += sum(arr[-len(w):])
	for i in range(len(w)):
		ans += arr[mi]
		mi += w[i] - 1
	print(ans)


t = int(input())
for tt in range(t):
	(n, k) = map(int, input().strip().split())
	a = list(map(int, input().strip().split()))
	w = list(map(int, input().strip().split()))
	a.sort(reverse=True)
	w.sort()
	(l, ans, ii, r) = (0, 0, k, n - 1)
	for i in range(k):
		if w[i] > 1:
			ii = i
			break
		ans = ans + a[l] * 2
		l = l + 1
	for i in range(k - 1, ii - 1, -1):
		ans = ans + a[l] + a[r]
		r = r - w[i] + 1
		l = l + 1
	print(ans)


import sys
import math
import collections

def set_debug(debug_mode=False):
	if debug_mode:
		fin = open('input.txt', 'r')
		sys.stdin = fin

def int_input():
	return list(map(int, input().split()))

def get(s):
	return str(s % 9) + '9' * (s // 9)
t = int(input())
for ti in range(1, t + 1):
	(n, k) = int_input()
	A = int_input()
	w = int_input()
	A.sort()
	w.sort()
	res = 0
	r = len(A) - 1
	l = 0
	for i in range(len(w)):
		if w[i] == 1:
			res += 2 * A[r]
			r -= 1
		else:
			break
	else:
		print(res)
		continue
	j = len(w) - 1
	while j >= i:
		res += A[l]
		res += A[r]
		r -= 1
		l += w[j] - 1
		j -= 1
	print(res)


import io, os
R = lambda : map(int, input().split())
for _ in range(int(input())):
	(n, k) = R()
	a = list(R())
	w = list(R())
	w.sort()
	a.sort(reverse=True)
	now = k
	one = 0
	ans = sum(a[:k])
	for i in w:
		if i == 1:
			ans += a[one]
			one += 1
		else:
			ans += a[now + i - 2]
			now += i - 1
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	a.sort(reverse=True)
	b.sort()
	ans = 0
	(l, r) = (0, n - 1)
	ind = k
	for i in range(k):
		if b[i] > 1:
			ind = i
			break
		ans += a[l] * 2
		l += 1
	for u in range(k - 1, ind - 1, -1):
		y = b[u]
		ans += a[l] + a[r]
		l += 1
		r -= y - 1
	print(ans)


import time, math, bisect, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IO():
	return stdin.readline()

def IP():
	return map(int, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def P(x):
	return stdout.write(str(x))

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def readTree():
	v = int(input())
	adj = [set() for i in range(v + 1)]
	for i in range(v - 1):
		(u1, u2) = In()
		adj[u1].add(u2)
		adj[u2].add(u1)
	return (adj, v)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * 1000001
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(1000001):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count

def solve():
	(n, k) = IP()
	a = L()
	w = L()
	if n == k:
		print(sum(a) * 2)
		return
	else:
		a.sort()
		li = []
		for i in range(n - 1, n - k - 1, -1):
			li.append(a.pop())
		a = a[::-1]
		w.sort()
		sm = 0
		curr = 0
		for i in range(k):
			ele = w[i]
			if ele == 1:
				sm += 2 * li[i]
			else:
				sm += li[i] + a[curr + ele - 2]
				curr = curr + ele - 1
		print(sm)
t = II()
for i in range(t):
	solve()


from collections import deque
from sys import stdin, stdout
import math
input = stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	items = list(sorted(map(int, input().split()), reverse=True))
	friends = list(sorted(map(int, input().split())))
	res = [0] * m
	for i in range(m):
		res[i] = items[i]
		if friends[i] == 1:
			res[i] *= 2
	last = m - 1
	for i in range(m):
		if friends[i] == 1:
			continue
		res[i] += items[last + friends[i] - 1]
		last += friends[i] - 1
	print(sum(res))


import sys
input = sys.stdin.readline

def solve():
	(n, k) = map(int, input().split())
	lista = list(map(int, input().split()))
	listak = list(map(int, input().split()))
	lista.sort(reverse=True)
	listak.sort()
	pi = 0
	soma = 0
	for i in range(k):
		if listak[i] == 1:
			soma += lista[pi] + lista[pi]
		else:
			soma += lista[pi]
		pi += 1
	pi -= 1
	for i in range(k):
		if listak[i] != 1:
			pi += listak[i] - 1
			soma += lista[pi]
	print(soma)
test = int(input())
while test != 0:
	solve()
	test -= 1


t = int(input())
for i in range(t):
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	w = [int(x) for x in input().split()]
	a.sort()
	w.sort()
	ans = 0
	i = count = 0
	j = n - 1
	while i != k and w[i] == 1:
		i += 1
		ans += 2 * a[j]
		j -= 1
		count += 1
	ans += sum(a[j - (k - count) + 1:j + 1])
	j = j - (k - count)
	while i != k:
		ans += a[j - w[i] + 2]
		j = j - w[i] + 1
		i += 1
	print(ans)


from collections import defaultdict, Counter, deque
from math import inf, sqrt
from functools import lru_cache
from heapq import heappop, heappush, heapify
from bisect import bisect_left, bisect_right
import sys
Mod = 10 ** 9 + 7

def solution():
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	parts = list(map(int, input().split()))
	arr.sort()
	parts.sort(reverse=True)
	(l, r) = (0, len(arr) - 1)
	res = 0
	while parts and parts[-1] == 1:
		parts.pop()
		res += 2 * arr[r]
		r -= 1
	parts = parts[::-1]
	while parts:
		val = parts.pop()
		res += arr[l]
		res += arr[r]
		r -= 1
		l += val - 2 + 1
	return print(res)

def main():
	t = 1
	t = int(input())
	for _ in range(t):
		solution()
import sys
import threading
sys.setrecursionlimit(10 ** 6)
threading.stack_size(1 << 27)
thread = threading.Thread(target=main)
thread.start()
thread.join()


for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	w = [int(i) for i in input().split()]
	a.sort()
	w.sort(reverse=True)
	ans = sum(a[n - w.count(1):]) * 2
	j = 0
	for i in range(k):
		if w[i] == 1:
			break
		ans += a[j] + a[n - k + i]
		j += w[i] - 1
	print(ans)


for t in range(int(input())):
	total = 0
	(n, k) = map(int, input().split())
	a = sorted(map(int, input().split()))
	results = [a.pop() for i in range(k)][::-1]
	ws = sorted(map(int, input().split()))
	for i in range(ws.count(1)):
		total += 2 * results.pop()
	for i in range(ws.count(2)):
		total += results.pop() + a.pop()
	a = a[::-1]
	for w in [i for i in ws[::-1] if i > 2]:
		ma = results.pop()
		mi = a.pop()
		for i in range(w - 2):
			a.pop()
		total += ma + mi
	print(total)


from sys import stdin, stdout
from bisect import bisect, bisect_left, bisect_right

def gt():
	return map(int, stdin.readline().split())

def gi():
	return int(stdin.readline())

def gl():
	return list(map(int, stdin.readline().split()))

def gs():
	return stdin.readline()
import heapq
t = gi()
for _ in range(t):
	(n, k) = gt()
	a = gl()
	w = gl()
	r = []
	w.sort()
	a.sort()
	(f, l) = (0, n - 1)
	ans = 0
	for count in w:
		if count == 1:
			ans = ans + 2 * a[l]
			l -= 1
		elif count == 2:
			ans = ans + a[l]
			l -= 1
			ans = ans + a[l]
			l -= 1
		else:
			r.append(count)
	r.sort(reverse=True)
	for count in r:
		ans = ans + a[l]
		l -= 1
		ans = ans + a[f]
		for i in range(count - 1):
			f += 1
	print(ans)


T = int(input())
for z in range(T):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	a.sort()
	w = list(map(int, input().split()))
	w.sort()
	for i in range(k):
		w[i] = w[i] - 1
	Happy = sum(a[n - k:n])
	j = 0
	Min = a[n - k:n]
	Min.reverse()
	j = n - k
	for i in range(k):
		if w[i] != 0:
			j = j - w[i]
			Min[i] = a[j]
	Happy = Happy + sum(Min)
	print(Happy)


for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	l = [int(x) for x in input().split()]
	f = [int(x) for x in input().split()]
	lr = sorted(l, reverse=True)
	f = sorted(f)
	ans = 0
	for i in range(k):
		f[i] -= 1
		ans += lr[i]
		if f[i] == 0:
			ans += lr[i]
	m = k
	for i in range(k):
		x = f[i]
		if x > 0:
			ans += lr[m + x - 1]
		m += x
	print(ans)


def solve(n, k, a, w):
	a = sorted(a, reverse=True)
	w = sorted(w)
	W = {j: [] for j in range(k)}
	j = 0
	for j in range(k):
		W[j].append(a[j])
	i = k
	for j in range(k):
		for z in range(1, w[j]):
			W[j].append(a[i])
			i += 1
	return sum([min(W[j]) + max(W[j]) for j in range(k)])
t = int(input().strip())
for _ in range(t):
	(n, k) = list(map(int, input().strip().split()))
	a = list(map(int, input().strip().split()))
	w = list(map(int, input().strip().split()))
	print(solve(n, k, a, w))


from enum import *
from copy import *
from sys import *
from collections import *
from itertools import *
from functools import *
from math import *

def l2i(fr=None):
	return map_type_to_fr(int, fr)[0]

def i2i(fr=None):
	return l2i(fr)

def dbg(*args):
	print(*args, file=stderr)

def dbv(var_name):
	print(f'{var_name} = {eval(var_name)}', file=stderr)

def map_type_to_fr(t, fr):
	global GETLINE_OFFSET
	if fr is None:
		if RUNNING_ON_MY_PC:
			fr = TEST_INP[GETLINE_OFFSET].split()
			GETLINE_OFFSET += 1
		else:
			fr = input().split()
	return list(map(t, fr))

def mis(fr=None):
	return map_type_to_fr(int, fr)

def mbs(fr=None):
	return map_type_to_fr(bool, fr)

def gs(fr=None):
	return map_type_to_fr(str, fr)[0]
import os
import sysconfig
RUNNING_ON_MY_PC = os.name == 'nt' and platform == 'win32' and (sysconfig.get_platform() == 'win-amd64')
GETLINE_OFFSET = 0
TEST_INP = '3\n4 2\n1 13 7 17\n1 3\n6 2\n10 10 10 10 11 11\n3 3\n4 4\n1000000000 1000000000 1000000000 1000000000\n1 1 1 1\n'.split('\n')

def my_r(x):
	c = ceil(x)
	if c - x > 0.5:
		return floor(x)
	return c

def cleanup(c):
	while c[-1][1] == 0:
		c.pop()
	return c
for t in range(i2i()):
	(n, k) = mis()
	a = mis()
	w = mis()
	c = deque(sorted(a))
	w = sorted(w)
	ans = 0
	curr_idx = 0
	while w[curr_idx] == 1:
		ans += c.pop() * 2
		curr_idx += 1
		if curr_idx == n:
			break
	w = w[curr_idx:][::-1]
	for needed in w:
		mx = c.pop()
		mn = mx
		left = needed - 1
		while left > 0:
			nw = c.popleft()
			mn = min(mn, nw)
			left -= 1
		ans += mx + mn
	print(ans)


import sys
import math
import heapq
from collections import defaultdict, deque
input = sys.stdin.readline

def r():
	return int(input())

def rm():
	return map(int, input().split())

def rl():
	return list(map(int, input().split()))
for _ in range(r()):
	(n, k) = rm()
	a = rl()
	b = rl()
	a.sort(reverse=True)
	b.sort()
	arra = []
	im = 0
	cnt = 0
	for i in range(k):
		arra.append(a[im])
		cnt += a[im]
		im += 1
	for (i, j) in enumerate(b):
		k = j - 1
		if k == 0:
			cnt += arra[i]
			continue
		cnt += a[im + k - 1]
		im += k
	print(cnt)


import sys
input = sys.stdin.buffer.readline
import os
from math import *
t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	brr = list(map(int, input().split()))
	brr.sort()
	ans = 0
	ip = 0
	for i in range(k):
		if brr[i] == 1:
			ans += arr[ip] + arr[ip]
			ip += 1
		else:
			break
	brr = brr[ip:]
	arr = arr[ip:]
	ip = 0
	fp = len(arr) - 1
	for i in range(len(brr) - 1, -1, -1):
		ans += arr[ip] + arr[fp]
		ip += 1
		fp -= brr[i] - 1
	print(ans)


t = int(input())
for q in range(0, t):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	a.sort()
	b = sorted(b, reverse=True)
	i = k - 1
	ans = 0
	j = n - 1
	while i >= 0:
		if b[i] != 1:
			break
		ans += 2 * a[j]
		j -= 1
		i -= 1
	l = 0
	m = 0
	while l <= i:
		ans += a[j]
		ans += a[m]
		m += b[l] - 1
		l += 1
		j -= 1
	print(ans)


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))

def solve():
	(n, k) = rl()
	A = rl()
	W = rl()
	A.sort()
	W.sort(reverse=True)
	(lo, hi) = (0, len(A) - 1)
	answer = 0
	for w in W[::-1]:
		if w != 1:
			break
		answer += 2 * A[hi]
		hi -= 1
	for w in W:
		if w == 1:
			break
		else:
			answer += A[hi] + A[lo]
			lo += w - 1
			hi -= 1
	print(answer)
mode = 'T'
if mode == 'T':
	t = ri()
	for i in range(t):
		solve()
else:
	solve()


from collections import Counter
from collections import defaultdict
from collections import deque
import math
import heapq
import sys
import io, os
input = sys.stdin.readline
from bisect import *
rs = lambda : input().strip()
ri = lambda : int(input())
rl = lambda : list(map(int, input().strip().split()))
rls = lambda : list(map(str, input().split()))
t = int(input())
for _ in range(0, t):
	(n, k) = rl()
	a = rl()
	w = rl()
	a.sort(reverse=True)
	w.sort()
	j = n - 1
	m = 0
	s = 0
	for i in range(0, len(w)):
		s = s + a[m]
		m = m + 1
		w[i] = w[i] - 1
		if w[i] == 0:
			s = s + a[m - 1]
	for i in range(len(w) - 1, -1, -1):
		if w[i] > 0:
			s = s + a[j]
			j = j - w[i]
	print(s)


import math
from bisect import bisect_left
from queue import deque
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	Int = list(map(int, input().split()))
	Dis = list(map(int, input().split()))
	Dis.sort()
	Index = -1
	for i in range(len(Dis)):
		if Dis[i] > 2:
			Index = i
			break
	if Index != -1:
		Dis = Dis[:Index] + Dis[Index:][::-1]
	Int.sort()
	Int = deque(Int)
	ans = 0
	for i in Dis:
		if i == 1:
			ans += 2 * deque.pop(Int)
		elif i == 2:
			ans += deque.pop(Int)
			ans += deque.pop(Int)
		else:
			ans += deque.pop(Int)
			ans += deque.popleft(Int)
			i -= 2
			for j in range(i):
				deque.popleft(Int)
	print(ans)


from sys import stdin
from collections import deque
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	integers = list(map(int, stdin.readline().split()))
	toeach = list(map(int, stdin.readline().split()))
	integers.sort()
	toeach.sort()
	integers = deque(integers)
	h = 0
	ind = 0
	rev = k - 1
	while integers:
		num_ints = toeach[ind]
		if num_ints == 1:
			h += 2 * integers.pop()
			ind += 1
		elif num_ints == 2:
			h += integers.pop() + integers.pop()
			ind += 1
		else:
			num_ints = toeach[rev]
			h += integers.popleft()
			h += integers.pop()
			num_ints -= 2
			while num_ints and integers:
				integers.popleft()
				num_ints -= 1
			rev -= 1
	print(h)


import sys
input = sys.stdin.readline
for f in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	w = list(map(int, input().split()))
	w.sort()
	sol = 0
	for i in range(k):
		sol += a[i]
		if w[i] == 1:
			sol += a[i]
	i = k - 1
	for wi in w:
		if wi > 1:
			i += wi - 1
			sol += a[i]
	print(sol)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l1.sort()
	l2.sort()
	ans = 0
	x = -1
	for i in range(k):
		if l2[i] == 1:
			ans += 2 * l1.pop()
		else:
			x = i
			break
	if x == -1:
		print(ans)
		continue
	cur = 0
	for i in range(k - 1, x - 1, -1):
		ans += l1.pop() + l1[cur]
		cur += l2[i] - 1
	print(ans)


def gns():
	return list(map(int, input().split()))
t = int(input())
for _ in range(t):
	(n, k) = gns()
	ns = gns()
	ks = gns()
	ns.sort(reverse=True)
	ks.sort()
	one = 0
	for i in range(k):
		if ks[i] == 1:
			one += 1
	ans = sum(ns[:k]) + sum(ns[:one])
	c = k
	for ki in ks:
		if ki == 1:
			continue
		ki -= 2
		c += ki
		ans += ns[c]
		c += 1
	print(ans)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	w.sort()
	posmin = 0
	posmax = 1
	posi = 0
	posx = 1
	sum = 0
	while posi < k and w[posi] == 1:
		sum += a[-posmax] * 2
		posmax += 1
		posi += 1
	while posi < k and w[posi] == 2:
		sum += a[-posmax] + a[-posmax - 1]
		posmax += 2
		posi += 1
	while posi <= k - posx:
		sum += a[-posmax] + a[posmin]
		posmax += 1
		posmin += w[-posx] - 1
		posx += 1
	print(sum)


import sys
from array import array
import typing as Tp

def input():
	return sys.stdin.buffer.readline().decode('utf-8')

def main():
	t = int(input())
	ans = [''] * t
	for ti in range(t):
		(n, k) = map(int, input().split())
		a = sorted(map(int, input().split()), reverse=True)
		b = sorted(map(lambda x: int(x) - 1, input().split()))
		score = sum(a[:k])
		i = k - 1
		for j in range(k):
			if b[j] == 0:
				score += a[j]
			else:
				i += b[j]
				score += a[i]
		ans[ti] = str(score)
	sys.stdout.buffer.write(('\n'.join(map(str, ans)) + '\n').encode('utf-8'))
main()


from sys import stdin
t = int(stdin.readline())
for _ in range(t):
	(n, k) = list(map(int, stdin.readline().rstrip().split(' ')))
	a = sorted(list(map(int, stdin.readline().rstrip().split(' '))), reverse=True)
	w = sorted(list(map(int, stdin.readline().rstrip().split(' '))))
	gone = 0
	answer = 0
	for i in range(k):
		current = w[i]
		answer += a[i]
		if current > 1:
			answer += a[k - 1 + current - 1 + gone]
		else:
			answer += a[i]
		gone += w[i] - 1
	print(answer)


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		(N, K) = [int(x) for x in input().split()]
		A = [int(x) for x in input().split()]
		W = [int(x) for x in input().split()]
		B = [[] for j in range(K)]
		A.sort(reverse=True)
		W.sort()
		for i in range(K):
			B[i].append(A[i])
			W[i] -= 1
		ni = 0
		for a in A[K:]:
			while W[ni] == 0:
				ni = (ni + 1) % K
			W[ni] -= 1
			B[ni].append(a)
		ans = 0
		for b in B:
			ans += min(b)
			ans += max(b)
		print(ans)
main()


for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	ss = 0
	i = 0
	j = k
	a.sort(reverse=True)
	b.sort()
	for k in b:
		ss += a[i]
		i += 1
		if k == 1:
			ss += a[i - 1]
		else:
			j += k - 1
			ss += a[j - 1]
	print(ss)


import sys
read = lambda : sys.stdin.readline()
T = int(read())
for t in range(T):
	(n, k) = map(int, read().split())
	arr = list(map(int, read().split()))
	ws = list(map(int, read().split()))
	arr.sort()
	ws.sort(reverse=True)
	n1 = 0
	for w in ws:
		if w == 1:
			n1 += 1
	l = 0
	r = n - 1 - n1
	result = sum(arr[r + 1:]) * 2
	for w in ws:
		if w == 1:
			break
		else:
			result += arr[r]
			result += arr[l]
			for i in range(w - 1):
				l += 1
			r -= 1
	print(result)


t = int(input())
for i in range(t):
	sum1 = 0
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a1 = sorted(a)
	w1 = sorted(w, reverse=True)
	y1 = w1.count(1)
	for q in range(-1, -y1 - 1, -1):
		sum1 += a1[q]
	for b in range(-1, -k - 1, -1):
		sum1 += a1[b]
	a1 = a1[0:n - k]
	w1 = [x - 1 for x in w1]
	lol = 0
	if len(a1) != 0:
		for u in range(k):
			sum1 += a1[lol]
			lol += w1[u]
			if lol == len(a1):
				break
	print(sum1)


from sys import maxsize, stdout, stdin, stderr
mod = int(1000000000.0 + 7)

def I():
	return int(stdin.readline())

def lint():
	return [int(x) for x in stdin.readline().split()]

def S():
	return input().strip()

def grid(r, c):
	return [lint() for i in range(r)]
from collections import defaultdict, Counter
import math
from itertools import groupby

def gcd(a, b):
	while b:
		a %= b
		tmp = a
		a = b
		b = tmp
	return a

def lcm(a, b):
	return a / gcd(a, b) * b

def check_prime(n):
	for i in range(2, n):
		if n % i == 0:
			return 0
	return 1
t = I()
for _ in range(t):
	(n, k) = lint()
	a = lint()
	w = lint()
	a.sort(reverse=True)
	w.sort()
	ans = 0
	ans = sum(a[:k])
	j = k - 1
	for i in range(k):
		if w[i] == 1:
			ans += a[i]
		else:
			ans += a[j - 1 + w[i]]
			j = j - 1 + w[i]
	print(ans)


for _ in range(int(input())):
	(n, p) = map(int, input().split())
	ar = list(map(int, input().split()))
	sr = list(map(int, input().split()))
	ans = 0
	ar.sort()
	sr.sort()
	ee = 0
	k = n - 1
	for m in range(p):
		if sr[m] != 1:
			break
		else:
			ee += 1
			ans += 2 * ar[k]
			k -= 1
	if ee != n - 1:
		sr = sr[ee:]
		sr.reverse()
		b = 0
		for j in sr:
			ans += ar[k]
			k -= 1
			ans += ar[b]
			b += j - 1
	print(ans)


for z in range(int(input())):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	ak = list(map(int, input().split()))
	arr.sort()
	arr = arr[::-1]
	lis = [[] for i in range(k)]
	ak.sort()
	ind = 0
	for i in range(k):
		lis[i].append(arr[ind])
		ind += 1
	for i in range(k):
		j = 1
		while j < ak[i]:
			lis[i].append(arr[ind])
			ind += 1
			j += 1
	ans = 0
	for i in range(k):
		ans += lis[i][0] + lis[i][-1]
	print(ans)


for _ in range(0, int(input())):
	(n, k) = map(int, input().split())
	integers = list(map(int, input().split()))
	weights = list(map(int, input().split()))
	integers.sort()
	weights.sort(reverse=True)
	sum = 0
	i = 0
	while weights[k - i - 1] == 1:
		sum += 2 * integers.pop()
		weights.pop()
		i += 1
		if i == k:
			break
	if i == k:
		print(sum)
		continue
	for x in range(k - i):
		sum += integers.pop()
	p = 0
	for y in range(0, k - i):
		sum += integers[p]
		p += weights[y] - 1
	print(sum)


t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	w.sort()
	w1 = []
	s = 0
	start = 0
	for j in range(k):
		if w[j] == 1:
			s += 2 * a[start]
			start += 1
		else:
			w1.append(w[j])
	finish = n - 1
	w1.sort(reverse=True)
	for j in range(len(w1)):
		s += a[start] + a[finish]
		start += 1
		finish -= w1[j] - 1
	print(s)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	w.sort()
	j = n - 1
	count = 0
	for i in range(k):
		if w[i] == 1:
			count += 2 * a[j]
			j -= 1
		else:
			break
	if w[k - 1] == 1:
		print(count)
	else:
		q = 0
		for p in range(k - 1, i - 1, -1):
			count += a[j] + a[q]
			j -= 1
			q += w[p] - 1
		print(count)


def main():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		a = list(map(int, input().split()))
		w = list(map(int, input().split()))
		a.sort()
		w.sort()
		happiness = sum(a[-k:])
		pz = 0
		while pz < k:
			if w[pz] != 1:
				break
			happiness += a[-pz - 1]
			pz += 1
		z = 0
		x = 1
		while x <= k - pz:
			happiness += a[z]
			z += w[-x] - 1
			x += 1
		print(happiness)
main()


test = int(input())
for _ in range(test):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	w = list(map(int, input().split()))
	arr.sort(reverse=True)
	w.sort()
	summ = 0
	for i in range(k):
		w[i] -= 1
		summ += arr[i]
		if w[i] == 0:
			summ += arr[i]
	j = k
	for i in range(k):
		v = w[i]
		if v > 0:
			summ += arr[j + v - 1]
		j += v
	print(summ)


import sys
from collections import deque
T = int(sys.stdin.readline())
for _ in range(T):
	(n, k) = map(int, sys.stdin.readline().split())
	list_integer = list(map(int, sys.stdin.readline().split()))
	list_friend = list(map(int, sys.stdin.readline().split()))
	res = 0
	list_integer.sort()
	list_friend.sort()
	for num in list_friend:
		if num == 1:
			res += list_integer.pop() * 2
		else:
			res += list_integer.pop()
	for num in list_friend:
		if num > 1:
			num -= 1
			while num > 1:
				list_integer.pop()
				num -= 1
			res += list_integer.pop()
	print(res)


t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a = sorted(a, reverse=True)
	w = sorted(w)
	ans = 0
	i = 0
	kw = 0
	while i < k and w[i] == 1:
		ans = ans + 2 * a[kw]
		kw += 1
		i += 1
	w = w[::-1]
	(l, r) = (kw, n - 1)
	i = 0
	while i < k and w[i] != 1:
		ans = ans + a[l] + a[r]
		l += 1
		r = r - w[i] + 1
		i += 1
	print(ans)
	t -= 1


from sys import stdin, stdout
import sys
INF = 100000000000.0
import bisect

def get_int():
	return int(stdin.readline().strip())

def get_ints():
	return map(int, stdin.readline().strip().split())

def get_array():
	return list(map(int, stdin.readline().strip().split()))

def get_string():
	return stdin.readline().strip()

def op(c):
	return stdout.write(c)
from collections import defaultdict
import math
for _ in range(int(stdin.readline())):
	(n, k) = get_ints()
	cost = get_array()
	f = get_array()
	cost.sort()
	i = 0
	j = n - 1
	total = 0
	for a in f:
		if a == 1:
			total += 2 * cost[j]
			j -= 1
	f.sort(reverse=True)
	for a in f:
		if a == 1:
			continue
		total += cost[i]
		i += a - 1
		total += cost[j]
		j -= 1
	print(total)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	w.sort(reverse=True)
	f = True
	j = k - 1
	sumi = 0
	wk = 0
	count = 0
	while f and j != -1:
		if w[j] == 1:
			sumi = sumi + 2 * a[n - wk - 1]
			wk += 1
			count += 1
		else:
			f = False
			break
		j = j - 1
	el = 0
	for j in range(0, k - count):
		sumi = sumi + a[el] + a[n - wk - 1]
		el = el + w[j] - 1
		wk += 1
	print(sumi)


t = int(input())
for q in range(t):
	res = 0
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	a = a[::-1]
	b.sort()
	for i in range(k):
		b[i] -= 1
	for i in range(k):
		res += a[i]
		if b[i] == 0:
			res += a[i]
	index = k - 1
	for i in range(k):
		index += b[i]
		if b[i] != 0:
			res += a[index]
	print(res)


t = int(input())
for i in range(t):
	nw = list(map(int, input().rstrip().split()))
	num = list(map(int, input().rstrip().split()))
	fr = list(map(int, input().rstrip().split()))
	n = nw[0]
	w = nw[1]
	sums = 0
	num.sort()
	for j in range(w):
		nm = fr[j]
		if nm == 1:
			sums += 2 * num.pop()
	fr.sort(reverse=True)
	for j in range(w):
		nm = fr[j]
		if nm == 2:
			sums += num.pop() + num[0]
			del num[0]
		elif nm > 2:
			sums += num.pop() + num[0]
			for k in range(nm - 1):
				del num[0]
	print(sums)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	w.sort()
	ans = sum(a[:k])
	idx = k - 1
	for i in range(k):
		if w[i] > 1:
			idx = i - 1
			break
		ans += a[i]
	i = n - 1
	for j in range(k - 1, idx, -1):
		ans += a[i]
		i -= w[j] - 1
	print(ans)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import sqrt, ceil, factorial, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from decimal import Decimal
from fractions import Fraction
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	(n, k) = sp()
	arr = l()
	w = l()
	w.sort()
	answer = 0
	arr.sort()
	for i in range(k):
		temp = arr.pop()
		if w[i] == 1:
			answer += temp * 2
		else:
			answer += temp
		w[i] -= 1
	for i in range(k):
		if not w[i]:
			continue
		m = inf
		for j in range(w[i]):
			m = min(m, arr.pop())
		answer += m
	out(answer)


from collections import defaultdict
tot = int(input().strip())
while tot > 0:
	l = [int(x) for x in input().strip().split(' ')]
	(n, k) = (l[0], l[1])
	a = [int(x) for x in input().strip().split(' ')]
	w = [int(x) for x in input().strip().split(' ')]
	a = sorted(a)
	w = sorted(w)
	p = len(a) - 1
	d = defaultdict(list)
	for i in range(0, len(w)):
		if w[i] > 0:
			d[i].append(a[p])
			w[i] -= 1
			p -= 1
	i = 0
	while p >= 0:
		while w[i] > 0:
			d[i].append(a[p])
			p -= 1
			w[i] -= 1
		i += 1
	ans = 0
	for v in d.values():
		ans += min(v) + max(v)
	print(ans)
	tot -= 1


testcases = int(input())
for i in range(testcases):
	(n, k) = map(int, input().split())
	gifts = list(map(int, input().split()))
	freq_of_gifts = list(map(int, input().split()))
	gifts.sort()
	freq_of_gifts.sort()
	happiness = 0
	point1 = 0
	while point1 < k:
		if freq_of_gifts[point1] != 1:
			break
		happiness += gifts.pop() * 2
		point1 += 1
	if point1 >= k:
		print(happiness)
		continue
	point2 = 0
	point3 = -1
	freq_of_gifts.reverse()
	point1 = 0
	while point1 < k:
		if freq_of_gifts[point1] == 1:
			break
		happiness += gifts[point3]
		point3 -= 1
		happiness += gifts[point2]
		point2 += freq_of_gifts[point1] - 1
		point1 += 1
	print(happiness)


for _ in range(int(input())):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	W = list(map(int, input().split()))
	W.sort(reverse=True)
	left = 0
	right = len(A) - 1
	sm = 0
	ind = len(W) - 1
	for i in range(len(A) - 1, -1, -1):
		if W[ind] != 1:
			break
		else:
			sm += 2 * A[i]
			ind -= 1
			right -= 1
	for i in range(ind + 1):
		sm += A[left] + A[right]
		left += 1
		right -= 1
		for i in range(W[i] - 2):
			left += 1
	print(sm)


from collections import defaultdict
for _ in range(int(input())):
	(N, K) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	W = list(map(int, input().split()))
	A.sort()
	W.sort()
	suma = 0
	anslist = defaultdict(list)
	check = 0
	left = 0
	right = N - 1
	for i in range(K):
		if W[i] == 1:
			check += 1
			suma += A[right] * 2
			right -= 1
	W.sort(reverse=True)
	for i in range(K):
		if W[i] == 1:
			break
		else:
			suma += A[left] + A[right]
			left += 1
			right -= 1
			left += W[i] - 2
	print(suma)


from sys import stdin, stdout

def input():
	return stdin.readline().strip()

def ans(A, W):
	A = sorted(A)[::-1]
	W_1 = 0
	W_rest = []
	for w in W:
		if w == 1:
			W_1 += 1
		else:
			W_rest += [w]
	ret = 2 * sum(A[0:W_1])
	A = A[W_1:]
	W = W_rest
	ret += sum(A[0:len(W)])
	A = A[len(W):]
	W = [w - 1 for w in W]
	W = sorted(W)[::-1]
	A = A[::-1]
	w_sum = 0
	for w in W:
		ret += A[w_sum]
		w_sum += w
	return ret
T = int(input())
for _ in range(T):
	input()
	A = input().split(' ')
	A = list(map(int, A))
	W = input().split(' ')
	W = list(map(int, W))
	print(ans(A, W))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = sorted(map(int, input().split()))[::-1]
	w = sorted(map(int, input().split()))
	f = w.count(1)
	if f == 0:
		ans = sum(s[:k])
		p = n - 1
		for i in w[::-1]:
			ans += s[p]
			p -= i - 1
	else:
		ans = sum(s[:k]) + sum(s[:f])
		p = n - 1
		for i in w[:f - 1:-1]:
			ans += s[p]
			p -= i - 1
	print(ans)


import math
T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	w = list(map(int, input().split()))
	c = w.count(1)
	w.sort()
	A.sort(reverse=True)
	Sum = 0
	for i in range(len(w)):
		if w[i] == 1:
			Sum += A[i] * 2
		else:
			Sum += A[i]
			w[i] -= 1
	A = A[len(w):]
	w = w[c:]
	count = len(A) - 1
	for i in range(len(w) - 1, -1, -1):
		Sum += A[count]
		count -= w[i]
	print(Sum)


import math

def facts(n):
	ans = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			ans.append(i)
			ans.append(n // i)
	ans = sorted(list(dict.fromkeys(ans)))
	if ans[-1] == n:
		ans = ans[:-1]
	return ans
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	nms = list(map(int, input().split()))
	ps = list(map(int, input().split()))
	nms.sort(reverse=True)
	ps.sort()
	ans = 0
	(ii, l, r) = (k, 0, n - 1)
	for i in range(k):
		if ps[i] > 1:
			ii = i
			break
		else:
			ans += nms[l] * 2
			l += 1
	for u in range(k - 1, ii - 1, -1):
		i = ps[u]
		ans += nms[l] + nms[r]
		l += 1
		r = r - i + 1
	print(ans)


from collections import deque
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	a = deque(a)
	w = list(map(int, input().split()))
	w.sort(reverse=True)
	ans = 0
	for i in range(w.count(1)):
		ans += 2 * a.popleft()
	for i in range(k - w.count(1)):
		p = a.popleft()
		ans += p
		for j in range(w[i] - 1):
			p = a.pop()
			if j == 0:
				ans += p
	print(ans)


t = int(input())
for i10 in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	s = 0
	a.sort()
	b.sort()
	l = 0
	r = n - 1
	i = 0
	d = 0
	f = True
	while d != k:
		d += 1
		if b[i] == 1:
			i += 1
			s += a[r] * 2
			r -= 1
		else:
			if f == False:
				i -= 1
			else:
				i = k - 1
			f = False
			j = b[i]
			while j != 0:
				if j == b[i]:
					s += a[r]
					r -= 1
				elif j == b[i] - 1:
					s += a[l]
					l += 1
				else:
					l += 1
				j -= 1
	print(s)


import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.buffer.readline().rstrip()
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	w = sorted(list(map(int, input().split())))
	e = 0
	for i in range(k):
		w[i] -= 1
		if w[i] == 0:
			e += 2 * a.pop()
		else:
			e += a.pop()
	a = a[::-1]
	j = -1
	for i in w:
		if i != 0:
			j += i
			e += a[j]
	print(e)


import sys
from collections import deque
pprint = lambda s: print(' '.join(map(str, s)))
input = lambda : sys.stdin.readline().strip()
ipnut = input
for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	w.sort()
	ans = 0
	d = deque()
	for i in a:
		d.append(i)
	for i in range(k):
		w[i] -= 1
		if w[i]:
			ans += d.pop()
		else:
			ans += d.pop() * 2
	w.reverse()
	j = 0
	f = True
	for i in range(k, n):
		while w[j] == 0:
			f = True
			j += 1
		w[j] -= 1
		if f:
			ans += d.popleft()
			f = False
		else:
			d.popleft()
	print(ans)


y = int(input())
ans = []
for i in range(y):
	al = input().split()
	m = list(map(int, al))
	n = m[0]
	k = m[1]
	max = 0
	al = input().split()
	num = list(map(int, al))
	al = input().split()
	f = list(map(int, al))
	num.sort()
	f.sort()
	f = f[::-1]
	max += sum(num[-k:])
	ui = 0
	for j in range(k):
		if f[j] != 1:
			max += num[ui]
		else:
			max += num[n - 1 - (k - 1 - j)]
		ui = ui + f[j] - 1
	ans.append(max)
for i in ans:
	print(i)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	p = 0
	q = 0
	r = []
	for i in w:
		if i == 1:
			p = p + 1
		elif i == 2:
			q = q + 1
		else:
			r.append(i - 1)
	c = 0
	for i in range(0, p):
		c = c + a[i]
	c = 2 * c
	f = p + 2 * q + len(r)
	for i in range(p, f):
		c = c + a[i]
	r.sort()
	s = 0
	for i in range(len(r)):
		c = c + a[f + s + r[i] - 1]
		s = s + r[i]
	print(c)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	integers = list(map(int, input().split()))
	friends = list(map(int, input().split()))
	integers.sort(reverse=True)
	friends.sort()
	ans = 0
	count1 = friends.count(1)
	ans += 2 * sum(integers[:count1])
	integers = integers[count1:]
	friends = friends[count1:]
	friends.sort(reverse=True)
	for i in range(len(friends)):
		num = friends[i]
		maxim = integers.pop(0)
		minim = maxim
		for j in range(num - 1):
			val = integers.pop(-1)
			minim = min(val, minim)
		ans += maxim + minim
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	a = a[::-1]
	w.sort()
	som = 0
	l = 0
	r = n - 1
	o = 0
	for i in w:
		if i == 1:
			x = a[l]
			som = som + x * 2
			l = l + 1
		else:
			break
	w = w[::-1]
	for i in range(0, k):
		if w[i] != 1:
			som = som + a[l] + a[r]
			l = l + 1
			r = r - w[i] + 1
	print(som)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
for _ in range(int(ri())):
	(n, k) = Ri()
	a = Ri()
	w = Ri()
	a.sort(reverse=True)
	summ = 0
	for i in range(k):
		summ += a[i]
	cur = k
	maxxcur = 0
	w = [i - 1 for i in w]
	w.sort()
	for i in range(len(w)):
		if w[i] == 0:
			summ += a[maxxcur]
			maxxcur += 1
		else:
			cur = cur + w[i] - 1
			summ += a[cur]
			cur += 1
	print(summ)


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	A.sort()
	B.sort()
	ans = sum(A[n - k:n])
	(i, j) = (n - k, 0)
	while j < k:
		if B[j] == 1:
			ans = ans + A[n - j - 1]
		else:
			a = B[j] - 1
			ans = ans + A[i - a]
			i = i - a
		j = j + 1
	print(ans)


i = int(input())
for t in range(i):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	wArr = []
	wArr = list(map(int, input().split()))
	ans = 0
	j = 0
	wArr.sort()
	for (i, z) in enumerate(wArr):
		if z == 1:
			ans += 2 * arr[i]
		else:
			ans += arr[i]
		wArr[i] -= 1
		j += 1
	j -= 1
	for (i, z) in enumerate(wArr):
		if z == 0:
			continue
		else:
			ans += arr[j + z]
		j += z
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	nlst = list(map(int, input().split()))
	klst = list(map(int, input().split()))
	snlst = sorted(nlst, reverse=True)
	sklst = sorted(klst)
	count = k - 1
	ans = 0
	ans += sum(snlst[:k])
	for i in range(k):
		if sklst[i] == 1:
			ans += snlst[i]
		else:
			ans += snlst[count + (sklst[i] - 1)]
			count += sklst[i] - 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort()
	w.sort()
	sum1 = 0
	great = n - 1
	for i in range(k):
		x = w[i]
		if x == 1:
			sum1 += 2 * a[great]
		else:
			sum1 += a[great]
		great -= 1
	x = great + 1
	for i in range(k):
		if w[i] == 1:
			continue
		else:
			x = x - (w[i] - 1)
			sum1 += a[x]
	print(sum1)


t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	inp = list(map(int, input().split()))
	kinp = list(map(int, input().split()))
	end = n - 1
	start = 0
	ans = 0
	inp.sort()
	for i in range(k):
		if kinp[i] == 1:
			ans += 2 * inp[end]
			end -= 1
	kinp.sort(reverse=True)
	for i in range(k):
		if kinp[i] != 1:
			ans += inp[start]
			start += kinp[i] - 1
			ans += inp[end]
			end -= 1
	print(ans)
	t -= 1


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	w = sorted(list(map(int, input().split())))
	ans = 0
	g = [a.pop() for i in range(k)]
	for i in range(k):
		best = g[i]
		for j in range(w[i] - 1):
			best = a.pop()
		ans += best + g[i]
	print(ans)


import sys
import math
from decimal import *

def I():
	return int(sys.stdin.readline())

def IL():
	return list(map(int, sys.stdin.readline().strip().split()))

def ILS():
	return list(map(str, sys.stdin.readline().strip().split()))

def solve():
	tt = I()
	for ii in range(tt):
		(n, k) = IL()
		l = IL()
		l.sort()
		kl = IL()
		kl.sort()
		ones = 0
		for x in kl:
			if x == 1:
				ones += 1
			else:
				break
		klst = ones
		lend = len(l) - ones
		idx = 0
		en = lend - 1
		ans = sum([2 * x for x in l[lend:]])
		for i in range(len(kl) - 1, klst - 1, -1):
			xx = kl[i] - 1
			ans += l[idx] + l[en]
			idx += xx
			en -= 1
		print(ans)
solve()


from sys import stdin
for _ in range(int(stdin.readline())):
	(n, k) = map(int, stdin.readline().split())
	arr = sorted(list(map(int, stdin.readline().split())), reverse=True)
	w = sorted(list(map(int, stdin.readline().split())))
	j = len(w)
	on = 0
	hap = sum(arr[:len(w)])
	for i in w:
		if i == 1:
			hap += arr[on]
			on += 1
		else:
			hap += arr[j + i - 2]
		j += i - 1
	print(hap)


from sys import stdin, gettrace
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def main():

	def solve():
		(n, k) = map(int, inputi().split())
		aa = [int(a) for a in inputi().split()]
		ww = [int(a) for a in inputi().split()]
		aa.sort()
		ww.sort()
		sm = 0
		apos = 0
		atop = n - 1
		wpos = 0
		w = ww[wpos]
		while w == 1:
			sm += aa[atop] * 2
			atop -= 1
			wpos += 1
			if wpos == n:
				break
			w = ww[wpos]
		for i in range(k - 1, wpos - 1, -1):
			w = ww[i]
			sm += aa[apos] + aa[atop]
			apos += w - 1
			atop -= 1
		print(sm)
	t = int(inputi())
	for _ in range(t):
		solve()
main()


import sys
sys.setrecursionlimit(10000)
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a.sort(reverse=True)
	w.sort()
	thesum = 0
	for i in a[:k]:
		thesum += i
	topgiven = 0
	newa = a[k:].copy()
	pos = -1
	for wi in w:
		if wi == 1:
			thesum += a[topgiven]
			topgiven += 1
			continue
		pos += wi - 1
		thesum += newa[pos]
	print(thesum)