#include <bits/stdc++.h>
using namespace std;
int 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 arr[n], w[k];
    for (int i = 0; i < n; i++) cin >> arr[i];
    for (int i = 0; i < k; i++) cin >> w[i];
    sort(arr, arr + n);
    sort(w, w + k);
    long long int j = n - 1, s = 0, p = 0, sum = 0;
    while (p < k && w[p] == 1) sum += 2 * arr[j], j--, p++;
    for (int i = k - 1; i >= p; i--) {
      sum += arr[j] + arr[s];
      j--, s++;
      w[i] -= 2;
      while (w[i] != 0) s++, w[i] -= 1;
    }
    cout << sum << "\n";
  }
  return 0;
}
