#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int qwerg = 0; qwerg < t; qwerg++) {
    int n, k;
    cin >> n >> k;
    vector<long> a(n);
    vector<int> w(k);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < k; i++) {
      cin >> w[i];
    }
    sort(a.begin(), a.end());
    sort(w.begin(), w.end());
    vector<int> delet;
    int sum = 0;
    long long answer = 0;
    for (int i = 0; i < k; i++) {
      if (w[i] == 1) {
        answer += a[n - i - 1];
        delet.push_back(i);
      }
      answer += a[n - i - 1];
    }
    for (int i = delet.size() - 1; i > -1; i--) {
      w.erase(w.begin() + delet[i]);
    }
    k = k - delet.size();
    for (int i = k - 1; i > -1; i--) {
      answer += a[sum];
      sum = sum + w[i] - 1;
    }
    cout << answer << "\n";
  }
}
