#include <bits/stdc++.h>
#define ll long long
#define endll '\n';
#define pb push_back
#define all(v) v.begin(), v.end()
using namespace std;
const int mod = 1e9 + 7, N = 1e6;
void solve()
{
int n, k;
cin >> n >> k;
int mx = 0;
int ar[n + 3];
for (int i = 1; i <= n; i++)
cin >> ar[i], mx = max(ar[i], mx);
string s = to_string(mx);
for (int i = 1; i <= n; i++)
{
string x;
for (int j = i; j <= min(n, i + k); j++)
{
x += to_string(ar[j]);
}
if (x.size() > s.size())
{
s = x;
}
else if (x.size() == s.size())
{
s = max(s, x);
}
// cout << s << " " << x << endll;
}
cout << s << endll;
}
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t = 1;
cin >> t;
while (t--)
{
solve();
}
return 0;
}