#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long T;
  cin >> T;
  while (T--) {
    long long n, k;
    cin >> n >> k;
    long long a[n], b[k];
    vector<long long> v;
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
      v.push_back(a[i]);
    }
    for (long long i = 0; i < k; i++) {
      cin >> b[i];
    }
    sort(b, b + k);
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    long long cnt = 0;
    long long ans = 0;
    long long sum = k;
    for (long long i = 0; i < k; i++) {
      if (b[i] == 1) {
        ans += v[i] + v[i];
      } else {
        sum += b[i] - 1;
        ans += v[i] + v[sum - 1];
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
