#include<bits/stdc++.h>
using namespace std;
string concatenate_max(string &a, string &b) {
return (a + b );
}
int main() {
int T;
cin >> T;
while (T--) {
int N, K;
cin >> N >> K;
vector<string> arr(N);
for (int i = 0; i < N; i++) {
cin >> arr[i];
}
for (int i = 0; i < K && arr.size() > 1; i++) {
string max_concat = "";
int index = 0;
for (int j = 0; j < arr.size() - 1; j++) {
string concatenated = concatenate_max(arr[j], arr[j + 1]);
if (concatenated > max_concat) {
max_concat = concatenated;
index = j;
}
}
arr[index] = max_concat;
arr.erase(arr.begin() + index + 1);
}
string result = arr[0];
for (int i = 1; i < arr.size(); i++) {
//cout << arr[i] << " ";
result = concatenate_max(result, arr[i]);
}
cout << arr[K] << endl;
}
return 0;
}