#include <bits/stdc++.h>
using namespace std;
void test() {
  long long n, k;
  cin >> n >> k;
  long long a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  long long w[k];
  for (int i = 0; i < k; i++) cin >> w[i];
  sort(w, w + k);
  sort(a, a + n);
  reverse(a, a + n);
  long long sum = 0;
  int start = 0, end = n - 1;
  int i = 0;
  while (i < k and w[i] == 1) {
    sum = sum + a[start] * 2LL;
    start++;
    i++;
  }
  for (int j = k - 1; j >= i; j--) {
    if (w[j] == 2) {
      sum = sum + a[start];
      start++;
      sum = sum + a[start];
      start++;
    } else {
      sum = sum + a[start] + a[end];
      start++;
      end--;
      w[j] = w[j] - 2;
      end = end - w[j];
    }
  }
  cout << sum << "\n";
}
int main() {
  int tests = 1;
  cin >> tests;
  while (tests--) {
    test();
  }
}
