#include <bits/stdc++.h>
using namespace std;
long long int solve() {
  long long int n, k;
  cin >> n >> k;
  long long int a[n];
  for (long long int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  reverse(a, a + n);
  long long int w[k];
  for (long long int i = 0; i < k; i++) cin >> w[i];
  sort(w, w + k);
  long long int sum = 0;
  for (long long int i = 0; i < k; i++) {
    if (w[i] == 1)
      sum = sum + a[i] * 2;
    else
      sum = sum + a[i];
    w[i]--;
  }
  long long int j = 0;
  for (long long int i = k; i < n;) {
    if (w[j] == 0) {
      j++;
      continue;
    }
    long long int mini = a[i];
    long long int c = 1;
    i++;
    while (c < w[j]) {
      mini = min(mini, a[i]);
      i++;
      c++;
    }
    j++;
    sum = sum + mini;
  }
  cout << sum << endl;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
