#include<bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    const unsigned int Mod = 1000000007;
    int testCases;
    cin >> testCases;

    for(int t=0; t<testCases; t++){
    long long x, l = 0;
    cin >> x;
    string s;
    cin >> s;
    long long length = s.length();
    //cout << length << "\n";

    for(long long times=0; times<x; times++)
    {
        long long index = s.length() - 1;
        long long limit = (s[times] - '0') - 1;
        long long stringLength = s.length();

        while(limit--)
        {
            for(long long i=times+1; i<stringLength; i++)
            {
                s += s[i];
                index++;
                if(index >= x - 1)
                {
                    break;
                }
            }
            if(index >= x - 1)
            {
                break;
            }
        }
        if(index >= x - 1)
        {
            //cout << index << " index\n";
            break;
        }
    }

    for(long long j=0; j<x; j++)
    {
        //cout << length << " + (" << length << " - " << j + 1 << ") x ( " << s[j] << " - 1) = ";
        length += ((((length - j - 1) % Mod) % Mod) * ((((s[j] - '0') - 1) % Mod) % Mod));
        length %= Mod;
        //cout << length << "\n";
    }
    cout << length << "\n";}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    const unsigned int Mod = 1000000007;
    int testCases;
    cin >> testCases;

    for(int t=0; t<testCases; t++){
    long long x, l = 0;
    cin >> x;
    char s[100000];
    cin >> s;
    long long length = strlen(s);
    //cout << length << "\n";

    for(long long times=0; times<x; times++)
    {
        l++;
        char temp[100000];
        long long temp_index = -1;
        long long limit = s[times] - '0';
        for(long long i=times+1; i<strlen(s); i++)
        {
            temp[++temp_index] = s[i];
            //cout << "inserted in c\n";
        }
        temp[temp_index + 1] = '\0';
        //cout << temp << " " << c << "\n";
        //cout << temp_index << " " << c_index << "\n";
        /*for(int i=0; i<=temp_index; i++)
        {
            cout << temp[i];
            //cout << "here temp";
        }
        cout << " ";
        for(int i=0; i<=c_index; i++)
        {
            cout << c[i];
            //cout << "here c";
        }
        cout << "\n";*/
        for(long long i=0; i<limit-1 ; i++)
        {
            strcat(s, temp);
        }
        //strcat(temp, c);
        //strcat(temp, c);
        //strcat(temp, c);
        //cout << sl << "\n";
        /*for(int i=0; i<=temp_index; i++)
        {
            cout << temp[i];
            //cout << "here temp";
        }
        cout << "\n";*/
        //cout << temp << "\n";
        //length = temp_index + 1;
        //cout << s << "\n";
        //cout << temp_index << "\n";
        if(strlen(s) >= x)
        {
            break;
        }
    }
    //cout << s << "\n" << strlen(s) << "\n";
    for(long long j=0; j<x; j++)
    {
        //cout << length << " + (" << length << " - " << j + 1 << ") x ( " << s[j] << " - 1) = ";
        length += (((length - j - 1) % Mod) * (((s[j] - '0') - 1) % Mod));
        length %= Mod;
        //cout << length << "\n";
    }
    cout << length << "\n";}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    const unsigned int Mod = 1000000007;
    int testCases;
    cin >> testCases;

    for(int t=0; t<testCases; t++){
    long long x, l = 0;
    cin >> x;
    char s[100000];
    cin >> s;
    long long length = strlen(s);
    //cout << length << "\n";

    for(long long times=0; times<x; times++)
    {
        l++;
        char c[100000], temp[100000];
        long long c_index = -1, temp_index = -1;
        for(long long i=0; i<l; i++)
        {
            temp[++temp_index] = s[i];
            //cout << "inserted in temp\n";
        }
        for(long long i=l; i<strlen(s); i++)
        {
            c[++c_index] = s[i];
            //cout << "inserted in c\n";
        }
        temp[temp_index + 1] = '\0';
        c[c_index + 1] = '\0';
        //cout << temp << " " << c << "\n";
        //cout << temp_index << " " << c_index << "\n";
        /*for(int i=0; i<=temp_index; i++)
        {
            cout << temp[i];
            //cout << "here temp";
        }
        cout << " ";
        for(int i=0; i<=c_index; i++)
        {
            cout << c[i];
            //cout << "here c";
        }
        cout << "\n";*/
        long long sl = temp[temp_index] - '0';
        for(long long i=0; i<sl; i++)
        {
            strcat(temp, c);
            temp_index += (c_index + 1);
        }
        //strcat(temp, c);
        //strcat(temp, c);
        //strcat(temp, c);
        //cout << sl << "\n";
        /*for(int i=0; i<=temp_index; i++)
        {
            cout << temp[i];
            //cout << "here temp";
        }
        cout << "\n";*/
        temp[temp_index + 1] = '\0';
        //cout << temp << "\n";
        strcpy(s, temp);
        //length = temp_index + 1;
        //cout << s << "\n";
        //cout << temp_index << "\n";
        if(temp_index + 1 >= x)
        {
            break;
        }
    }
    //cout << s << "\n" << strlen(s) << "\n";
    for(long long j=0; j<x; j++)
    {
        //cout << length << " + (" << length << " - " << j + 1 << ") x ( " << s[j] << " - 1) = ";
        length += (((length - j - 1) % Mod) * (((s[j] - '0') - 1) % Mod));
        length %= Mod;
        //cout << length << "\n";
    }
    cout << length << "\n";}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    const unsigned int Mod = 1000000007;
    int testCases;
    cin >> testCases;

    for(int t=0; t<testCases; t++){
    long long x, l = 0;
    cin >> x;
    char s[100000];
    cin >> s;
    long long length = strlen(s);
    //cout << length << "\n";

    for(long long times=0; times<x; times++)
    {
        l++;
        char c[100000], temp[100000];
        long long c_index = -1, temp_index = -1;
        for(long long i=0; i<l; i++)
        {
            temp[++temp_index] = s[i];
            //cout << "inserted in temp\n";
        }
        for(long long i=l; i<strlen(s); i++)
        {
            c[++c_index] = s[i];
            //cout << "inserted in c\n";
        }
        temp[temp_index + 1] = '\0';
        c[c_index + 1] = '\0';
        //cout << temp << " " << c << "\n";
        //cout << temp_index << " " << c_index << "\n";
        /*for(int i=0; i<=temp_index; i++)
        {
            cout << temp[i];
            //cout << "here temp";
        }
        cout << " ";
        for(int i=0; i<=c_index; i++)
        {
            cout << c[i];
            //cout << "here c";
        }
        cout << "\n";*/
        long long sl = temp[temp_index] - '0';
        for(long long i=0; i<sl; i++)
        {
            strcat(temp, c);
            temp_index += (c_index + 1);
        }
        //strcat(temp, c);
        //strcat(temp, c);
        //strcat(temp, c);
        //cout << sl << "\n";
        /*for(int i=0; i<=temp_index; i++)
        {
            cout << temp[i];
            //cout << "here temp";
        }
        cout << "\n";*/
        temp[temp_index + 1] = '\0';
        //cout << temp << "\n";
        strcpy(s, temp);
        //length = temp_index + 1;
        //cout << s << "\n";
        //cout << temp_index << "\n";
        if(temp_index + 1 >= x)
        {
            break;
        }
    }
    //cout << s << "\n" << strlen(s) << "\n";
    for(long long j=0; j<x; j++)
    {
        //cout << length << " + (" << length << " - " << j + 1 << ") x ( " << s[j] << " - 1) = ";
        length += ((length - j - 1) * ((s[j] - '0') - 1));
        length %= Mod;
        //cout << length << "\n";
    }
    cout << length << "\n";}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t,x;
    cin >> t;
    while(t--)
    {
        cin >> x;
        string s;
        cin >> s;
        long long int k=0;
        long long int l=s.length();
        while(k<x)
        {
            k++;
            long long int j=(s[k-1]-'0');
            if(s.length()<=1000)
            {
                long long int g=s.length();
                string s1=s.substr(0,k);
                for(long long int i=0;i<j;i++)
                {
                    s1+=s.substr(k,g-k);
                }
                s=s1;
            }
            l=(k+(l-k)*j);
        }
        cout << l << "\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
int main()
{
    long long int t,x;
    cin >> t;
    while(t--)
    {
        cin >> x;
        string s;
        cin >> s;
        long long int k=0;
        long long int l=s.length();
        while(k<x)
        {
            k++;
            long long int j=(s[k-1]-'0');
            if(s.length()<x)
            {
                long long int g=s.length();
                string s1=s.substr(0,k);
                for(long long int i=0;i<j;i++)
                {
                    s1+=s.substr(k,g-k);
                }
                s=s1;
            }
            l=(k%mod+(((l-k)%mod)*(j%mod))%mod)%mod;
        }
        cout << l << "\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int t,x;
    cin >> t;
    while(t--)
    {
        cin >> x;
        string s;
        cin >> s;
        long long int k=0;
        long long int l=s.length();
        while(k<x)
        {
            k++;
            long long int j=(s[k-1]-'0');
            if(s.length()<x)
            {
                long long int g=s.length();
                string s1=s.substr(0,k);
                for(long long int i=0;i<j;i++)
                {
                    s1+=s.substr(k,g-k);
                }
                s=s1;
            }
            l=(k+(((l-k+mod)%mod)*j)%mod)%mod;
        }
        cout << l << "\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007;
int main()
{
    long long int t,x;
    cin >> t;
    while(t--)
    {
        cin >> x;
        string s;
        cin >> s;
        long long int k=0;
        long long int l=s.length();
        while(k<x)
        {
            k++;
            long long int j=(s[k-1]-'0');
            if(s.length()<x)
            {
                long long int g=s.length();
                string s1=s.substr(0,k);
                for(long long int i=0;i<j;i++)
                {
                    s1+=s.substr(k,g-k);
                }
                s=s1;
            }
            l=(k+(l-k)*j)%mod;
        }
        cout << l << "\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int t,x;
    cin >> t;
    while(t--)
    {
        cin >> x;
        string s;
        cin >> s;
        long long int k=0;
        long long int l=s.length();
        while(k<x)
        {
            k++;
            long long int j=(s[k-1]-'0');
            if(s.length()<x)
            {
                long long int g=s.length();
                string s1=s.substr(k,g-k);
                for(long long int i=1;i<j;i++)
                {
                    s+=s1;
                }
            }
            l=(k+(((l-k+mod)%mod)*j)%mod)%mod;
        }
        cout << l << "\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
int main()
{
    long long int t,x;
    cin >> t;
    while(t--)
    {
        cin >> x;
        string s;
        cin >> s;
        long long int k=0;
        long long int l=s.length();
        while(k<x)
        {
            k++;
            long long int j=(s[k-1]-'0');
            if(s.length()<x)
            {
                long long int g=s.length();
                string s1=s.substr(0,k);
                for(long long int i=0;i<j;i++)
                {
                    s1+=s.substr(k,g-k);
                }
                s=s1;
            }
            l=(k+(((l-k+mod)%mod)*j)%mod)%mod;
        }
        cout << l << "\n";
    }
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N=2e6+1e3+7,P=1e9+7;

int x,T;

char s[N];

ll len;

int main()
{
	scanf("%d",&T);
	while(T--)
	{
		bool flag=true;
		scanf("%d",&x);
		scanf("%s",s+1);
		len=strlen(s+1);
		for(int i=1;i<=x;i++)
		{
			ll apl=(len-i+P)%P;
			for(int k=1;k<=s[i]-'0'-1;k++)
			{
				if(flag)
					for(int j=len+1;j<=min(len+apl,(ll)x);j++)
						if(j-apl>0)
							s[j]=s[j-apl];
				if(len+apl>x)
					flag=false;
				len=(len+apl)%P;
			}
		}
		printf("%lld\n",len);
	}
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N=1e6+1e3+7,P=1e9+7;

int x,T;

char s[N];

ll len;

int main()
{
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d",&x);
		scanf("%s",s+1);
		len=strlen(s+1);
		for(int i=1;i<=x;i++)
		{
			ll apl=(len-i);
			for(int k=1;k<=s[i]-'0'-1;k++)
			{
				for(int j=len+1;j<=min(len+apl,(ll)x);j++)
					s[j]=s[j-apl];
				len=(len+apl)%P;
			}
		}
		printf("%lld\n",len);
	}
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N=2e6+1e3+7,P=1e9+7;

int x,T;

char s[N];

ll len;

int main()
{
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d",&x);
		scanf("%s",s+1);
		len=strlen(s+1);
		for(int i=1;i<=x;i++)
		{
			ll apl=(len-i);
			for(int k=1;k<=s[i]-'0'-1;k++)
			{
				for(int j=len+1;j<=min(len+apl,(ll)x);j++)
					if(j-apl>0&&j<N)
						s[j]=s[j-apl];
				len=(len+apl)%P;
			}
		}
		printf("%lld\n",len);
	}
}


#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long LL;
const int N=1e5+5,md=1e9+7;
string s,c;
int n;
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int T;
	for(cin>>T;T--;){
		cin>>n;
		cin>>s;
		int len=s.length();
		for(int i=0;i<n;++i){
			if(s.length()>=n){
				int lc=(len-i-1+md)%md;
				len=(len+lc*((s[i]^'0')-1LL))%md;
				continue;
			}
			c="";
			for(int j=i+1;j<len;++j)c+=s[j];
			int d=s[i]^'0';
			for(int t=1;t<d;++t)s+=c,len+=c.length();
		}
		cout<<len<<'\n';
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long LL;
const int N=1e5+5,md=1e9+7;
string s,c;
int n;
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int T;
	for(cin>>T;T--;){
		cin>>n;
		cin>>s;
		int len=s.length();
		for(int i=0;i<n;++i){
			if(s.length()>=n){
				int lc=(len-i-1+md)%md;
				len=(len+lc*((s[i]^'0')-1LL))%md;
				continue;
			}
			int d=s[i]^'0';
			if(!d)continue;
			c="";
			for(int j=i+1;j<len;++j)c+=s[j];
			for(int t=1;t<d;++t)s+=c,len+=c.length();
		}
		cout<<len<<'\n';
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long LL;
const int N=1e5+5,md=1e9+7;
string s,c;
int n,T;
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	for(cin>>T;T--;){
		cin>>n;
		cin>>s;
		int len=s.length();
		for(int i=0;i<n;++i){
			if(s.length()>=n){
				int lc=(len-i-1+md)%md;
				len=(len+lc*((s[i]^'0')-1LL))%md;
				continue;
			}
			int d=s[i]^'0';
			if(d==1)continue;
			c="";
			for(int j=i+1;j<len;++j)c.push_back(s[j]);
			for(int t=1;t<d;++t)len+=c.length();
			for(int t=1;t<d;++t)
			for(int j=0;j<c.length();++j)
			s.push_back(c[j]);
		}
		cout<<len<<'\n';
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long LL;
const int N=1e5+5,md=1e9+7;
string s,c;
int n;
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int T;
	for(cin>>T;T--;){
		cin>>n;
		cin>>s;
		int len=s.length();
		for(int i=0;i<n;++i){
			if(s.length()>=n){
				int lc=(len-i-1+md)%md;
				len=(len+lc*((s[i]^'0')-1LL))%md;
				continue;
			}
			int d=s[i]^'0';
			if(!d)continue;
			c="";
			for(int j=i+1;j<len;++j)c.push_back(s[j]);
			for(int t=1;t<d;++t)len+=c.length();
			for(int t=1;t<d;++t)
			for(int j=0;j<c.length();++j)
			s.push_back(c[j]);
		}
		cout<<len<<'\n';
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long LL;
const int N=1e5+5,md=1e9+7;
string s,c;
int n;
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int T;
	for(cin>>T;T--;){
		cin>>n;
		cin>>s;
		int len=s.length();
		for(int i=0;i<n;++i){
			if(s.length()>=n){
				int lc=(len-i-1+md)%md;
				len=(len+lc*((s[i]^'0')-1LL))%md;
				continue;
			}
			int d=s[i]^'0';
			if(!d)continue;
			c="";
			for(int j=i+1;j<len;++j)c.push_back(s[j]);
			for(int t=1;t<d;++t)s+=c,len+=c.length();
		}
		cout<<len<<'\n';
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long LL;
const int N=1e5+5,md=1e9+7;
string s,c;
int n;
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int T;
	for(cin>>T;T--;){
		cin>>n;
		cin>>s;
		int len=s.length();
		for(int i=0;i<n;++i){
			if(s.length()>=n){
				int lc=(len-i-1+md)%md;
				len=(len+lc*((s[i]^'0')-1LL))%md;
				continue;
			}
			int d=s[i]^'0';
			if(d==1)continue;
			c="";
			for(int j=i+1;j<len;++j)c.push_back(s[j]);
			for(int t=1;t<d;++t)len+=c.length();
			for(int t=1;t<d;++t)
			for(int j=0;j<c.length();++j)
			s.push_back(c[j]);
		}
		cout<<len<<'\n';
	}
	return 0;
}


#include<bits/stdc++.h>
#define ULL unsigned long long
#define F first
#define S second
#define pb push_back
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define range(a) a.begin(), a.end()
#define PI pair<int,int>
#define VI vector<int,int>

using namespace std;

typedef long long ll;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/* DSU
int p[maxn]; // rep1(i,n) p[i]=i;

int find(int u){
    if (p[u]==u) return u;
    return p[u]=find(p[u]);
}

bool unite(int u,int v){
    int pu=find(u),pv=find(v);
    p[pu]=pv;
    return pu!=pv;
}
*/

const int maxn=400007;
const int mod=1e9+7;
int n,x,t;
char s[maxn];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin>>t;
    while (t--){
        cin>>x;
        cin>>s;
        int u=strlen(s),tmp=u,l=0;
        while (l<u&&u<x){
            int rem=u;
            for (int j=1;j<s[l]-'0';++j){
                for (int k=l+1;k<rem;++k){
                    s[u++]=s[k];
                }
            }
            l++;
        }
 //       cout<<s<<endl;
        long long now=tmp;
        for (int i=0;i<x;++i){
            now--;
            now=((s[i]-'0')*now)%mod;
        }
        cout<<now+x<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ULL unsigned long long
#define F first
#define S second
#define pb push_back
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define range(a) a.begin(), a.end()
#define PI pair<int,int>
#define VI vector<int,int>

using namespace std;

typedef long long ll;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/* DSU
int p[maxn]; // rep1(i,n) p[i]=i;

int find(int u){
    if (p[u]==u) return u;
    return p[u]=find(p[u]);
}

bool unite(int u,int v){
    int pu=find(u),pv=find(v);
    p[pu]=pv;
    return pu!=pv;
}
*/

const int maxn=4000007;
const int mod=1e9+7;
int n,x,t;
char s[maxn];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin>>t;
    while (t--){
        cin>>x;
        cin>>s;
        int u=strlen(s),tmp=u,l=0;
        while (l<u&&u<x){
            int rem=u;
            for (int j=1;j<s[l]-'0';++j){
                for (int k=l+1;k<rem;++k){
                    s[u++]=s[k];
                }
            }
            l++;
        }
 //       cout<<s<<endl;
        long long now=tmp;
        for (int i=0;i<x;++i){
            now--;
            now=((s[i]-'0')*now)%mod;
        }
        cout<<(now+x)%mod<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ULL unsigned long long
#define F first
#define S second
#define pb push_back
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define range(a) a.begin(), a.end()
#define PI pair<int,int>
#define VI vector<int,int>

using namespace std;

typedef long long ll;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/* DSU
int p[maxn]; // rep1(i,n) p[i]=i;

int find(int u){
    if (p[u]==u) return u;
    return p[u]=find(p[u]);
}

bool unite(int u,int v){
    int pu=find(u),pv=find(v);
    p[pu]=pv;
    return pu!=pv;
}
*/

const int maxn=400007;
const int mod=1e9+7;
int n,x,t;
char s[maxn];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin>>t;
    while (t--){
        cin>>x;
        cin>>s;
        int u=strlen(s),tmp=u,l=0;
        while (l<tmp&&u<x){
            int rem=u;
            for (int j=1;j<s[l]-'0';++j){
                for (int k=l+1;k<rem;++k){
                    s[u++]=s[k];
                }
            }
            l++;
        }
 //       cout<<s<<endl;
        long long now=tmp;
        for (int i=0;i<x;++i){
            now--;
            now=((s[i]-'0')*now)%mod;
        }
        cout<<now+x<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ULL unsigned long long
#define F first
#define S second
#define pb push_back
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define range(a) a.begin(), a.end()
#define PI pair<int,int>
#define VI vector<int,int>

using namespace std;

typedef long long ll;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/* DSU
int p[maxn]; // rep1(i,n) p[i]=i;

int find(int u){
    if (p[u]==u) return u;
    return p[u]=find(p[u]);
}

bool unite(int u,int v){
    int pu=find(u),pv=find(v);
    p[pu]=pv;
    return pu!=pv;
}
*/

const int maxn=400007;
const int mod=1e9+7;
int n,x,t;
char s[maxn];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin>>t;
    while (t--){
        cin>>x;
        cin>>s;
        int u=strlen(s),tmp=u,l=0;
        while (u<x){
            int rem=u;
            for (int j=1;j<s[l]-'0';++j){
                for (int k=l+1;k<rem;++k){
                    s[u++]=s[k];
                }
            }
            l++;
        }
 //       cout<<s<<endl;
        long long now=tmp;
        for (int i=0;i<x;++i){
            now--;
            now=((s[i]-'0')*now)%mod;
        }
        cout<<now+x<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define N 10000100
#define ll long long
using namespace std;

const ll p = 1e9 + 7;
ll t, n, x, l, lenc;
ll a[N], c[N];
char s[N];

int main()
{
    scanf("%lld", &t);
    while(t --)
    {
        memset(a, 0, sizeof(a));
        scanf("%lld%s", &x, s);
        n = strlen(s); l = 0;
        for(int i = 0; i < n; i ++)
            a[i + 1] = s[i] - '0';
        while(l != x)
        {
            l ++; lenc = 0;
            if(n <= x + 10)
            {
                int num = 0, tmp = (a[l] - 1) * (n - l) % p;
                for(int i = l + 1; i <= n; i ++)
                    c[++ lenc] = a[i];
                //printf("%lld", lenc); system("pause");
                for(int i = 1; i <= a[l] - 1 && n <= x + 10; i ++)
                    for(int j = 1; j <= lenc && n <= x + 10; j ++)
                        a[++ n] = c[j], num ++;
                //printf("%lld %lld %lld", n, tmp, num); system("pause");
                n = (n + (tmp - num + p) % p) % p;
            }
            else n = (n + (a[l] - 1) * (n - l) % p) % p;
        }
        printf("%lld\n", n);
    }
    return 0;
}
/*
1
24
133321333
*/


#include<bits/stdc++.h>
#define N 1000010
#define ll long long
using namespace std;

const ll p = 1e9 + 7;
ll t, n, x, l, lenc;
ll a[N], c[N];
char s[N];

int main()
{
    scanf("%lld", &t);
    while(t --)
    {
        //memset(a, 0, sizeof(a));
        scanf("%lld%s", &x, s);
        n = strlen(s); l = 0;
        for(int i = 0; i < n; i ++)
            a[i + 1] = s[i] - '0';
        bool f = false;
        while(l != x)
        {
            l ++; lenc = 0;
            if(!f)
            {
                int num = 0, tmp = (a[l] - 1) * ((n - l + p) % p) % p;
                for(int i = l + 1; i <= n; i ++)
                    c[++ lenc] = a[i];
                //printf("%lld", lenc); system("pause");
                for(int i = 1; i <= a[l] - 1 && n <= x + 10; i ++)
                    for(int j = 1; j <= lenc && n <= x + 10; j ++)
                        a[++ n] = c[j], num ++;
                if(tmp != num) f = 1;
                //printf("%lld %lld %lld", n, tmp, num); system("pause");
                n = (n + (tmp - num + p) % p) % p;
            }
            else n = (n + (a[l] - 1) * ((n - l + p) % p) % p) % p;
        }
        printf("%lld\n", n);
    }
    return 0;
}
/*
1
24
133321333
*/


#include<bits/stdc++.h>
#define N 2000010
#define ll long long
using namespace std;

const ll p = 1e9 + 7;
ll t, n, x, l, lenc;
ll a[N], c[N];
char s[N];

int main()
{
    scanf("%lld", &t);
    while(t --)
    {
        //memset(a, 0, sizeof(a));
        scanf("%lld%s", &x, s);
        n = strlen(s); l = 0;
        for(int i = 0; i < n; i ++)
            a[i + 1] = s[i] - '0';
        bool f = false;
        while(l != x)
        {
            l ++; lenc = 0;
            if(!f)
            {
                if(a[l] == 1) continue;
                ll num = 0, tmp = (a[l] - 1) * ((n - l + p) % p) % p;
                for(int i = l + 1; i <= n; i ++)
                    c[++ lenc] = a[i];
                //printf("%lld", lenc); system("pause");
                for(int i = 1; i <= a[l] - 1 && n <= x + 10; i ++)
                    for(int j = 1; j <= lenc && n <= x + 10; j ++)
                        a[++ n] = c[j], num ++;
                if(tmp != num) f = 1;
                //printf("%lld %lld %lld", n, tmp, num); system("pause");
                n = (n + (tmp - num + p) % p) % p;
                if(n >= x) f = 1;
            }
            else n = (n + (a[l] - 1) * ((n - l + p) % p) % p) % p;
        }
        printf("%lld\n", n);
    }
    return 0;
}
/*
1
24
133321333
*/


#include<bits/stdc++.h>
#define N 10000100
#define ll long long
using namespace std;

const ll p = 1e9 + 7;
ll t, n, x, l, lenc;
ll a[N], c[N];
char s[N];

int main()
{
    scanf("%lld", &t);
    while(t --)
    {
        scanf("%lld%s", &x, s);
        n = strlen(s); l = 0;
        for(int i = 0; i < n; i ++)
            a[i + 1] = s[i] - '0';
        while(l != x)
        {
            l ++; lenc = 0;
            if(n <= x + 10)
            {
                for(int i = l + 1; i <= n; i ++)
                    c[++ lenc] = a[i];
                for(int i = 1; i <= a[l] - 1; i ++)
                    for(int j = 1; j <= lenc; j ++)
                        a[++ n] = c[j];
            }
            else n = (n + (a[l] - 1) * (n - l) % p) % p;
        }
        printf("%lld\n", n);
    }
    return 0;
}
/*
1
24
133321333
*/


#include<bits/stdc++.h>
#define N 10000100
#define ll long long
using namespace std;

const ll p = 1e9 + 7;
ll t, n, x, l, lenc;
ll a[N], c[N];
char s[N];

int main()
{
    scanf("%lld", &t);
    while(t --)
    {
        scanf("%lld%s", &x, s);
        n = strlen(s); l = 0;
        for(int i = 0; i < n; i ++)
            a[i + 1] = s[i] - '0';
        while(l != x)
        {
            l ++; lenc = 0;
            if(n <= x + 10)
            {
                int num = 0, tmp = (a[l] - 1) * (n - l) % p;
                for(int i = l + 1; i <= n; i ++)
                    c[++ lenc] = a[i];
                for(int i = 1; i <= a[l] - 1 && n <= x + 10; i ++)
                    for(int j = 1; j <= lenc && n <= x + 10; j ++)
                        a[++ n] = c[j], num ++;
                n = (n + (tmp - num + p) % p) % p;
            }
            else n = (n + (a[l] - 1) * (n - l) % p) % p;
        }
        printf("%lld\n", n);
    }
    return 0;
}
/*
1
24
133321333
*/


#include<bits/stdc++.h>
#define N 1000010
#define ll long long
using namespace std;

const ll p = 1e9 + 7;
ll t, n, x, l, lenc;
ll a[N], c[N];
char s[N];

int main()
{
    scanf("%lld", &t);
    while(t --)
    {
        //memset(a, 0, sizeof(a));
        scanf("%lld%s", &x, s);
        n = strlen(s); l = 0;
        for(int i = 0; i < n; i ++)
            a[i + 1] = s[i] - '0';
        bool f = false;
        while(l != x)
        {
            l ++; lenc = 0;
            if(!f)
            {
                ll num = 0, tmp = (a[l] - 1) * ((n - l + p) % p) % p;
                for(int i = l + 1; i <= n; i ++)
                    c[++ lenc] = a[i];
                //printf("%lld", lenc); system("pause");
                for(int i = 1; i <= a[l] - 1 && n <= x + 10; i ++)
                    for(int j = 1; j <= lenc && n <= x + 10; j ++)
                        a[++ n] = c[j], num ++;
                if(tmp != num) f = 1;
                //printf("%lld %lld %lld", n, tmp, num); system("pause");
                n = (n + (tmp - num + p) % p) % p;
            }
            else n = (n + (a[l] - 1) * ((n - l + p) % p) % p) % p;
        }
        printf("%lld\n", n);
    }
    return 0;
}
/*
1
24
133321333
*/


#include<bits/stdc++.h>
#define N 1000100
#define ll long long
using namespace std;

const ll p = 1e9 + 7;
ll t, n, x, l, lenc;
ll a[N], c[N];
char s[N];

int main()
{
    scanf("%lld", &t);
    while(t --)
    {
        scanf("%lld%s", &x, s);
        n = strlen(s); l = 0;
        for(int i = 0; i < n; i ++)
            a[i + 1] = s[i] - '0';
        while(l != x)
        {
            l ++; lenc = 0;
            if(n <= x + 10)
            {
                for(int i = l + 1; i <= n; i ++)
                    c[++ lenc] = a[i];
                for(int i = 1; i <= a[l] - 1; i ++)
                    for(int j = 1; j <= lenc; j ++)
                        a[++ n] = c[j];
            }
            else n = (n + (a[l] - 1) * (n - l) % p) % p;
        }
        printf("%lld\n", n);
    }
    return 0;
}
/*
1
24
133321333
*/


#include<bits/stdc++.h>
#define N 1000010
#define ll long long
using namespace std;

const ll p = 1e9 + 7;
ll t, n, x, l, lenc;
ll a[N], c[N];
char s[N];

int main()
{
    scanf("%lld", &t);
    while(t --)
    {
        //memset(a, 0, sizeof(a));
        scanf("%lld%s", &x, s);
        n = strlen(s); l = 0;
        for(int i = 0; i < n; i ++)
            a[i + 1] = s[i] - '0';
        bool f = false;
        while(l != x)
        {
            l ++; lenc = 0;
            if(n <= x + 10 && !f)
            {
                int num = 0, tmp = (a[l] - 1) * (n - l) % p;
                for(int i = l + 1; i <= n; i ++)
                    c[++ lenc] = a[i];
                //printf("%lld", lenc); system("pause");
                for(int i = 1; i <= a[l] - 1 && n <= x + 10; i ++)
                    for(int j = 1; j <= lenc && n <= x + 10; j ++)
                        a[++ n] = c[j], num ++;
                if(tmp != num) f = 1;
                //printf("%lld %lld %lld", n, tmp, num); system("pause");
                n = (n + (tmp - num + p) % p) % p;
            }
            else n = (n + (a[l] - 1) * (n - l) % p) % p;
        }
        printf("%lld\n", n);
    }
    return 0;
}
/*
1
24
133321333
*/


#include<bits/stdc++.h>
#define N 1000100
#define ll long long
using namespace std;

const ll p = 1e9 + 7;
ll t, n, x, l, lenc;
ll a[N], c[N];
char s[N];

int main()
{
    scanf("%lld", &t);
    while(t --)
    {
        scanf("%lld%s", &x, s);
        n = strlen(s); l = 0;
        for(int i = 0; i < n; i ++)
            a[i + 1] = s[i] - '0';
        while(l != x)
        {
            l ++; lenc = 0;
            if(n <= x + 10)
            {
                for(int i = l + 1; i <= n; i ++)
                    c[++ lenc] = a[i];
                for(int i = 1; i <= a[l] - 1; i ++)
                    for(int j = 1; j <= lenc; j ++)
                        a[++ n] = c[j];
            }
            else n = (n + (a[l] - 1) * (n - l) % p) % p;
        }
        printf("%lld", n);
    }
    return 0;
}
/*
1
24
133321333
*/


#include<bits/stdc++.h>
#define N 1000010
#define ll long long
using namespace std;

const ll p = 1e9 + 7;
ll t, n, x, l, lenc;
ll a[N], c[N];
char s[N];

int main()
{
    scanf("%lld", &t);
    while(t --)
    {
        //memset(a, 0, sizeof(a));
        scanf("%lld%s", &x, s);
        n = strlen(s); l = 0;
        for(int i = 0; i < n; i ++)
            a[i + 1] = s[i] - '0';
        bool f = false;
        while(l != x)
        {
            l ++; lenc = 0;
            if(n <= x + 10 && !f)
            {
                int num = 0, tmp = (a[l] - 1) * ((n - l + p) % p) % p;
                for(int i = l + 1; i <= n; i ++)
                    c[++ lenc] = a[i];
                //printf("%lld", lenc); system("pause");
                for(int i = 1; i <= a[l] - 1 && n <= x + 10; i ++)
                    for(int j = 1; j <= lenc && n <= x + 10; j ++)
                        a[++ n] = c[j], num ++;
                if(tmp != num) f = 1;
                //printf("%lld %lld %lld", n, tmp, num); system("pause");
                n = (n + (tmp - num + p) % p) % p;
            }
            else n = (n + (a[l] - 1) * ((n - l + p) % p) % p) % p;
        }
        printf("%lld\n", n);
    }
    return 0;
}
/*
1
24
133321333
*/


#include<bits/stdc++.h>
#define N 2000010
#define ll long long
using namespace std;

const ll p = 1e9 + 7;
ll t, n, x, l, lenc;
ll a[N], c[N];
char s[N];

int main()
{
    scanf("%lld", &t);
    while(t --)
    {
        //memset(a, 0, sizeof(a));
        scanf("%lld%s", &x, s);
        n = strlen(s); l = 0;
        for(int i = 0; i < n; i ++)
            a[i + 1] = s[i] - '0';
        bool f = false;
        while(l != x)
        {
            l ++; lenc = 0;
            if(!f)
            {
                ll num = 0, tmp = (a[l] - 1) * ((n - l + p) % p) % p;
                for(int i = l + 1; i <= n; i ++)
                    c[++ lenc] = a[i];
                //printf("%lld", lenc); system("pause");
                for(int i = 1; i <= a[l] - 1 && n <= x + 10; i ++)
                    for(int j = 1; j <= lenc && n <= x + 10; j ++)
                        a[++ n] = c[j], num ++;
                if(tmp != num) f = 1;
                //printf("%lld %lld %lld", n, tmp, num); system("pause");
                n = (n + (tmp - num + p) % p) % p;
            }
            else n = (n + (a[l] - 1) * ((n - l + p) % p) % p) % p;
        }
        printf("%lld\n", n);
    }
    return 0;
}
/*
1
24
133321333
*/


#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 10, mod = 1e9 + 7;

int x, t;
char s[N];

int main() {
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    scanf("%d", &t);
    while(t--) {
        scanf("%d", &x);
        s[0] = '\0';
        scanf("%s", &s);
        long long len = strlen(s);
        long long after = len - 1;
        bool ok = 1;
        for(int l = 0; l < x; l++) {
            int old = len;
            if(!ok && s[l] != '1') {
                long long add = after * (s[l] - '0' - 1) % mod;
                len = (len + add) % mod;
                after = (after + add) % mod;
            }
            for(int j = 0; j < s[l] - '0' - 1 && ok; j++) {
                for(int k = l + 1; k < old; k++) s[len++] = s[k], after++;
            }
            if(len >= x) ok = 0;
            len %= mod;
            after--;
            if(after < 0) after += mod;
        }
        printf("%d\n", len);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 10, mod = 1e9 + 7;

int x, t;
char s[N];

int main() {
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    scanf("%d", &t);
    while(t--) {
        scanf("%d", &x);
        scanf("%s", &s);
        long long len = strlen(s);
        bool ok = 1;
        for(int l = 0; l < x; l++) {
            int old = len;
            if(!ok && s[l] != '1') len = (len + (len - l - 1) * (s[l] - '0' - 1) % mod) % mod;
            for(int j = 0; j < s[l] - '0' - 1 && ok; j++) {
                for(int k = l + 1; k < old; k++) s[len++] = s[k];
            }
            if(len > x) ok = 0;
            len %= mod;
        }
        printf("%d\n", len);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 10, mod = 1e9 + 7;

int x, t;
char s[N];

int main() {
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    scanf("%d", &t);
    while(t--) {
        scanf("%d", &x);
        s[0] = '\0';
        scanf("%s", &s);
        long long len = strlen(s);
        bool ok = 1;
        for(int l = 0; l < x; l++) {
            int old = len;
            if(!ok && s[l] != '1') len = (len + (len - l - 1) * (s[l] - '0' - 1) % mod) % mod;
            for(int j = 0; j < s[l] - '0' - 1 && ok; j++) {
                for(int k = l + 1; k < old; k++) s[len++] = s[k];
            }
            if(len >= x) ok = 0;
            len %= mod;
        }
        printf("%d\n", len);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define mod 1000000007

using namespace std;
typedef long long ll;
const int MAXN = 505;
char str[MAXN];
int from[MAXN];

int main()
{
    int T;
    cin >> T;
    while(T--)
    {
        int x;
        cin >> x;
        cin >> str+1;
        int n = strlen(str+1);
		ll len = n;
		for(int i = 1; i<=x; i++)
        {
            if(len<x)
            {
            	int t = (len-i)*(str[i]-'1');
                for(int j = len+1; j<=len+t; j++)
                    str[j] = str[i+(j-len-1)%(len-j)+1];
                len += t;
			}
			else
		        len = (len+1ll*(len-i+mod)*(str[i]-'1')%mod)%mod;
		}
		cout << len << endl;
	}
	return 0;
}


import java.io.*;
import java.util.*;
public class code {
	static printer pw;
	static boolean[] visit;
	static ArrayList<Pair>[] adj;
	static ArrayList<Integer> list;
	static long max=01;
	static void dfs(int i, long c) {
		visit[i]=true;
		max=Math.max(c, max);
		for(Pair p: adj[i]) {
			if(!visit[p.x-1]) {
				dfs(p.x-1, c+1l*p.y);
			}
		}
	}
	public static double dist(Pair a, Pair b) {
		return Math.sqrt((a.x-b.x)*(a.x-b.x)+ (a.y-b.y)*(a.y-b.y));
	}
	public static boolean sign(int x) {
		return x>0;
	}
	static long ceildiv(long x,long y) {
		return x%y==0? x/y: x/y+1;
	}
	public static void main(String[] args) throws Exception {
		Scanner sc= new Scanner(System.in);
		pw = new printer();
		int t=sc.nextInt();
		while(t-->0) {
			int n=sc.nextInt(),k=sc.nextInt();
			String s=sc.next();
			Character[] arr=new Character[n];
			for(int i=0; i<n; i++) {
				arr[i]=s.charAt(i);
			}
			Arrays.sort(arr);
			int a=n/k,b=n/k+1;
			int x=n%k;
			PriorityQueue<String> set=new PriorityQueue<String>(Collections.reverseOrder());
			int i=0,j=n-1;
			int tempk=k;
			int tempx=x;
			while(x-->0) {
				int w=1;
				StringBuilder sb=new StringBuilder();
				int lim=i+w;
				for(;i<lim; i++) {
					sb.append(arr[i]);
				}
				lim=j-(b-w);
				int tempj=lim;
				lim++;
				for(;j>=lim; lim++) {
					sb.append(arr[lim]);
				}
				j=tempj;
				set.add(sb.toString());
				k--;
			}
			while(k-->0) {
				int w=1;
				StringBuilder sb=new StringBuilder();
				int lim=i+w;
				sb.append(arr[i]);
				lim=j-(a-w);
				int tempj=lim;
				lim++;
				for(;j>=lim; lim++) {
					sb.append(arr[lim]);
				}
				j=tempj;
				set.add(sb.toString());
			}
			x=tempx;
			k=tempk;
			PriorityQueue<String> prior=new PriorityQueue<String>(Collections.reverseOrder());
			while(x-->0) {
				int w=b/2;
				StringBuilder sb=new StringBuilder();
				int lim=i+w;
				for(;i<lim; i++) {
					sb.append(arr[i]);
				}
				lim=j-(b-w);
				int tempj=lim;
				lim++;
				for(;j>=lim; lim++) {
					sb.append(arr[lim]);
				}
				j=tempj;
				prior.add(sb.toString());
				k--;
			}
			while(k-->0) {
				int w=a/2;
				StringBuilder sb=new StringBuilder();
				int lim=i+w;
				for(;i<lim; i++) {
					sb.append(arr[i]);
				}
				lim=j-(a-w);
				int tempj=lim;
				lim++;
				for(;j>=lim; lim++) {
					sb.append(arr[lim]);
				}
				j=tempj;
				prior.add(sb.toString());
			}
			PriorityQueue<String> pq=new PriorityQueue<String>(Collections.reverseOrder());
			i=1;j=n-1;
			b=n-(tempk-1);
			StringBuilder sb=new StringBuilder();
			sb.append(arr[0]);
			int lim=j-(b-1)+1;
			int tempj=lim-1;
			for(;j>=lim; lim++) {
				sb.append(arr[lim]);
			}
			j=tempj;
			pq.add(sb.toString());
			k--;
			for(;i<=j; i++) {
				pq.add(arr[i]+"");
			}
			PriorityQueue<String> ans=new PriorityQueue<String>(Collections.reverseOrder());
			ans.add(pq.poll());ans.add(set.poll());ans.add(prior.poll());
			pw.println(ans.poll());
		}
		pw.close();
	}
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(FileReader r) {
			br = new BufferedReader(r);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextArr(int n) throws IOException {
			int[] arr = new int[n];
			for (int i = 0; i < arr.length; i++)
				arr[i] = nextInt();
			return arr;
		}
		public Integer[] nextsort(int n) throws IOException{
			Integer[] arr=new Integer[n];
			for(int i=0; i<n; i++)
				arr[i]=nextInt();
			return arr;
		}
		public boolean ready() throws IOException {
			return br.ready();
		}
	}
	static class printer{
		PrintWriter pw;
		public printer() {
			pw=new PrintWriter(System.out);
		}
		public void print(String s) throws IOException{
			pw.print(s);
		}
		public void print(int s) throws IOException{
			pw.print(s);
		}
		public void print(long s) throws IOException{
			pw.print(s);
		}
		public void print(char s) throws IOException{
			pw.print(s);
		}
		public void print(Integer s) throws IOException{
			pw.print(s);
		}
		public void print(Long s) throws IOException{
			pw.print(s);
		}
		public void print(Character s) throws IOException{
			pw.print(s);
		}
		public void println(String s) throws IOException{
			pw.println(s);
		}
		public void println(int s) throws IOException{
			pw.println(s);
		}
		public void println(long s) throws IOException{
			pw.println(s);
		}
		public void println(char s) throws IOException{
			pw.println(s);
		}
		public void println(Integer s) throws IOException{
			pw.println(s);
		}
		public void println(Long s) throws IOException{
			pw.println(s);
		}
		public void println(Character s) throws IOException{
			pw.println(s);
		}
		public void println() throws IOException{
			pw.println();
		}
		public void println(int[] arr) throws IOException{
			for(int i=0; i<arr.length-1; i++)
				pw.print(arr[i]+" ");
			pw.println(arr[arr.length-1]);
		}
		public void println(Integer[] arr) throws IOException{
			for(int i=0; i<arr.length-1; i++)
				pw.print(arr[i]+" ");
			pw.println(arr[arr.length-1]);
		}
		public void println(long[] arr) throws IOException{
			for(int i=0; i<arr.length-1; i++)
				pw.print(arr[i]+" ");
			pw.println(arr[arr.length-1]);
		}
		public void println(Long[] arr) throws IOException{
			for(int i=0; i<arr.length-1; i++)
				pw.print(arr[i]+" ");
			pw.println(arr[arr.length-1]);
		}
		public void println(char[] arr) throws IOException{
			for(int i=0; i<arr.length-1; i++)
				pw.print(arr[i]+" ");
			pw.println(arr[arr.length-1]);
		}
		public void println(Character[] arr) throws IOException{
			for(int i=0; i<arr.length-1; i++)
				pw.print(arr[i]+" ");
			pw.println(arr[arr.length-1]);
		}
		public void println(ArrayList<Integer> arr) throws IOException{
			for(int i=0; i<arr.size()-1; i++)
				pw.print(arr.get(i)+" ");
			pw.println(arr.get(arr.size()-1));
		}
		public void println(TreeSet<Integer> arr) throws IOException{
			for(int x: arr) {
				pw.print(x+" ");
			}
		}
		public void close() throws IOException{
			pw.close();
		}
		public void flush() throws IOException{
			pw.flush();
		}
	}
	static class Pair implements Comparable<Pair>{
		int x;
		int y;
		public Pair(int a, int b) {
			this.x=a;
			this.y=b;
		}
		public int compareTo(Pair other) {
			return -1*(this.y-other.y);
		}
	}
	static class Triple implements Comparable<Triple>{
		int x;
		int y;
		boolean d;
		public Triple(int a, int b, boolean t) {
			this.x=a;
			this.y=b;
			this.d=t;
		}
		public int compareTo(Triple other) {
			if(this.d && !other.d) {
				return 1;
			}else if(!this.d && other.d) {
				return -1;
			}else {
				return this.y-other.y;
			}
		}
	}
}


import java.io.*;
import java.util.*;
public class code {
	static printer pw;
	static boolean[] visit;
	static ArrayList<Pair>[] adj;
	static ArrayList<Integer> list;
	static long max=01;
	static void dfs(int i, long c) {
		visit[i]=true;
		max=Math.max(c, max);
		for(Pair p: adj[i]) {
			if(!visit[p.x-1]) {
				dfs(p.x-1, c+1l*p.y);
			}
		}
	}
	public static double dist(Pair a, Pair b) {
		return Math.sqrt((a.x-b.x)*(a.x-b.x)+ (a.y-b.y)*(a.y-b.y));
	}
	public static boolean sign(int x) {
		return x>0;
	}
	static long ceildiv(long x,long y) {
		return x%y==0? x/y: x/y+1;
	}
	public static void main(String[] args) throws Exception {
		Scanner sc= new Scanner(System.in);
		pw = new printer();
		int t=sc.nextInt();
		while(t-->0) {
			int n=sc.nextInt(),k=sc.nextInt();
			String s=sc.next();
			Character[] arr=new Character[n];
			for(int i=0; i<n; i++) {
				arr[i]=s.charAt(i);
			}
			Arrays.sort(arr);
			int a=n/k,b=n/k+1;
			int x=n%k;
			PriorityQueue<String> set=new PriorityQueue<String>(Collections.reverseOrder());
			int i=0,j=n-1;
			int tempk=k;
			while(x-->0) {
				int w=b/2;
				StringBuilder sb=new StringBuilder();
				int lim=i+w;
				for(;i<lim; i++) {
					sb.append(arr[i]);
				}
				lim=j-(b-w);
				int tempj=lim;
				lim++;
				for(;j>=lim; lim++) {
					sb.append(arr[lim]);
				}
				j=tempj;
				set.add(sb.toString());
				k--;
			}
			while(k-->0) {
				int w=a/2;
				StringBuilder sb=new StringBuilder();
				int lim=i+w;
				for(;i<lim; i++) {
					sb.append(arr[i]);
				}
				lim=j-(a-w);
				int tempj=lim;
				lim++;
				for(;j>=lim; lim++) {
					sb.append(arr[lim]);
				}
				j=tempj;
				set.add(sb.toString());
			}
			PriorityQueue<String> pq=new PriorityQueue<String>(Collections.reverseOrder());
			i=1;j=n-1;
			b=n-(tempk-1);
			StringBuilder sb=new StringBuilder();
			sb.append(arr[0]);
			int lim=j-(b-1)+1;
			int tempj=lim;
			for(;j>=lim; lim++) {
				sb.append(arr[lim]);
			}
			j=tempj;
			pq.add(sb.toString());
			k--;
			for(;i<j; i++) {
				pq.add(arr[i]+"");
			}
			String f=pq.poll(),l=set.poll();
			pw.println(f.compareTo(l)<0? f:l);
		}
		pw.close();
	}
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(FileReader r) {
			br = new BufferedReader(r);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextArr(int n) throws IOException {
			int[] arr = new int[n];
			for (int i = 0; i < arr.length; i++)
				arr[i] = nextInt();
			return arr;
		}
		public Integer[] nextsort(int n) throws IOException{
			Integer[] arr=new Integer[n];
			for(int i=0; i<n; i++)
				arr[i]=nextInt();
			return arr;
		}
		public boolean ready() throws IOException {
			return br.ready();
		}
	}
	static class printer{
		PrintWriter pw;
		public printer() {
			pw=new PrintWriter(System.out);
		}
		public void print(String s) throws IOException{
			pw.print(s);
		}
		public void print(int s) throws IOException{
			pw.print(s);
		}
		public void print(long s) throws IOException{
			pw.print(s);
		}
		public void print(char s) throws IOException{
			pw.print(s);
		}
		public void print(Integer s) throws IOException{
			pw.print(s);
		}
		public void print(Long s) throws IOException{
			pw.print(s);
		}
		public void print(Character s) throws IOException{
			pw.print(s);
		}
		public void println(String s) throws IOException{
			pw.println(s);
		}
		public void println(int s) throws IOException{
			pw.println(s);
		}
		public void println(long s) throws IOException{
			pw.println(s);
		}
		public void println(char s) throws IOException{
			pw.println(s);
		}
		public void println(Integer s) throws IOException{
			pw.println(s);
		}
		public void println(Long s) throws IOException{
			pw.println(s);
		}
		public void println(Character s) throws IOException{
			pw.println(s);
		}
		public void println() throws IOException{
			pw.println();
		}
		public void println(int[] arr) throws IOException{
			for(int i=0; i<arr.length-1; i++)
				pw.print(arr[i]+" ");
			pw.println(arr[arr.length-1]);
		}
		public void println(Integer[] arr) throws IOException{
			for(int i=0; i<arr.length-1; i++)
				pw.print(arr[i]+" ");
			pw.println(arr[arr.length-1]);
		}
		public void println(long[] arr) throws IOException{
			for(int i=0; i<arr.length-1; i++)
				pw.print(arr[i]+" ");
			pw.println(arr[arr.length-1]);
		}
		public void println(Long[] arr) throws IOException{
			for(int i=0; i<arr.length-1; i++)
				pw.print(arr[i]+" ");
			pw.println(arr[arr.length-1]);
		}
		public void println(char[] arr) throws IOException{
			for(int i=0; i<arr.length-1; i++)
				pw.print(arr[i]+" ");
			pw.println(arr[arr.length-1]);
		}
		public void println(Character[] arr) throws IOException{
			for(int i=0; i<arr.length-1; i++)
				pw.print(arr[i]+" ");
			pw.println(arr[arr.length-1]);
		}
		public void println(ArrayList<Integer> arr) throws IOException{
			for(int i=0; i<arr.size()-1; i++)
				pw.print(arr.get(i)+" ");
			pw.println(arr.get(arr.size()-1));
		}
		public void println(TreeSet<Integer> arr) throws IOException{
			for(int x: arr) {
				pw.print(x+" ");
			}
		}
		public void close() throws IOException{
			pw.close();
		}
		public void flush() throws IOException{
			pw.flush();
		}
	}
	static class Pair implements Comparable<Pair>{
		int x;
		int y;
		public Pair(int a, int b) {
			this.x=a;
			this.y=b;
		}
		public int compareTo(Pair other) {
			return -1*(this.y-other.y);
		}
	}
	static class Triple implements Comparable<Triple>{
		int x;
		int y;
		boolean d;
		public Triple(int a, int b, boolean t) {
			this.x=a;
			this.y=b;
			this.d=t;
		}
		public int compareTo(Triple other) {
			if(this.d && !other.d) {
				return 1;
			}else if(!this.d && other.d) {
				return -1;
			}else {
				return this.y-other.y;
			}
		}
	}
}


import java.io.*;
import java.util.*;
public class code {
	static printer pw;
	static boolean[] visit;
	static ArrayList<Pair>[] adj;
	static ArrayList<Integer> list;
	static long max=01;
	static void dfs(int i, long c) {
		visit[i]=true;
		max=Math.max(c, max);
		for(Pair p: adj[i]) {
			if(!visit[p.x-1]) {
				dfs(p.x-1, c+1l*p.y);
			}
		}
	}
	public static double dist(Pair a, Pair b) {
		return Math.sqrt((a.x-b.x)*(a.x-b.x)+ (a.y-b.y)*(a.y-b.y));
	}
	public static boolean sign(int x) {
		return x>0;
	}
	static long ceildiv(long x,long y) {
		return x%y==0? x/y: x/y+1;
	}
	public static void main(String[] args) throws Exception {
		Scanner sc= new Scanner(System.in);
		pw = new printer();
		int t=sc.nextInt();
		while(t-->0) {
			int n=sc.nextInt(),k=sc.nextInt();
			String s=sc.next();
			Character[] arr=new Character[n];
			for(int i=0; i<n; i++) {
				arr[i]=s.charAt(i);
			}
			Arrays.sort(arr);
			int a=n/k,b=n/k+1;
			int x=n%k;
			TreeSet<String> link=new TreeSet<String>();
			int i=0,j=n-1;
			int tempk=k;
			while(x-->0) {
				int w=b/2;
				StringBuilder sb=new StringBuilder();
				int lim=i+w;
				for(;i<lim; i++) {
					sb.append(arr[i]);
				}
				lim=j-(b-w);
				int tempj=lim;
				lim++;
				for(;j>=lim; lim++) {
					sb.append(arr[lim]);
				}
				j=tempj;
				link.add(sb.toString());
				k--;
			}
			while(k-->0) {
				int w=a/2;
				StringBuilder sb=new StringBuilder();
				int lim=i+w;
				for(;i<lim; i++) {
					sb.append(arr[i]);
				}
				lim=j-(a-w);
				int tempj=lim;
				lim++;
				for(;j>=lim; lim++) {
					sb.append(arr[lim]);
				}
				j=tempj;
				link.add(sb.toString());
			}
			TreeSet<String> tree=new TreeSet<String>();
			i=1;j=n-1;
			b=n-(tempk-1);
			StringBuilder sb=new StringBuilder();
			sb.append(arr[0]);
			int lim=j-(b-1)+1;
			int tempj=lim;
			for(;j>=lim; lim++) {
				sb.append(arr[lim]);
			}
			j=tempj;
			tree.add(sb.toString());
			k--;
			for(;i<j; i++) {
				tree.add(arr[i]+"");
			}
			String f=tree.last(),l=link.last();
			pw.println(f.compareTo(l)<0? f:l);
		}
		pw.close();
	}
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(FileReader r) {
			br = new BufferedReader(r);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextArr(int n) throws IOException {
			int[] arr = new int[n];
			for (int i = 0; i < arr.length; i++)
				arr[i] = nextInt();
			return arr;
		}
		public Integer[] nextsort(int n) throws IOException{
			Integer[] arr=new Integer[n];
			for(int i=0; i<n; i++)
				arr[i]=nextInt();
			return arr;
		}
		public boolean ready() throws IOException {
			return br.ready();
		}
	}
	static class printer{
		PrintWriter pw;
		public printer() {
			pw=new PrintWriter(System.out);
		}
		public void print(String s) throws IOException{
			pw.print(s);
		}
		public void print(int s) throws IOException{
			pw.print(s);
		}
		public void print(long s) throws IOException{
			pw.print(s);
		}
		public void print(char s) throws IOException{
			pw.print(s);
		}
		public void print(Integer s) throws IOException{
			pw.print(s);
		}
		public void print(Long s) throws IOException{
			pw.print(s);
		}
		public void print(Character s) throws IOException{
			pw.print(s);
		}
		public void println(String s) throws IOException{
			pw.println(s);
		}
		public void println(int s) throws IOException{
			pw.println(s);
		}
		public void println(long s) throws IOException{
			pw.println(s);
		}
		public void println(char s) throws IOException{
			pw.println(s);
		}
		public void println(Integer s) throws IOException{
			pw.println(s);
		}
		public void println(Long s) throws IOException{
			pw.println(s);
		}
		public void println(Character s) throws IOException{
			pw.println(s);
		}
		public void println() throws IOException{
			pw.println();
		}
		public void println(int[] arr) throws IOException{
			for(int i=0; i<arr.length-1; i++)
				pw.print(arr[i]+" ");
			pw.println(arr[arr.length-1]);
		}
		public void println(Integer[] arr) throws IOException{
			for(int i=0; i<arr.length-1; i++)
				pw.print(arr[i]+" ");
			pw.println(arr[arr.length-1]);
		}
		public void println(long[] arr) throws IOException{
			for(int i=0; i<arr.length-1; i++)
				pw.print(arr[i]+" ");
			pw.println(arr[arr.length-1]);
		}
		public void println(Long[] arr) throws IOException{
			for(int i=0; i<arr.length-1; i++)
				pw.print(arr[i]+" ");
			pw.println(arr[arr.length-1]);
		}
		public void println(char[] arr) throws IOException{
			for(int i=0; i<arr.length-1; i++)
				pw.print(arr[i]+" ");
			pw.println(arr[arr.length-1]);
		}
		public void println(Character[] arr) throws IOException{
			for(int i=0; i<arr.length-1; i++)
				pw.print(arr[i]+" ");
			pw.println(arr[arr.length-1]);
		}
		public void println(ArrayList<Integer> arr) throws IOException{
			for(int i=0; i<arr.size()-1; i++)
				pw.print(arr.get(i)+" ");
			pw.println(arr.get(arr.size()-1));
		}
		public void println(TreeSet<Integer> arr) throws IOException{
			for(int x: arr) {
				pw.print(x+" ");
			}
		}
		public void close() throws IOException{
			pw.close();
		}
		public void flush() throws IOException{
			pw.flush();
		}
	}
	static class Pair implements Comparable<Pair>{
		int x;
		int y;
		public Pair(int a, int b) {
			this.x=a;
			this.y=b;
		}
		public int compareTo(Pair other) {
			return -1*(this.y-other.y);
		}
	}
	static class Triple implements Comparable<Triple>{
		int x;
		int y;
		boolean d;
		public Triple(int a, int b, boolean t) {
			this.x=a;
			this.y=b;
			this.d=t;
		}
		public int compareTo(Triple other) {
			if(this.d && !other.d) {
				return 1;
			}else if(!this.d && other.d) {
				return -1;
			}else {
				return this.y-other.y;
			}
		}
	}
}


import java.io.*;
import java.util.*;
public class code {
	static printer pw;
	static boolean[] visit;
	static ArrayList<Pair>[] adj;
	static ArrayList<Integer> list;
	static long max=01;
	static void dfs(int i, long c) {
		visit[i]=true;
		max=Math.max(c, max);
		for(Pair p: adj[i]) {
			if(!visit[p.x-1]) {
				dfs(p.x-1, c+1l*p.y);
			}
		}
	}
	public static double dist(Pair a, Pair b) {
		return Math.sqrt((a.x-b.x)*(a.x-b.x)+ (a.y-b.y)*(a.y-b.y));
	}
	public static boolean sign(int x) {
		return x>0;
	}
	static long ceildiv(long x,long y) {
		return x%y==0? x/y: x/y+1;
	}
	public static void main(String[] args) throws Exception {
		Scanner sc= new Scanner(System.in);
		pw = new printer();
		int t=sc.nextInt();
		while(t-->0) {
			int n=sc.nextInt(),k=sc.nextInt();
			String s=sc.next();
			Character[] arr=new Character[n];
			for(int i=0; i<n; i++) {
				arr[i]=s.charAt(i);
			}
			Arrays.sort(arr);
			int a=n/k,b=n/k+1;
			int x=n%k;
			PriorityQueue<String> set=new PriorityQueue<String>(Collections.reverseOrder());
			int i=0,j=n-1;
			int tempk=k;
			while(x-->0) {
				int w=b/2;
				StringBuilder sb=new StringBuilder();
				int lim=i+w;
				for(;i<lim; i++) {
					sb.append(arr[i]);
				}
				lim=j-(b-w);
				int tempj=lim;
				lim++;
				for(;j>=lim; lim++) {
					sb.append(arr[lim]);
				}
				j=tempj;
				set.add(sb.toString());
				k--;
			}
			while(k-->0) {
				int w=a/2;
				StringBuilder sb=new StringBuilder();
				int lim=i+w;
				for(;i<lim; i++) {
					sb.append(arr[i]);
				}
				lim=j-(a-w);
				int tempj=lim;
				lim++;
				for(;j>=lim; lim++) {
					sb.append(arr[lim]);
				}
				j=tempj;
				set.add(sb.toString());
			}
			PriorityQueue<String> pq=new PriorityQueue<String>(Collections.reverseOrder());
			i=1;j=n-1;
			b=n-(tempk-1);
			StringBuilder sb=new StringBuilder();
			sb.append(arr[0]);
			int lim=j-(b-1)+1;
			int tempj=lim-1;
			for(;j>=lim; lim++) {
				sb.append(arr[lim]);
			}
			j=tempj;
			pq.add(sb.toString());
			k--;
			for(;i<=j; i++) {
				pq.add(arr[i]+"");
			}
			String f=pq.poll(),l=set.poll();
			pw.println(f.compareTo(l)<0? f:l);
		}
		pw.close();
	}
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(FileReader r) {
			br = new BufferedReader(r);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextArr(int n) throws IOException {
			int[] arr = new int[n];
			for (int i = 0; i < arr.length; i++)
				arr[i] = nextInt();
			return arr;
		}
		public Integer[] nextsort(int n) throws IOException{
			Integer[] arr=new Integer[n];
			for(int i=0; i<n; i++)
				arr[i]=nextInt();
			return arr;
		}
		public boolean ready() throws IOException {
			return br.ready();
		}
	}
	static class printer{
		PrintWriter pw;
		public printer() {
			pw=new PrintWriter(System.out);
		}
		public void print(String s) throws IOException{
			pw.print(s);
		}
		public void print(int s) throws IOException{
			pw.print(s);
		}
		public void print(long s) throws IOException{
			pw.print(s);
		}
		public void print(char s) throws IOException{
			pw.print(s);
		}
		public void print(Integer s) throws IOException{
			pw.print(s);
		}
		public void print(Long s) throws IOException{
			pw.print(s);
		}
		public void print(Character s) throws IOException{
			pw.print(s);
		}
		public void println(String s) throws IOException{
			pw.println(s);
		}
		public void println(int s) throws IOException{
			pw.println(s);
		}
		public void println(long s) throws IOException{
			pw.println(s);
		}
		public void println(char s) throws IOException{
			pw.println(s);
		}
		public void println(Integer s) throws IOException{
			pw.println(s);
		}
		public void println(Long s) throws IOException{
			pw.println(s);
		}
		public void println(Character s) throws IOException{
			pw.println(s);
		}
		public void println() throws IOException{
			pw.println();
		}
		public void println(int[] arr) throws IOException{
			for(int i=0; i<arr.length-1; i++)
				pw.print(arr[i]+" ");
			pw.println(arr[arr.length-1]);
		}
		public void println(Integer[] arr) throws IOException{
			for(int i=0; i<arr.length-1; i++)
				pw.print(arr[i]+" ");
			pw.println(arr[arr.length-1]);
		}
		public void println(long[] arr) throws IOException{
			for(int i=0; i<arr.length-1; i++)
				pw.print(arr[i]+" ");
			pw.println(arr[arr.length-1]);
		}
		public void println(Long[] arr) throws IOException{
			for(int i=0; i<arr.length-1; i++)
				pw.print(arr[i]+" ");
			pw.println(arr[arr.length-1]);
		}
		public void println(char[] arr) throws IOException{
			for(int i=0; i<arr.length-1; i++)
				pw.print(arr[i]+" ");
			pw.println(arr[arr.length-1]);
		}
		public void println(Character[] arr) throws IOException{
			for(int i=0; i<arr.length-1; i++)
				pw.print(arr[i]+" ");
			pw.println(arr[arr.length-1]);
		}
		public void println(ArrayList<Integer> arr) throws IOException{
			for(int i=0; i<arr.size()-1; i++)
				pw.print(arr.get(i)+" ");
			pw.println(arr.get(arr.size()-1));
		}
		public void println(TreeSet<Integer> arr) throws IOException{
			for(int x: arr) {
				pw.print(x+" ");
			}
		}
		public void close() throws IOException{
			pw.close();
		}
		public void flush() throws IOException{
			pw.flush();
		}
	}
	static class Pair implements Comparable<Pair>{
		int x;
		int y;
		public Pair(int a, int b) {
			this.x=a;
			this.y=b;
		}
		public int compareTo(Pair other) {
			return -1*(this.y-other.y);
		}
	}
	static class Triple implements Comparable<Triple>{
		int x;
		int y;
		boolean d;
		public Triple(int a, int b, boolean t) {
			this.x=a;
			this.y=b;
			this.d=t;
		}
		public int compareTo(Triple other) {
			if(this.d && !other.d) {
				return 1;
			}else if(!this.d && other.d) {
				return -1;
			}else {
				return this.y-other.y;
			}
		}
	}
}


import java.io.*;
import java.util.*;
public class code {
	static printer pw;
	static boolean[] visit;
	static ArrayList<Pair>[] adj;
	static ArrayList<Integer> list;
	static long max=01;
	static void dfs(int i, long c) {
		visit[i]=true;
		max=Math.max(c, max);
		for(Pair p: adj[i]) {
			if(!visit[p.x-1]) {
				dfs(p.x-1, c+1l*p.y);
			}
		}
	}
	public static double dist(Pair a, Pair b) {
		return Math.sqrt((a.x-b.x)*(a.x-b.x)+ (a.y-b.y)*(a.y-b.y));
	}
	public static boolean sign(int x) {
		return x>0;
	}
	static long ceildiv(long x,long y) {
		return x%y==0? x/y: x/y+1;
	}
	public static void main(String[] args) throws Exception {
		Scanner sc= new Scanner(System.in);
		pw = new printer();
		int t=sc.nextInt();
		while(t-->0) {
			int n=sc.nextInt(),k=sc.nextInt();
			String s=sc.next();
			Character[] arr=new Character[n];
			for(int i=0; i<n; i++) {
				arr[i]=s.charAt(i);
			}
			Arrays.sort(arr);
			int a=n/k,b=n/k+1;
			int x=n%k;
			PriorityQueue<String> set=new PriorityQueue<String>(Collections.reverseOrder());
			int i=0,j=n-1;
			int tempk=k;
			int tempx=x;
			while(x-->0) {
				int w=1;
				StringBuilder sb=new StringBuilder();
				int lim=i+w;
				for(;i<lim; i++) {
					sb.append(arr[i]);
				}
				lim=j-(b-w);
				int tempj=lim;
				lim++;
				for(;j>=lim; lim++) {
					sb.append(arr[lim]);
				}
				j=tempj;
				set.add(sb.toString());
				k--;
			}
			while(k-->0) {
				int w=1;
				StringBuilder sb=new StringBuilder();
				int lim=i+w;
				for(;i<lim; i++) {
					sb.append(arr[i]);
				}
				lim=j-(a-w);
				int tempj=lim;
				lim++;
				for(;j>=lim; lim++) {
					sb.append(arr[lim]);
				}
				j=tempj;
				set.add(sb.toString());
			}
			x=tempx;
			k=tempk;
			PriorityQueue<String> prior=new PriorityQueue<String>(Collections.reverseOrder());
			i=0;j=n-1;
			while(x-->0) {
				int w=b/2;
				StringBuilder sb=new StringBuilder();
				int lim=i+w;
				for(;i<lim; i++) {
					sb.append(arr[i]);
				}
				lim=j-(b-w);
				int tempj=lim;
				lim++;
				for(;j>=lim; lim++) {
					sb.append(arr[lim]);
				}
				j=tempj;
				prior.add(sb.toString());
				k--;
			}
			while(k-->0) {
				int w=a/2;
				StringBuilder sb=new StringBuilder();
				int lim=i+w;
				for(;i<lim; i++) {
					sb.append(arr[i]);
				}
				lim=j-(a-w);
				int tempj=lim;
				lim++;
				for(;j>=lim; lim++) {
					sb.append(arr[lim]);
				}
				j=tempj;
				prior.add(sb.toString());
			}
			PriorityQueue<String> pq=new PriorityQueue<String>(Collections.reverseOrder());
			i=1;j=n-1;
			b=n-(tempk-1);
			StringBuilder sb=new StringBuilder();
			sb.append(arr[0]);
			int lim=j-(b-1)+1;
			int tempj=lim-1;
			for(;j>=lim; lim++) {
				sb.append(arr[lim]);
			}
			j=tempj;
			pq.add(sb.toString());
			k--;
			for(;i<=j; i++) {
				pq.add(arr[i]+"");
			}
			PriorityQueue<String> ans=new PriorityQueue<String>();
			ans.add(pq.poll());ans.add(set.poll());ans.add(prior.poll());
			pw.println(ans.poll());
		}
		pw.close();
	}
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(FileReader r) {
			br = new BufferedReader(r);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextArr(int n) throws IOException {
			int[] arr = new int[n];
			for (int i = 0; i < arr.length; i++)
				arr[i] = nextInt();
			return arr;
		}
		public Integer[] nextsort(int n) throws IOException{
			Integer[] arr=new Integer[n];
			for(int i=0; i<n; i++)
				arr[i]=nextInt();
			return arr;
		}
		public boolean ready() throws IOException {
			return br.ready();
		}
	}
	static class printer{
		PrintWriter pw;
		public printer() {
			pw=new PrintWriter(System.out);
		}
		public void print(String s) throws IOException{
			pw.print(s);
		}
		public void print(int s) throws IOException{
			pw.print(s);
		}
		public void print(long s) throws IOException{
			pw.print(s);
		}
		public void print(char s) throws IOException{
			pw.print(s);
		}
		public void print(Integer s) throws IOException{
			pw.print(s);
		}
		public void print(Long s) throws IOException{
			pw.print(s);
		}
		public void print(Character s) throws IOException{
			pw.print(s);
		}
		public void println(String s) throws IOException{
			pw.println(s);
		}
		public void println(int s) throws IOException{
			pw.println(s);
		}
		public void println(long s) throws IOException{
			pw.println(s);
		}
		public void println(char s) throws IOException{
			pw.println(s);
		}
		public void println(Integer s) throws IOException{
			pw.println(s);
		}
		public void println(Long s) throws IOException{
			pw.println(s);
		}
		public void println(Character s) throws IOException{
			pw.println(s);
		}
		public void println() throws IOException{
			pw.println();
		}
		public void println(int[] arr) throws IOException{
			for(int i=0; i<arr.length-1; i++)
				pw.print(arr[i]+" ");
			pw.println(arr[arr.length-1]);
		}
		public void println(Integer[] arr) throws IOException{
			for(int i=0; i<arr.length-1; i++)
				pw.print(arr[i]+" ");
			pw.println(arr[arr.length-1]);
		}
		public void println(long[] arr) throws IOException{
			for(int i=0; i<arr.length-1; i++)
				pw.print(arr[i]+" ");
			pw.println(arr[arr.length-1]);
		}
		public void println(Long[] arr) throws IOException{
			for(int i=0; i<arr.length-1; i++)
				pw.print(arr[i]+" ");
			pw.println(arr[arr.length-1]);
		}
		public void println(char[] arr) throws IOException{
			for(int i=0; i<arr.length-1; i++)
				pw.print(arr[i]+" ");
			pw.println(arr[arr.length-1]);
		}
		public void println(Character[] arr) throws IOException{
			for(int i=0; i<arr.length-1; i++)
				pw.print(arr[i]+" ");
			pw.println(arr[arr.length-1]);
		}
		public void println(ArrayList<Integer> arr) throws IOException{
			for(int i=0; i<arr.size()-1; i++)
				pw.print(arr.get(i)+" ");
			pw.println(arr.get(arr.size()-1));
		}
		public void println(TreeSet<Integer> arr) throws IOException{
			for(int x: arr) {
				pw.print(x+" ");
			}
		}
		public void close() throws IOException{
			pw.close();
		}
		public void flush() throws IOException{
			pw.flush();
		}
	}
	static class Pair implements Comparable<Pair>{
		int x;
		int y;
		public Pair(int a, int b) {
			this.x=a;
			this.y=b;
		}
		public int compareTo(Pair other) {
			return -1*(this.y-other.y);
		}
	}
	static class Triple implements Comparable<Triple>{
		int x;
		int y;
		boolean d;
		public Triple(int a, int b, boolean t) {
			this.x=a;
			this.y=b;
			this.d=t;
		}
		public int compareTo(Triple other) {
			if(this.d && !other.d) {
				return 1;
			}else if(!this.d && other.d) {
				return -1;
			}else {
				return this.y-other.y;
			}
		}
	}
}


import java.io.*;
import java.util.*;

import static java.lang.Double.parseDouble;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.exit;

public class Solution {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
    static boolean isLocal = false;

    int n, k;
    Character[] s;

    private int gcd(int a, int b) {
        while (b > 0) {
            int temp = b;
            b = a % b;
            a = temp;
        }
        return a;
    }

    int getGcd(int cnt[]) {
        List<Integer> count = new ArrayList<>();
        for (int i = 0; i < 26; i++) {
            if (cnt[i] > 0) {
                count.add(cnt[i]);
            }
        }
        if (count.size() <= 1) return 1;
        int gcd = count.get(0);
        for (int x : cnt) gcd = gcd(gcd, x);
        return min(k, gcd);
    }

    String get1() {
        StringBuilder sb = new StringBuilder();
        int cnt[] = new int[26];
        sb.append(s[0]);
        for (int i = k; i < n; i++) sb.append(s[i]);
        return sb.toString();
    }

    String get2() {
        StringBuilder sb[] = new StringBuilder[k];
        for (int i = 0; i < k; i++) sb[i] = new StringBuilder();
        for (int i = 0; i < n; i++) sb[i % k].append(s[i]);
        String[] ans = new String[k];
        for (int i = 0; i < k; i++) ans[i] = sb[i].toString();
        Arrays.sort(ans);
        return ans[k - 1].toString();
    }

    void Case() throws IOException {
        n = nextInt();
        k = nextInt();
        char[] tmp = next().toCharArray();
        s = new Character[n];
        for (int i = 0; i < n; i++) s[i] = tmp[i];
        Arrays.sort(s);
        if (s[k - 1] != s[0]) {
            out.println(s[k - 1]);
            return;
        }
        String[] ans = {get1(), get2()};
        Arrays.sort(ans);
        out.println(ans[0]);
    }

    void solve() throws Exception {
        int t = nextInt();
        for (int i = 1; i <= t; i++) {
            Case();
            out.flush();
        }
    }

    int min(int x, int y) {
        return Integer.min(x, y);
    }

    int max(int x, int y) {
        return Integer.max(x, y);
    }

    long min(long x, long y) {
        return Long.min(x, y);
    }

    long max(long x, long y) {
        return Long.max(x, y);
    }

    int[] sort(int[] arr) {
        sort(arr, 0, arr.length - 1);
        return arr;
    }

    void sort(int arr[], int l, int r) {
        if (l < r) {
            int m = (l + r) / 2;
            sort(arr, l, m);
            sort(arr, m + 1, r);
            merge(arr, l, m, r);
        }
    }

    void merge(int arr[], int l, int m, int r) {
        int n1 = m - l + 1;
        int n2 = r - m;
        int L[] = new int[n1];
        int R[] = new int[n2];
        for (int i = 0; i < n1; ++i)
            L[i] = arr[l + i];
        for (int j = 0; j < n2; ++j)
            R[j] = arr[m + 1 + j];
        int i = 0, j = 0;
        int k = l;
        while (i < n1 && j < n2) {
            if (L[i] <= R[j]) {
                arr[k] = L[i];
                i++;
            } else {
                arr[k] = R[j];
                j++;
            }
            k++;
        }
        while (i < n1) {
            arr[k] = L[i];
            i++;
            k++;
        }
        while (j < n2) {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    class Seg implements Comparable<Seg> {
        int st, end;

        public Seg(int st, int end) {
            this.st = st;
            this.end = end;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Seg seg = (Seg) o;
            return st == seg.st &&
                    end == seg.end;
        }

        @Override
        public int hashCode() {
            return Objects.hash(st, end);
        }

        @Override
        public int compareTo(Seg seg) {
            return st == seg.st ? Integer.compare(end, seg.end) : Integer.compare(st, seg.st);
        }
    }

    private int[] na(int n) throws IOException {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = nextInt();
        return a;
    }

    private long[] nal(int n) throws IOException {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) a[i] = nextLong();
        return a;
    }

    int nextInt() throws IOException {
        return parseInt(next());
    }

    long nextLong() throws IOException {
        return parseLong(next());
    }

    double nextDouble() throws IOException {
        return parseDouble(next());
    }

    String next() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    public static void main(String[] args) throws Exception {
        try {
            if (isLocal) {
                in = new BufferedReader(new FileReader("src/tests/sol.in"));
                out = new PrintWriter(new BufferedWriter(new FileWriter("src/tests/sol.out")));
            } else {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(new OutputStreamWriter(System.out));
            }
//            long lStartTime = System.currentTimeMillis();
            new Solution().solve();
//            long lEndTime = System.currentTimeMillis();
//            out.println("Elapsed time in seconds: " + (double) (lEndTime - lStartTime) / 1000.0);
            in.close();
            out.close();
        } catch (Throwable e) {
            e.printStackTrace();
            exit(1);
        }
    }
}


import java.io.*;
import java.util.*;

import static java.lang.Double.parseDouble;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.exit;

public class Solution {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
    static boolean isLocal = false;

    int n, k;
    Character[] s;

    private int gcd(int a, int b) {
        while (b > 0) {
            int temp = b;
            b = a % b;
            a = temp;
        }
        return a;
    }

    int getGcd(int cnt[]) {
        List<Integer> count = new ArrayList<>();
        for (int i = 0; i < 26; i++) {
            if (cnt[i] > 0) {
                count.add(cnt[i]);
            }
        }
        if (count.size() <= 1) return 1;
        int gcd = count.get(0);
        for (int x : cnt) gcd = gcd(gcd, x);
        return min(k, gcd);
    }

    String get1() {
        StringBuilder sb = new StringBuilder();
        int cnt[] = new int[26];
        for (int i = 0; i < n; i++) cnt[s[i] - 'a']++;
        for (int i = 0; i < 26; i++) {
            if (cnt[i] > 0) {
                sb.append((char) (i + 'a'));
                cnt[i] -= k;
                break;
            }
        }
        int gcd = getGcd(cnt);
        for (int i = 0; i < 26; i++) {
            if (cnt[i] > 0) {
                for (int j = 0; j < cnt[i] / gcd; j++) sb.append((char) (i + 'a'));
            }
        }
        return sb.toString();
    }

    String get2() {
        char z = 'z';
        z++;
        if (true) return "" + z;
        StringBuilder sb[] = new StringBuilder[k];
        for (int i = 0; i < k; i++) sb[i] = new StringBuilder();
        for (int i = 0; i < n; i++) sb[i % k].append(s[i]);
        Arrays.sort(sb);
        return sb[k - 1].toString();
    }

    void Case() throws IOException {
        n = nextInt();
        k = nextInt();
        char[] tmp = next().toCharArray();
        s = new Character[n];
        for (int i = 0; i < n; i++) s[i] = tmp[i];
        Arrays.sort(s);
        if (s[k - 1] != s[0]) {
            out.println(s[k - 1]);
            return;
        }
        String[] ans = {get1(), get2()};
        Arrays.sort(ans);
        out.println(ans[0]);
    }

    void solve() throws Exception {
        int t = nextInt();
        for (int i = 1; i <= t; i++) {
            Case();
            out.flush();
        }
    }

    int min(int x, int y) {
        return Integer.min(x, y);
    }

    int max(int x, int y) {
        return Integer.max(x, y);
    }

    long min(long x, long y) {
        return Long.min(x, y);
    }

    long max(long x, long y) {
        return Long.max(x, y);
    }

    int[] sort(int[] arr) {
        sort(arr, 0, arr.length - 1);
        return arr;
    }

    void sort(int arr[], int l, int r) {
        if (l < r) {
            int m = (l + r) / 2;
            sort(arr, l, m);
            sort(arr, m + 1, r);
            merge(arr, l, m, r);
        }
    }

    void merge(int arr[], int l, int m, int r) {
        int n1 = m - l + 1;
        int n2 = r - m;
        int L[] = new int[n1];
        int R[] = new int[n2];
        for (int i = 0; i < n1; ++i)
            L[i] = arr[l + i];
        for (int j = 0; j < n2; ++j)
            R[j] = arr[m + 1 + j];
        int i = 0, j = 0;
        int k = l;
        while (i < n1 && j < n2) {
            if (L[i] <= R[j]) {
                arr[k] = L[i];
                i++;
            } else {
                arr[k] = R[j];
                j++;
            }
            k++;
        }
        while (i < n1) {
            arr[k] = L[i];
            i++;
            k++;
        }
        while (j < n2) {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    class Seg implements Comparable<Seg> {
        int st, end;

        public Seg(int st, int end) {
            this.st = st;
            this.end = end;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Seg seg = (Seg) o;
            return st == seg.st &&
                    end == seg.end;
        }

        @Override
        public int hashCode() {
            return Objects.hash(st, end);
        }

        @Override
        public int compareTo(Seg seg) {
            return st == seg.st ? Integer.compare(end, seg.end) : Integer.compare(st, seg.st);
        }
    }

    private int[] na(int n) throws IOException {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = nextInt();
        return a;
    }

    private long[] nal(int n) throws IOException {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) a[i] = nextLong();
        return a;
    }

    int nextInt() throws IOException {
        return parseInt(next());
    }

    long nextLong() throws IOException {
        return parseLong(next());
    }

    double nextDouble() throws IOException {
        return parseDouble(next());
    }

    String next() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    public static void main(String[] args) throws Exception {
        try {
            if (isLocal) {
                in = new BufferedReader(new FileReader("src/tests/sol.in"));
                out = new PrintWriter(new BufferedWriter(new FileWriter("src/tests/sol.out")));
            } else {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(new OutputStreamWriter(System.out));
            }
//            long lStartTime = System.currentTimeMillis();
            new Solution().solve();
//            long lEndTime = System.currentTimeMillis();
//            out.println("Elapsed time in seconds: " + (double) (lEndTime - lStartTime) / 1000.0);
            in.close();
            out.close();
        } catch (Throwable e) {
            e.printStackTrace();
            exit(1);
        }
    }
}


import java.io.*;
import java.util.*;

import static java.lang.Double.parseDouble;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.exit;

public class Solution {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
    static boolean isLocal = false;

    int n, k;
    Character[] s;

    private int gcd(int a, int b) {
        while (b > 0) {
            int temp = b;
            b = a % b;
            a = temp;
        }
        return a;
    }

    int getGcd(int cnt[]) {
        List<Integer> count = new ArrayList<>();
        for (int i = 0; i < 26; i++) {
            if (cnt[i] > 0) {
                count.add(cnt[i]);
            }
        }
        if (count.size() <= 1) return 1;
        int gcd = count.get(0);
        for (int x : cnt) gcd = gcd(gcd, x);
        return min(k, gcd);
    }

    String get1() {
        StringBuilder sb = new StringBuilder();
        int cnt[] = new int[26];
        for (int i = 0; i < n; i++) cnt[s[i] - 'a']++;
        for (int i = 0; i < 26; i++) {
            if (cnt[i] > 0) {
                sb.append((char) (i + 'a'));
                cnt[i] -= k;
                break;
            }
        }
        int gcd = getGcd(cnt);
        for (int i = 0; i < 26; i++) {
            if (cnt[i] > 0) {
                for (int j = 0; j < cnt[i] / gcd; j++) sb.append((char) (i + 'a'));
            }
        }
        return sb.toString();
    }

    String get2() {
        StringBuilder sb[] = new StringBuilder[k];
        for (int i = 0; i < k; i++) sb[i] = new StringBuilder();
        for (int i = 0; i < n; i++) sb[i % k].append(s[i]);
        Arrays.sort(sb);
        return sb[k - 1].toString();
    }

    void Case() throws IOException {
        n = nextInt();
        k = nextInt();
        char[] tmp = next().toCharArray();
        s = new Character[n];
        for (int i = 0; i < n; i++) s[i] = tmp[i];
        Arrays.sort(s);
        if (s[k - 1] != s[0]) {
            out.println(s[k - 1]);
            return;
        }
        String[] ans = {get1(), get2()};
        Arrays.sort(ans);
        out.println(ans[0]);
    }

    void solve() throws Exception {
        int t = nextInt();
        for (int i = 1; i <= t; i++) {
            Case();
            out.flush();
        }
    }

    int min(int x, int y) {
        return Integer.min(x, y);
    }

    int max(int x, int y) {
        return Integer.max(x, y);
    }

    long min(long x, long y) {
        return Long.min(x, y);
    }

    long max(long x, long y) {
        return Long.max(x, y);
    }

    int[] sort(int[] arr) {
        sort(arr, 0, arr.length - 1);
        return arr;
    }

    void sort(int arr[], int l, int r) {
        if (l < r) {
            int m = (l + r) / 2;
            sort(arr, l, m);
            sort(arr, m + 1, r);
            merge(arr, l, m, r);
        }
    }

    void merge(int arr[], int l, int m, int r) {
        int n1 = m - l + 1;
        int n2 = r - m;
        int L[] = new int[n1];
        int R[] = new int[n2];
        for (int i = 0; i < n1; ++i)
            L[i] = arr[l + i];
        for (int j = 0; j < n2; ++j)
            R[j] = arr[m + 1 + j];
        int i = 0, j = 0;
        int k = l;
        while (i < n1 && j < n2) {
            if (L[i] <= R[j]) {
                arr[k] = L[i];
                i++;
            } else {
                arr[k] = R[j];
                j++;
            }
            k++;
        }
        while (i < n1) {
            arr[k] = L[i];
            i++;
            k++;
        }
        while (j < n2) {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    class Seg implements Comparable<Seg> {
        int st, end;

        public Seg(int st, int end) {
            this.st = st;
            this.end = end;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Seg seg = (Seg) o;
            return st == seg.st &&
                    end == seg.end;
        }

        @Override
        public int hashCode() {
            return Objects.hash(st, end);
        }

        @Override
        public int compareTo(Seg seg) {
            return st == seg.st ? Integer.compare(end, seg.end) : Integer.compare(st, seg.st);
        }
    }

    private int[] na(int n) throws IOException {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = nextInt();
        return a;
    }

    private long[] nal(int n) throws IOException {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) a[i] = nextLong();
        return a;
    }

    int nextInt() throws IOException {
        return parseInt(next());
    }

    long nextLong() throws IOException {
        return parseLong(next());
    }

    double nextDouble() throws IOException {
        return parseDouble(next());
    }

    String next() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    public static void main(String[] args) throws Exception {
        try {
            if (isLocal) {
                in = new BufferedReader(new FileReader("src/tests/sol.in"));
                out = new PrintWriter(new BufferedWriter(new FileWriter("src/tests/sol.out")));
            } else {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(new OutputStreamWriter(System.out));
            }
//            long lStartTime = System.currentTimeMillis();
            new Solution().solve();
//            long lEndTime = System.currentTimeMillis();
//            out.println("Elapsed time in seconds: " + (double) (lEndTime - lStartTime) / 1000.0);
            in.close();
            out.close();
        } catch (Throwable e) {
            e.printStackTrace();
            exit(1);
        }
    }
}


import java.io.*;
import java.util.*;

import static java.lang.Double.parseDouble;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.exit;

public class Solution {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
    static boolean isLocal = false;

    int n, k;
    Character[] s;

    private int gcd(int a, int b) {
        while (b > 0) {
            int temp = b;
            b = a % b;
            a = temp;
        }
        return a;
    }

    int getGcd(int cnt[]) {
        List<Integer> count = new ArrayList<>();
        for (int i = 0; i < 26; i++) {
            if (cnt[i] > 0) {
                count.add(cnt[i]);
            }
        }
        if (count.size() <= 1) return 1;
        int gcd = count.get(0);
        for (int x : cnt) gcd = gcd(gcd, x);
        return min(k, gcd);
    }

    String get1() {
        StringBuilder sb = new StringBuilder();
        int cnt[] = new int[26];
        for (int i = 0; i < n; i++) cnt[s[i] - 'a']++;
        for (int i = 0; i < 26; i++) {
            if (cnt[i] > 0) {
                sb.append((char) (i + 'a'));
                cnt[i] -= k;
                break;
            }
        }
        int gcd = getGcd(cnt);
        for (int i = 0; i < 26; i++) {
            if (cnt[i] > 0) {
                for (int j = 0; j < cnt[i] / gcd; j++) sb.append((char) (i + 'a'));
            }
        }
        return sb.toString();
    }

    String get2() {
        char z = 'z';
        z++;

        StringBuilder sb[] = new StringBuilder[k];
        for (int i = 0; i < k; i++) sb[i] = new StringBuilder();
        for (int i = 0; i < n; i++) sb[i % k].append(s[i]);

        Arrays.sort(sb);
        if (true) return "" + z;
        return sb[k - 1].toString();
    }

    void Case() throws IOException {
        n = nextInt();
        k = nextInt();
        char[] tmp = next().toCharArray();
        s = new Character[n];
        for (int i = 0; i < n; i++) s[i] = tmp[i];
        Arrays.sort(s);
        if (s[k - 1] != s[0]) {
            out.println(s[k - 1]);
            return;
        }
        String[] ans = {get1(), get2()};
        Arrays.sort(ans);
        out.println(ans[0]);
    }

    void solve() throws Exception {
        int t = nextInt();
        for (int i = 1; i <= t; i++) {
            Case();
            out.flush();
        }
    }

    int min(int x, int y) {
        return Integer.min(x, y);
    }

    int max(int x, int y) {
        return Integer.max(x, y);
    }

    long min(long x, long y) {
        return Long.min(x, y);
    }

    long max(long x, long y) {
        return Long.max(x, y);
    }

    int[] sort(int[] arr) {
        sort(arr, 0, arr.length - 1);
        return arr;
    }

    void sort(int arr[], int l, int r) {
        if (l < r) {
            int m = (l + r) / 2;
            sort(arr, l, m);
            sort(arr, m + 1, r);
            merge(arr, l, m, r);
        }
    }

    void merge(int arr[], int l, int m, int r) {
        int n1 = m - l + 1;
        int n2 = r - m;
        int L[] = new int[n1];
        int R[] = new int[n2];
        for (int i = 0; i < n1; ++i)
            L[i] = arr[l + i];
        for (int j = 0; j < n2; ++j)
            R[j] = arr[m + 1 + j];
        int i = 0, j = 0;
        int k = l;
        while (i < n1 && j < n2) {
            if (L[i] <= R[j]) {
                arr[k] = L[i];
                i++;
            } else {
                arr[k] = R[j];
                j++;
            }
            k++;
        }
        while (i < n1) {
            arr[k] = L[i];
            i++;
            k++;
        }
        while (j < n2) {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    class Seg implements Comparable<Seg> {
        int st, end;

        public Seg(int st, int end) {
            this.st = st;
            this.end = end;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Seg seg = (Seg) o;
            return st == seg.st &&
                    end == seg.end;
        }

        @Override
        public int hashCode() {
            return Objects.hash(st, end);
        }

        @Override
        public int compareTo(Seg seg) {
            return st == seg.st ? Integer.compare(end, seg.end) : Integer.compare(st, seg.st);
        }
    }

    private int[] na(int n) throws IOException {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = nextInt();
        return a;
    }

    private long[] nal(int n) throws IOException {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) a[i] = nextLong();
        return a;
    }

    int nextInt() throws IOException {
        return parseInt(next());
    }

    long nextLong() throws IOException {
        return parseLong(next());
    }

    double nextDouble() throws IOException {
        return parseDouble(next());
    }

    String next() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    public static void main(String[] args) throws Exception {
        try {
            if (isLocal) {
                in = new BufferedReader(new FileReader("src/tests/sol.in"));
                out = new PrintWriter(new BufferedWriter(new FileWriter("src/tests/sol.out")));
            } else {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(new OutputStreamWriter(System.out));
            }
//            long lStartTime = System.currentTimeMillis();
            new Solution().solve();
//            long lEndTime = System.currentTimeMillis();
//            out.println("Elapsed time in seconds: " + (double) (lEndTime - lStartTime) / 1000.0);
            in.close();
            out.close();
        } catch (Throwable e) {
            e.printStackTrace();
            exit(1);
        }
    }
}