#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define nl "\n"
#define all(x) (x).begin(), (x).end()
#define Yes cout<<"Yes"<<"\n";
#define No cout<<"No"<<"\n";
using namespace std;
string concatenate(const string &a, const string &b) {
return a + b;
}
string findMaxValue(vector<string> arr, int K) {
while (K > 0) {
int n = arr.size();
int best_i = -1;
string best_val;
for (int i = 0; i < n - 1; i++) {
string combined = concatenate(arr[i], arr[i + 1]);
if (combined > best_val) {
best_val = combined;
best_i = i;
}
}
if (best_i != -1) {
arr[best_i] = best_val;
arr.erase(arr.begin() + best_i + 1);
--K;
} else {
break;
}
}
return *max_element(all(arr));
}
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];
}
cout << findMaxValue(arr, K) << nl;
}
return 0;
}