#include <bits/stdc++.h>
const long long inf = 0x3f3f3f3f3f3f3f3LL;
const long long mod = (long long)1e9 + 7;
using namespace std;
template <class T, class T2>
void smin(T& a, T2 val) {
  if (a > val) a = val;
}
template <class T, class T2>
void smax(T& a, T2 val) {
  if (a < val) a = val;
}
const long long N = 5 * (long long)1e5 + 10;
long long n, k;
void solve() {
  cin >> n >> k;
  vector<long long> a(n), w(k);
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (long long i = 0; i < k; ++i) {
    cin >> w[i];
  }
  sort(a.begin(), a.end());
  sort(w.begin(), w.end());
  vector<long long> mx(k, 0), mn(k, 0);
  long long ptr = 0;
  for (long long i = n - 1; i >= n - k; --i) {
    mx[ptr] = a[i];
    mn[ptr++] = a[i];
  }
  long long ans = 0;
  ptr = n - k - 1;
  for (long long i = 0; i < k; ++i) {
    long long curr = w[i] - 1;
    if (curr == 0) {
      ans += mx[i] + mn[i];
      continue;
    }
    for (long long j = ptr; j >= ptr - curr + 1; --j) {
      smin(mn[i], a[j]);
    }
    ans += mx[i] + mn[i];
    ptr -= curr;
  }
  cout << ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
    cout << '\n';
  }
  return 0;
}
