#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
void solve() {
  long long n, k;
  cin >> n >> k;
  long long a[n];
  long long s = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  long long p[k];
  for (long long i = 0; i < k; i++) cin >> p[i];
  long long l = 0, r = n - 1;
  sort(p, p + k);
  long long x = 0;
  long long i = 0;
  while (p[i] == 1) {
    s += (a[r] * 2);
    i++;
    r--;
    x++;
  }
  for (long long i = k - 1; i >= x; i--) {
    long long xx = p[i];
    s += a[r];
    xx--;
    if (xx > 0)
      s += a[l];
    else
      s += a[r];
    r--;
    while (xx--) l++;
  }
  cout << s << endl;
}
int32_t main() {
  long long T;
  cin >> T;
  while (T--) solve();
}
