#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
int T;
cin >> T;
while(T--){
long long N, M;
cin >> N >> M;
long long total = N * M;
vector<long long> A(total);
for(auto &x: A) cin >> x;
// Sort all elements in ascending order
sort(A.begin(), A.end());
// Determine the sizes of Set A and Set B
long long A_size = (total + 1) / 2; // ceil(N*M / 2)
long long B_size = total / 2; // floor(N*M / 2)
// Assign the largest A_size elements to Set A
// and the next largest B_size elements to Set B
// Since A is sorted in ascending order:
// Set A: last A_size elements
// Set B: next B_size elements
long long min_A = A[total - A_size];
long long min_B;
if(B_size > 0){
min_B = A[total - A_size - B_size];
}
else{
// If B_size is 0, there are no elements in Set B
// Depending on problem constraints, set B_sum appropriately
// Here, assuming B_sum is 0 if Set B is empty
min_B = 0;
}
// Calculate the minimal sum S
long long S = min_A + min_B;
// Output the result
cout << S << "\n";
}
}