#include <bits/stdc++.h>
using namespace std;
const long long mod1 = 1e9 + 7;
const long long mod2 = 998244353;
const int INF = 0x3f3f3f3f;
int t, n, k;
long long a[200005], w[200005], ans;
bool cmp(long long x, long long y) { return x > y; }
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> k;
    ans = 0;
    for (int i = 1; i <= n; i++) cin >> a[i];
    sort(a + 1, a + 1 + n);
    for (int i = 1; i <= k; i++) cin >> w[i];
    sort(w + 1, w + 1 + k);
    int cot = 0;
    for (int i = 1; i <= k; i++) {
      if (w[i] == 1) {
        cot++;
      }
    }
    for (int i = 1; i <= k; i++) {
      if (cot) {
        ans += a[n - i + 1] * 2;
        cot--;
      } else {
        ans += a[n - i + 1];
      }
      w[i]--;
    }
    sort(w + 1, w + 1 + k, cmp);
    int tep = 1;
    int pos = 1;
    while (w[tep] != 0 && pos <= n - k) {
      ans += a[pos];
      pos += w[tep];
      tep++;
    }
    cout << ans << endl;
  }
  return 0;
}
