/**
* written by Binoy Barman .
**/
#include<bits/stdc++.h>
using namespace std;
#define nl '\n'
#define all(v) v.begin(), v.end()
#define Too_Many_Jobs int tts, tc = 1; cin >> tts; hell: while(tts--)
#define Dark_Lord_Binoy ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifdef LOCAL
#include "unravel.hpp"
#else
#define dbg(...) 42
#endif
#define int long long
bool check(string &a, string &b) {
if(a.length() < b.length()) return true;
if(a.length() > b.length()) return false;
for (int i = 0; i < a.length(); i++) {
if(a[i] < b[i]) return true;
else if(a[i] > b[i]) return false;
}
return false;
}
int32_t main() {
Dark_Lord_Binoy
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
Too_Many_Jobs {
int n, k;
cin >> n >> k;
vector<string> a(n);
string mx = "";
for (int i = 0; i < n; i++) {
cin >> a[i];
if(i <= k) {
for(auto c : a[i]) mx.push_back(c);
}
}
string pre = mx;
for (int i = 1; i < n; i++) {
if(i + k >= n) break;
string cur = pre;
reverse(all(cur));
for (int j = 0; j < a[i - 1].length(); j++) {
cur.pop_back();
}
reverse(all(cur));
for(auto c : a[i + k]) cur.push_back(c);
if(check(mx, cur)) swap(mx, cur);
pre = cur;
}
cout << mx << nl;
}
return 0;
}