#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll, ll>;
using um = unordered_map<ll, ll>;
template <typename T>
inline void prt(T v) {
  cout << v << '\n';
}
template <typename T>
inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ld pi = 3.14159265358979323846;
const ld eps = 1e-10;
signed main(void) {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  ll t;
  cin >> t;
  for (ll i = 0; i < t; ++i) {
    ll n;
    cin >> n;
    ll k;
    cin >> k;
    vector<ll> a(n, 0);
    for (ll i = 0; i < n; ++i) cin >> a[i];
    vector<ll> w(k, 0);
    for (ll i = 0; i < k; ++i) cin >> w[i];
    sort(a.begin(), a.end());
    sort(w.rbegin(), w.rend());
    ll ans = 0;
    ll mark = 0;
    for (ll i = 0; i < k; ++i) {
      if (w[i] == 1) break;
      ans += a[mark];
      mark += w[i] - 1;
    }
    for (ll i = n - k; i < n; ++i) ans += a[i];
    ll count = 0;
    for (auto p : w)
      if (p == 1) count++;
    for (ll i = n - 1; i >= n - count; --i) ans += a[i];
    prt(ans);
  }
  cout << flush;
  return 0;
}
