#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 2e5 + 5;
long long a[N];
int w[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= k; ++i) cin >> w[i];
    sort(a + 1, a + n + 1);
    sort(w + 1, w + k + 1, greater<int>());
    int l = 1, r = n;
    long long ans = 0;
    for (int i = k; i; --i) {
      if (w[i] > 1) break;
      ans += a[r] + a[r--];
    }
    for (int i = 1; i <= k; ++i) {
      if (w[i] == 1) break;
      ans += a[r--], w[i]--;
      ans += a[l++], w[i]--;
      while (w[i]--) {
        l++;
      }
    }
    cout << ans << "\n";
  }
}
