#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long n, k = 0, p = 0, r = 0, m, q = 0;
    cin >> n >> m;
    long long a[n], b[m];
    for (int x = 0; x < n; x++) cin >> a[x];
    for (int x = 0; x < m; x++) cin >> b[x];
    sort(b, b + m);
    sort(a, a + n);
    p = n - 1;
    r = m;
    for (int x = 0; x < m; x++) {
      if (b[x] == 1) {
        k += 2 * a[p];
        p--;
      } else {
        r = x;
        break;
      }
    }
    if (r == m) {
      cout << k << endl;
      continue;
    }
    for (int x = m - 1; x >= r; x--) {
      k += a[p] + a[q];
      p--;
      q += (b[x] - 1);
    }
    cout << k << endl;
  }
}
