#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    vector<long long> nos(n, 0);
    vector<int> fr(k, 0);
    for (int i = 0; i < n; i++) cin >> nos[i];
    for (int i = 0, a; i < k; i++) {
      cin >> fr[i];
    }
    sort(nos.rbegin(), nos.rend());
    sort(fr.begin(), fr.end());
    long long ha = 0;
    int start = 0, end;
    for (int i = 0; i < k; i++) {
      if (fr[i] == 1)
        ha += 2 * nos[start];
      else
        ha += nos[start];
      start++;
      fr[i] -= 1;
    }
    for (int i = 0; i < k; i++) {
      if (fr[i] == 0) continue;
      end = start + fr[i] - 1;
      ha += nos[end];
      start = end + 1;
    }
    cout << ha << '\n';
  }
}
