#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    long long int a[n], b[k];
    for (long long int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    for (long long int i = 0; i < k; ++i) {
      cin >> b[i];
    }
    sort(a, a + n);
    sort(b, b + k);
    long long int ans = 0;
    long long int j = n - 1;
    for (long long int i = 0; i < k; ++i) {
      if (b[i] == 1) {
        ans += a[j] * 2;
        j--;
      }
    }
    long long int high = j;
    long long int low = 0;
    for (long long int i = k - 1; i >= 0; i--) {
      if (b[i] > 1) {
        ans += a[high];
        high--;
      }
    }
    high++;
    for (long long int i = 0; i < k; ++i) {
      if (b[i] > 1) {
        high = high - (b[i] - 1);
        ans += a[high];
      }
    }
    cout << ans << endl;
  }
  return 0;
}
