#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
long long A[MAXN];
long long B[MAXN];
long long M[MAXN];
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int T;
  cin >> T;
  while (T--) {
    int N, K;
    cin >> N >> K;
    for (int i = 1; i <= N; i++) cin >> A[i];
    sort(A + 1, A + N + 1, greater<long long>());
    for (int i = 1; i <= K; i++) M[i] = A[i];
    for (int i = 1; i <= K; i++) cin >> B[i];
    sort(B + 1, B + K + 1);
    int pos = K + 1;
    long long sum = 0;
    for (int i = 1; i <= K; i++) {
      if (B[i] == 1)
        sum += 2ll * M[i];
      else {
        B[i]--;
        while (B[i] > 1) B[i]--, pos++;
        sum += M[i] + A[pos++];
      }
    }
    cout << sum << '\n';
  }
  return 0;
}
