#include <bits/stdc++.h>
#pragma warning(disable : 4996)
const long long MOD = 1000000007;
using namespace std;
void solve() {
  int n, K;
  scanf("%d%d", &n, &K);
  vector<int> a(n), w(K);
  int i, j;
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a.rbegin(), a.rend());
  for (i = 0; i < K; i++) {
    scanf("%d", &w[i]);
  }
  sort(w.begin(), w.end());
  long long s = 0;
  int curr = 0;
  for (i = 0; i < K; i++) {
    s += a[i];
    if (w[i] == 1) {
      s += a[i];
    }
  }
  curr = K - 1;
  for (i = 0; i < K; i++) {
    if (w[i] == 1) continue;
    curr += (w[i] - 1);
    s += a[curr];
  }
  printf("%lld\n", s);
  return;
}
int main(int argc, char* argv[]) {
  int T;
  scanf("%d", &T);
  int t;
  for (t = 0; t < T; t++) {
    solve();
  }
  return 0;
}
