#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long n, k;
    cin >> n >> k;
    vector<long long> arr;
    long long sum = 0;
    vector<long> w;
    long long temp;
    for (int i = 0; i < n; i++) {
      cin >> temp;
      arr.push_back(temp);
    }
    for (int i = 0; i < k; i++) {
      cin >> temp;
      w.push_back(temp);
    }
    sort(arr.begin(), arr.end());
    sort(w.begin(), w.end());
    int i = 0;
    int j = n - 1, j1 = 0;
    while (i < k && w[i] == 1) {
      sum = sum + (2 * arr[j]);
      j--;
      i++;
    }
    int i1 = k - 1;
    while (i1 >= i) {
      sum = sum + arr[j] + arr[j1];
      j--;
      j1 = j1 + w[i1] - 1;
      i1--;
    }
    cout << sum << "\n";
  }
}
