#include <bits/stdc++.h>
#pragma optimize("O3")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void dout() { cerr << "\n"; }
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
  cerr << H << ' ';
  dout(T...);
}
void solve() {
  int n, k;
  cin >> n >> k;
  long long a[n + 11], w[k + 11], mn[k + 11], mx[k + 11];
  for (int i = (1); i < (n + 1); i++) {
    cin >> a[i];
  }
  for (int i = (1); i < (k + 1); i++) {
    cin >> w[i];
  }
  sort(a + 1, a + 1 + n);
  sort(w + 1, w + 1 + k);
  int p = n;
  fill(mn, mn + k + 1, 1e15);
  fill(mx, mx + k + 1, -1e15);
  for (int i = (1); i < (k + 1); i++) {
    if (w[i] > 0) {
      mn[i] = min(mn[i], a[p]);
      mx[i] = max(mx[i], a[p]);
      w[i]--;
      p--;
    }
  }
  long long x = 1;
  for (long long i = k; i >= 1; i--) {
    while (w[i] > 0) {
      mn[i] = min(mn[i], a[x]);
      mx[i] = max(mx[i], a[x]);
      w[i]--;
      x++;
    }
  }
  long long res = 0;
  for (int i = (1); i < (k + 1); i++) {
    res += mn[i] + mx[i];
  }
  cout << res << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  for (int i = (0); i < (t); i++) {
    solve();
  }
  cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << "\n";
  return 0;
}
