#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, j, ans = 0, q = 1, k, m = 1e12, n, l, p;
  cin >> q;
  string str;
  while (q--) {
    cin >> n >> k;
    ans = 0;
    vector<long long int> arr(n);
    long long int a[k];
    for (i = 0; i < n; i++) {
      cin >> arr[i];
    }
    for (i = 0; i < k; i++) cin >> a[i];
    sort(arr.begin(), arr.end());
    sort(a, a + k);
    j = n - 1;
    for (i = 0; i < k; i++) {
      if (a[i] == 1) {
        ans += arr[j] * 2;
        j--;
      } else if (a[i] == 2) {
        ans += arr[j];
        ans += arr[j - 1];
        j = j - 2;
      } else
        break;
    }
    p = i;
    l = 0;
    for (i = 0; i < k - p; i++) {
      ans += arr[j];
      j--;
    }
    for (i = k - 1; i >= p; i--) {
      ans += arr[l];
      l += a[i] - 1;
    }
    cout << ans << endl;
  }
  return 0;
}
