#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int k;
    cin >> k;
    vector<int> v(n);
    vector<int> v1(k);
    for (int i = 0; i < n; i++) {
      cin >> v[i];
    }
    for (int i = 0; i < k; i++) {
      cin >> v1[i];
    }
    sort(v.begin(), v.end());
    sort(v1.begin(), v1.end());
    long long int sum = 0;
    int r = n - 1;
    int i = 0;
    int l = 0;
    while (v1[i] == 1 && i < k) {
      sum += 2 * v[r];
      r--;
      i++;
    }
    i = k - 1;
    while (v1[i] != 1 && i >= 0) {
      sum += v[r];
      sum += v[l];
      r--;
      l++;
      l += v1[i] - 2;
      i--;
    }
    cout << sum << endl;
  }
  return 0;
}
