#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    vector<int> v;
    vector<int> f;
    long long happy = 0;
    for (long long i = 0; i < n; i++) {
      long long x;
      cin >> x;
      v.push_back(x);
    }
    for (long long i = 0; i < k; i++) {
      long long x;
      cin >> x;
      f.push_back(x);
    }
    long long count_zero = 0;
    for (long long i = 0; i < k; i++)
      if (f[i] == 1) count_zero++;
    sort(v.begin(), v.end());
    for (long long i = 0; i < count_zero; i++) happy += (v[n - i - 1] * 2);
    sort(f.begin(), f.end(), greater<int>());
    long long start = 0;
    long long end = n - count_zero - 1;
    for (long long i = 0; i < k; i++) {
      if (f[i] == 1) break;
      happy += (v[start] + v[end]);
      end--;
      start += (f[i] - 1);
    }
    v.clear();
    f.clear();
    cout << happy << endl;
  }
  return 0;
}
