#include <bits/stdc++.h>
using namespace std;
string solve(vector<string>& arr, int K) {
while (K-- > 0 && arr.size() > 1) {
int idx = -1;
string maxConcat = "";
for (int i = 0; i < arr.size() - 1; i++) {
string concat = arr[i] + arr[i + 1];
if (concat > maxConcat) {
maxConcat = concat;
idx = i;
}
}
arr[idx] = maxConcat;
arr.erase(arr.begin() + idx + 1);
}
return *max_element(arr.begin(), arr.end());
}
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 << solve(arr, K) << endl;
}
return 0;
}