#include<bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t; cin >> t;
while (t--) {
int n, k; cin >> n >> k;
vector <int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
vector <int> v1;
vector <int> v2;
for (int i = 0; i < k; i++) v1.push_back(a[i]);
for (int i = k; i < n; i++) v2.push_back(a[i]);
int mx = -1e5 + 7;
int mx_idx = 0;
int mn = 1e5 + 7;
int mn_idx = 0;
sort (v1.rbegin(), v1.rend());
sort (v2.begin(), v2.end());
int sz = min(v1.size(), v2.size());
for (int i = 0; i < sz; i++) {
if (v1[i] > v2[i]) swap (v1[i], v2[i]);
}
long long sum = 0;
for (int i = 0; i < k; i++) sum += v1[i];
cout << sum << '\n';
}
}