#include <bits/stdc++.h>
using namespace std;
long long a[200005];
int b[200005];
int n, k, Q;
long long ans;
int l, r;
int main() {
  scanf("%d", &Q);
  while (Q--) {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
    for (int i = 1; i <= k; i++) scanf("%d", &b[i]);
    sort(a + 1, a + 1 + n);
    sort(b + 1, b + 1 + k);
    int l, r;
    ans = 0;
    l = 1;
    r = n;
    for (int i = 1; i <= k; i++) {
      if (b[i] == 1)
        ans += a[r] + a[r];
      else
        break;
      r--;
    }
    for (int i = k; i >= 1; i--) {
      if (b[i] == 1) break;
      ans += a[l] + a[r];
      r--;
      l += b[i] - 1;
    }
    printf("%lld\n", ans);
  }
}
