#include <bits/stdc++.h>
const long long mod = 1e9 + 7;
using namespace std;
int main() {
  int T;
  cin >> T;
  for (int t = 0; t < T; t++) {
    int n, k;
    cin >> n >> k;
    vector<int> a(n, 0);
    for (auto& it : a) {
      cin >> it;
    }
    vector<int> w(k, 0);
    for (auto& it : w) {
      cin >> it;
    }
    long long result = 0;
    priority_queue<int> numbers_highest;
    priority_queue<int, vector<int>, greater<int>> weights_lowest;
    priority_queue<int> weights_highest;
    priority_queue<int, vector<int>, greater<int>> numbers_lowest;
    for (auto& it : a) {
      numbers_highest.push(it);
    }
    for (auto& it : w) {
      weights_lowest.push(it);
    }
    while (!weights_lowest.empty()) {
      int t = weights_lowest.top();
      weights_lowest.pop();
      int p = numbers_highest.top();
      numbers_highest.pop();
      result += (long long)p;
      if (t != 1) {
        weights_highest.push(t - 1);
      } else {
        result += (long long)p;
      }
    }
    while (!numbers_highest.empty()) {
      int t = numbers_highest.top();
      numbers_lowest.push(t);
      numbers_highest.pop();
    }
    while (!weights_highest.empty()) {
      int t = weights_highest.top();
      weights_highest.pop();
      int p = numbers_lowest.top();
      result += (long long)p;
      while (t--) {
        numbers_lowest.pop();
      }
    }
    cout << result << endl;
  }
  return 0;
}
