#include <bits/stdc++.h>
using namespace std;
priority_queue<long long> cancel;
long long arr[200005];
long long brr[200005];
int main() {
  long long test;
  cin >> test;
  for (long long z = 0; z < test; z++) {
    long long n, m, k;
    cin >> n >> k;
    for (long long i = 0; i < n; i++) {
      cin >> arr[i];
    }
    for (long long i = 0; i < k; i++) {
      cin >> brr[i];
    }
    sort(brr, brr + k);
    sort(arr, arr + n);
    long long i = 0;
    long long j = n - 1;
    long long sum = 0;
    while ((brr[i] == 1) && (i < k)) {
      sum += 2 * arr[j];
      i++;
      j--;
    }
    while ((brr[i] == 2) && (i < k)) {
      sum += arr[j--];
      sum += arr[j--];
      i++;
    }
    long long p = 0;
    long long te = k - 1;
    while (te >= i) {
      sum += arr[p] + arr[j--];
      p += brr[te] - 1;
      te--;
    }
    cout << sum << endl;
  }
}
