#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(A.begin(), A.end());
// Determine 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)
// Smallest in Set A is the first element of the last A_size elements
long long min_A = A[total - A_size];
// Smallest in Set B is the first element
long long min_B = A[0];
long long minimal_sum = min_A + min_B;
cout << minimal_sum << "\n";
}
}