#include <bits/stdc++.h>
using namespace std;
int t;
string s;
long long arr[400005], brr[400005];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    for (long long i = 0; i < n; i++) cin >> arr[i];
    sort(arr, arr + n, greater<int>());
    for (long long i = 0; i < k; i++) cin >> brr[i];
    sort(brr, brr + k);
    long long ans = 0, idx = 0;
    for (long long i = 0; i < k; i++) {
      brr[i]--;
      ans += arr[i];
      if (brr[i] == 0) ans += arr[i];
    }
    sort(arr, arr + n);
    for (long long i = k - 1; i >= 0; i--) {
      if (brr[i] == 0) break;
      ans += arr[idx];
      idx += brr[i];
    }
    cout << ans << endl;
  }
  return 0;
}
