#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
using namespace std;
clock_t start_time, end_time;
void open() {
  ((void)0);
  ((void)0);
  ((void)0);
  ((void)0);
}
void close() {
  ((void)0);
  ((void)0);
}
const int MAX = 2e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3fLL;
const double PI = acos(-1);
const long double ERR = 1e-10;
const int move_r[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int move_c[] = {0, -1, 0, 1, -1, 1, -1, 1};
int t, n, k, a[MAX], w[MAX];
int main(int argc, char *argv[]) {
  open();
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; ++i) scanf("%d", a + i);
    for (int i = 0; i < k; ++i) scanf("%d", w + i);
    sort(a, a + n);
    sort(w, w + k);
    int lo = 0, hi = n - 1, sep = 0;
    long long ans = 0;
    for (sep = 0; sep < k; ++sep) {
      if (w[sep] > 1) break;
      ans += 2LL * a[hi--];
    }
    for (int i = k - 1; i >= sep; --i) {
      ans += a[hi--] + a[lo];
      for (int j = 1; j < w[i]; ++j) ++lo;
    }
    printf("%lld\n", ans);
  }
  close();
  return 0;
}
