#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int t, n, k, a[N], w[N];
long long ans;
void solve(void);
int main(void) {
  scanf("%d", &t);
  while (t--) solve();
  return 0;
}
void solve(void) {
  scanf("%d%d", &n, &k), ans = 0;
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 1; i <= k; i++) scanf("%d", w + i);
  sort(a + 1, a + n + 1), sort(w + 1, w + k + 1), reverse(w + 1, w + k + 1);
  for (; w[k] == 1; k--) ans += 2 * a[n--];
  for (int i = 1, j = 1; j <= k; i += w[j] - 1, j++) ans += a[i] + a[n--];
  printf("%lld\n", ans);
}
