#include <bits/stdc++.h>
using namespace std;
void tool() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n), w(k);
  for (long long i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  for (long long i = 0; i < k; i++) cin >> w[i];
  sort(w.begin(), w.end());
  vector<vector<long long>> ans(k, vector<long long>());
  for (long long i = 0; i < k; i++) ans[i].push_back(a[n - i - 1]);
  long long j = n - k - 1, z = 0;
  while (z < k) {
    long long i = ans[z].size();
    while (i < w[z] && j >= 0) {
      ans[z].push_back(a[j]);
      i++;
      j--;
    }
    z++;
  }
  long long res = 0;
  for (long long i = 0; i < k; i++) {
    long long mx = *max_element(ans[i].begin(), ans[i].end());
    long long mn = *min_element(ans[i].begin(), ans[i].end());
    res += (mx + mn);
  }
  cout << res << "\n";
}
int32_t main() {
  tool();
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
