#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
void solve() {
  long long int n, k;
  cin >> n >> k;
  vector<long long int> a(n);
  for (long long int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  long long int ones = 0;
  vector<long long int> b;
  for (long long int i = 0; i < k; i++) {
    long long int temp;
    cin >> temp;
    if (temp == 1)
      ones++;
    else
      b.push_back(temp);
  }
  sort(b.begin(), b.end(), greater<long long int>());
  k = b.size();
  long long int ans = accumulate(a.end() - 1 - ones + 1, a.end(), 0ll) * 2;
  long long int end = n - 1 - ones, beg = 0;
  for (long long int i = 0; i < k; i++) {
    long long int cur = b[i];
    ans += (a[end]);
    cur--;
    end--;
    if (cur == 0)
      ans += (a[end + 1]);
    else {
      ans += a[beg];
      beg += cur;
    }
  }
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int __t;
  cin >> __t;
  while (__t--) {
    solve();
    cout << "\n";
  }
  return 0;
}
