#include <bits/stdc++.h>
using namespace std;
int tac, n, m;
int a[200010], b[200010];
int main() {
  scanf("%d", &tac);
  while (tac--) {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    for (int i = 0; i < m; i++) scanf("%d", &b[i]);
    sort(a, a + n), sort(b, b + m), reverse(b, b + m);
    long long res = 0;
    int t = count(b, b + m, 1);
    for (int i = n - 1; i >= n - m; i--) {
      res += a[i];
      if (i >= n - t) res += a[i];
    }
    int x = 0;
    for (int i = 0; i < m; i++) {
      if (b[i] == 1) continue;
      res += a[x];
      x += b[i] - 1;
    }
    printf("%I64d\n", res);
  }
  return 0;
}
