#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, M = 1e6 + 6, OO = 0x3f3f3f3f;
int tc;
long long arr[N];
int n, k, w[N];
long long mx[N], mn[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> tc;
  while (tc--) {
    priority_queue<long long> pq;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      pq.push(arr[i]);
    }
    for (int i = 0; i < k; i++) {
      cin >> w[i];
    }
    sort(w, w + k);
    sort(arr, arr + n, greater<long long>());
    int idx = 0;
    for (int i = 0; i < k; i++) {
      mx[i] = arr[idx];
      mn[i] = arr[idx++];
      w[i]--;
    }
    long long ans = 0;
    for (int i = 0; i < k; i++) {
      if (!w[i]) {
        ans += mx[i] + mn[i];
        continue;
      } else {
        idx += w[i] - 1;
        mn[i] = arr[idx];
        idx++;
      }
      ans += mx[i] + mn[i];
    }
    cout << ans << endl;
  }
  return 0;
}
