#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, k, p = 0;
    cin >> n >> k;
    long long int a[n], w[k];
    for (long long int i = 0; i < n; i++) cin >> a[i];
    for (long long int i = 0; i < k; i++) cin >> w[i];
    sort(a, a + n);
    sort(w, w + k);
    long long int ans = 0;
    p = n - 1;
    for (long long int i = 0; i < k; i++) {
      ans += a[p];
      if (w[i] == 1) ans += a[p];
      p--;
    }
    p++;
    for (long long int i = 0; i < k; i++) {
      if (w[i] == 1) continue;
      w[i]--;
      p -= w[i];
      ans += a[p];
    }
    cout << ans << endl;
  }
}
