#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, k;
  cin >> n >> k;
  long long int arr[n + 3];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  long long int w[k + 4];
  for (int i = 0; i < k; i++) {
    cin >> w[i];
  }
  sort(w, w + k);
  long long int final = 0;
  long long int m = 0;
  long long int str = 0;
  long long int count = 0;
  vector<long long int> res;
  for (int i = 0; i < k; i++) {
    if (w[i] == 1) {
      count++;
      continue;
    }
    res.push_back(w[i]);
  }
  sort(res.rbegin(), res.rend());
  long long int coun = n - 1;
  long long int step = 0;
  while (step < count) {
    final += arr[coun] + arr[coun];
    step++;
    coun--;
  }
  while (coun >= 0 && m < res.size()) {
    final += arr[coun] + arr[str];
    str += (res[m] - 1);
    m++;
    coun--;
  }
  cout << final << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  cin >> t;
  for (long long int i = 0; i < t; i++) {
    solve();
  }
  return 0;
}
