#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define endl '\n'
#define ll long long
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
void solve() {
ll n, m; cin >> n >> m;
vector<string> p(n);
rep(i, 0, n) cin >> p[i];
while (m-- && sz(p) > 1) {
ll j = 0;
string max1 = p[0] + p[1];
rep(i, 0, sz(p) - 1) {
string s = p[i] + p[i + 1];
if (s > max1) {
max1 = s;
j = i;
}
}
p[j] = max1;
p.erase(p.begin() + j + 1);
}
string max_ = *max_element(all(p));
cout << max_ << endl;
}
int main() {
fast;
ll t; cin >> t;
while (t--) {
solve();
}
return 0;
}