#include <bits/stdc++.h>
using namespace std;
long long a, b, d[200005], c, e[200005], l, r, ans;
string n;
int main() {
  cin >> a;
  while (a--) {
    ans = 0;
    cin >> b >> c;
    l = 0, r = b - 1;
    for (int s = 0; s < b; s++) cin >> d[s];
    for (int s = 0; s < c; s++) cin >> e[s];
    sort(d, d + b);
    sort(e, e + c, greater<long long>());
    for (int s = c - 1; s >= 0; s--) {
      if (e[s] != 1) break;
      ans += 2 * d[r];
      r--;
    }
    for (int s = 0; s < c; s++) {
      if (e[s] == 1) break;
      ans += d[l] + d[r];
      r--, l += (e[s] - 1);
    }
    cout << ans << endl;
  }
}
