#include <bits/stdc++.h>
using namespace std;
inline long long lowbit(long long x) { return x & (-x); }
inline long long min(long long a, long long b) { return a < b ? a : b; }
inline long long max(long long a, long long b) { return a > b ? a : b; }
const long long INF = 0x3f3f3f3f, max_n = 200050, mod = 19260817;
inline long long gcd(long long a, long long b) {
  return b == 0 ? a : gcd(b, a % b);
}
inline long long pow(long long a, long long b, long long mod) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long ans[max_n];
long long n, k;
long long a[max_n];
long long w[max_n];
long long ans1;
long long le;
long long yi;
bool cmp(long long a, long long b) { return a > b; }
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    ans1 = 0;
    yi = 0;
    le = 1;
    cin >> n >> k;
    for (long long i = 1; i <= n; i++) {
      cin >> a[i];
    }
    for (long long i = 1; i <= k; i++) {
      cin >> w[i];
      if (w[i] == 1) {
        yi++;
        w[i] = 0;
      }
    }
    sort(a + 1, a + 1 + n);
    long long r = n;
    for (long long i = 1; i <= yi; i++) {
      ans1 += a[r--] * 2;
    }
    sort(w + 1, w + 1 + k, cmp);
    long long le = 1;
    for (long long i = 1; i <= k; i++) {
      if (w[i] == 0) break;
      ans[i] += a[r--];
      w[i]--;
      if (w[i]) {
        ans[i] += a[le];
        w[i]--;
        le += w[i] + 1;
      } else {
        ans[i] += a[r--];
      }
    }
    for (long long i = 1; i <= k; i++) {
      ans1 += ans[i];
    }
    cout << ans1 << '\n';
    memset(ans, 0, sizeof(ans));
  }
}
