#include <bits/stdc++.h>
using namespace std;
string solve(int n, int k, vector<string>& arr) {
vector<string> current = arr;
for (int operations = 0; operations < k && n > 1; ++operations) {
string max_concat = "";
int pos = -1;
for (int i = 0; i < n - 1; ++i) {
string concat = current[i] + current[i + 1];
if (concat > max_concat) {
max_concat = concat;
pos = i;
}
}
if (pos != -1) {
current[pos] = max_concat;
current.erase(current.begin() + pos + 1);
--n;
}
}
return *max_element(current.begin(), current.end());
}
int main() {
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
vector<string> str(n);
for (int i = 0; i < n; ++i) {
cin >> str[i];
}
cout << solve(n, k, str) << endl;
}
return 0;
}