#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const double eps = 1e-7;
int a[N], w[N];
int main() {
  int _;
  scanf("%d", &_);
  while (_--) {
    int n, k;
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    sort(a + 1, a + n + 1);
    int c = 0;
    ll ans = 0;
    for (int i = 1; i <= k; ++i) {
      scanf("%d", &w[i]);
      if (w[i] == 1) c++;
    }
    sort(w + 1, w + k + 1);
    int x = c;
    int start = 1, end = n;
    while (c--) {
      ans += 1ll * 2 * a[end--];
    }
    for (int i = k; i > x; --i) {
      ans += 1ll * (a[start] + a[end]);
      end--;
      start += (w[i] - 1);
    }
    cout << ans << '\n';
  }
  return 0;
}
