#include <bits/stdc++.h>
using namespace std;
// Function to return the maximum of two numeric strings
string max_num(const string& a, const string& b){
if(a.length() > b.length()) return a;
if(a.length() < b.length()) return b;
return (a > b) ? a : b;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
while(T--){
int N, K;
cin >> N >> K;
vector<string> s(N);
for(int i=0; i<N; i++) cin >> s[i];
// Initialize max_number as the first element
string max_number = s[0];
for(int i=1; i<N; i++) {
max_number = max_num(max_number, s[i]);
}
// Determine the maximum number by considering all possible concatenations
int max_m = min(K+1, N); // Maximum group size
for(int m=2; m<=max_m; m++){
for(int i=0; i + m <= N; i++){
// Concatenate elements from index i to i+m-1
string concat = "";
for(int j=i; j<i+m; j++) concat += s[j];
// Update max_number if the concatenated string is larger
max_number = max_num(max_number, concat);
}
}
cout << max_number << "\n";
}
}