#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n);
  multiset<long long> s;
  for (long long& i : a) cin >> i;
  sort(a.rbegin(), a.rend());
  vector<int> w(k);
  for (int& i : w) cin >> i;
  sort(w.begin(), w.end());
  int on = 0;
  for (int i : w)
    if (i == 1) on++;
  long long sum = 0;
  int t = on;
  for (int i = 0; i < k; i++) {
    if (t) {
      sum += a[i] * 2, t--;
    } else
      sum += a[i];
  }
  int point = n - 1;
  sort(w.rbegin(), w.rend());
  for (int i : w) {
    if (i > 1) {
      sum += a[point];
      for (int j = 0; j < i - 1; j++) point--;
    }
  }
  cout << sum;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
}
