------
## 最终结论
```python
def max_happiness(t, test_cases):
    results = []
    for case in test_cases:
        n, k, a, w = case
        a.sort()
        w.sort(reverse=True)

        happiness = 0
        left_index = 0
        right_index = n - 1

        # Allocate friends who will get only one integer first
        for i in range(k):
            if w[i] == 1:
                happiness += 2 * a[right_index]
                right_index -= 1

        # Allocate remaining friends
        for i in range(k):
            if w[i] > 1:
                happiness += a[right_index] + a[left_index]
                left_index += (w[i] - 1)
                right_index -= 1

        results.append(happiness)
    return results


# Read input data
import sys
input = sys.stdin.read
data = input().split()

t = int(data[0])
index = 1
test_cases = []

for _ in range(t):
    n, k = int(data[index]), int(data[index + 1])
    index += 2
    a = list(map(int, data[index:index + n]))
    index += n
    w = list(map(int, data[index:index + k]))
    index += k
    test_cases.append((n, k, a, w))

# Get the result and print it
results = max_happiness(t, test_cases)
for result in results:
    print(result)
```