#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 2e5 + 10;
const int MOD = 1e9 + 7;
long long TESTCASE_NUM = 1;
template <typename T>
inline void _read(T &x) {
  cin >> x;
}
inline void _read(int &x) { scanf("%d", &x); }
inline void _read(long long &x) { scanf("%lld", &x); }
inline void _read(float &x) { scanf("%f", &x); }
inline void _read(double &x) { scanf("%lf", &x); }
inline void _read(char &x) { x = getchar(); }
inline void _read(char *x) { scanf("%s", x); }
inline void read() {}
template <typename T, typename... U>
inline void read(T &head, U &...tail) {
  _read(head);
  read(tail...);
}
template <typename T>
inline void _write(const T &x) {
  cout << x;
}
inline void _write(const int &x) { printf("%d", x); }
inline void _write(const long long &x) { printf("%lld", x); }
inline void _write(const float &x) { printf("%.6f", x); }
inline void _write(const double &x) { printf("%.8lf", x); }
inline void _write(const char &x) { putchar(x); }
inline void _write(const char *x) { printf("%s", x); }
inline void write() {}
template <typename T, typename... U>
inline void write(const T &head, const U &...tail) {
  _write(head);
  write(tail...);
}
inline void debug() {}
template <typename T, typename... U>
inline void debug(const T &head, const U &...tail) {}
void solve();
template <typename T1, typename T2>
inline T1 max(T1 a, T2 b) {
  return a < b ? b : a;
}
template <typename T1, typename T2>
inline T1 min(T1 a, T2 b) {
  return a < b ? a : b;
}
template <typename T>
inline bool isprime(T p) {
  if (p == 2 || p == 3) return 1;
  if (p < 2 || (p % 6 != 1 && p % 6 != 5)) return 0;
  for (T i = 5; i * i <= p; i = i + 6)
    if (p % i == 0 || p % (i + 2) == 0) return 0;
  return 1;
}
signed main() {
  scanf("%lld\n", &TESTCASE_NUM);
  while (TESTCASE_NUM--) solve();
  return 0;
}
void solve() {
  int n, k;
  read(n, k);
  int a[n + 10], w[k + 10];
  for (int i = 1; i <= n; i++) {
    read(a[i]);
  }
  for (int i = 1; i <= k; i++) {
    read(w[i]);
    w[i]--;
  }
  sort(a + 1, a + 1 + n);
  sort(w + 1, w + 1 + k);
  long long ans = 0;
  for (int i = 0; i < k; i++) {
    ans += a[n - i];
    if (w[i + 1] == 0) {
      ans += a[n - i];
    }
  }
  int p = n - k + 1;
  for (int i = 1; i <= k; i++) {
    if (w[i] == 0) {
      continue;
    }
    p -= w[i];
    ans += a[p];
  }
  write(ans, '\n');
}
