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

  public class B {

	InputStream is;
	static PrintWriter out;

	static int kmp(char txt[],char pat[],int k)
	{
		//char pat[]=pattern.toCharArray();

		int n=txt.length,m=pat.length;
		int lps[]=new int[m];
		lpsc(pat,m,lps);
		int i=0,j=0;
		int ans=-1;
		int ctr=0;
		while(i<n)
		{
			if(txt[i]==pat[j])
			{
				i++;
				j++;
			}
			if(j==m)
			{

				if((i-j+m)<=k && (i-j)!=0){
				ans=i-j;
				break;
				}
				j=lps[j-1];

			}
			else if(i<n && txt[i]!=pat[j])
			{
				if(j!=0)
					j=lps[j-1];
				else
					i=i+1;
			}
		}

		return ans;
	}

	static void lpsc(char pat[],int m,int lps[])
	{
		//char pat[]=pattern.toCharArray();
		int i=1,j=0;
		while(i<m)
		{
			if(pat[i]==pat[j])
			{
				j++;
				lps[i]=j;
				i++;
			}
			else
			{
				if(j!=0)
					j=lps[j-1];
				else
					i++;
			}
		}
	}

	void solve()
	{
		int t=ni();
		while(t-->0)
		{
			int n=ni(),k=ni();
			char ch[]=ns().toCharArray();
			Arrays.sort(ch);
			String s=String.valueOf(ch);

			String s1="",s2="";

			int f=0;
			for(int i=1;i<k;i++)
			{
				if(ch[i]!=ch[i-1]){
					f=1;break;}
			}

			if(f==1)
				out.println(ch[k-1]);
			else
			{
				String a[]=new String[k];
				Arrays.fill(a,"");
				for(int i=0;i<n;i++)
				{
					a[i%k]+=ch[i];
				}
				Arrays.sort(a);
				s1=a[k-1];
				s2=s.substring(k-1,n);
				//out.println(s1+" "+s2);
				if(s1.compareTo(s2)<=0)
					out.println(s1);
				else
					out.println(s2);

			}

		}
	}

    //---------- I/O Template ----------

    public static void main(String[] args) { new B().run(); }
    void run() {
        is = System.in;
        out = new PrintWriter(System.out);
        solve();
        out.flush();
    }

    byte input[] = new byte[1024];
    int len = 0, ptr = 0;

    int readByte() {
        if(ptr >= len) { ptr = 0;
            try { len = is.read(input); }
            catch(IOException e) { throw new InputMismatchException(); }
            if(len <= 0) { return -1; }
        } return input[ptr++];
    }
    boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }
    int skip() {
        int b = readByte();
        while(b != -1 && isSpaceChar(b)) { b = readByte(); }
        return b;
    }

    char nc() { return (char)skip(); }
    String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    String nLine() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    int ni() {
        int n = 0, b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        if(b == -1) { return -1; }  //no input
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }
    long nl() {
        long n = 0L;    int b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }

    double nd() { return Double.parseDouble(ns()); }
    float nf() { return Float.parseFloat(ns()); }
    int[] na(int n) {
        int a[] = new int[n];
        for(int i = 0; i < n; i++) { a[i] = ni(); }
        return a;
    }
    char[] ns(int n) {
        char c[] = new char[n];
        int i, b = skip();
        for(i = 0; i < n; i++) {
            if(isSpaceChar(b)) { break; }
            c[i] = (char)b; b = readByte();
        } return i == n ? c : Arrays.copyOf(c,i);
    }
	static void pa(int a[])
	{
		for(int i=0;i<a.length;i++)
		out.print(a[i]+" ");
		out.println();
	}
	 static void pa(long a[])
	{
		for(int i=0;i<a.length;i++)
		out.print(a[i]+" ");
		out.println();
	}

}


import java.io.*;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Random;
import java.util.StringTokenizer;

public class C {

    public static void main(String[] args) {
        FastReader scan = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
        Task solver = new Task();
        int t = scan.nextInt();
        for(int tt = 1; tt <= t; tt++) solver.solve(tt, scan, out);
        out.close();
    }

    static class Task {

        public void solve(int testNumber, FastReader scan, PrintWriter out) {
            int n = scan.nextInt(), k = scan.nextInt();
            char[] s = scan.next().toCharArray();
            shuffle(s);
            Arrays.sort(s);
            if(k == 1) out.println(new String(s));
            else {
                HashSet<Character> h = new HashSet<>();
                for(char c : s) h.add(c);
                if(h.size() == 1) {
                    int need = n / k + Math.min(1, n % k);
                    for(int i = 0; i < need; i++) out.print(s[0]);
                    out.println();
                }
                else if(s[k - 1] != s[0]){
                    out.println(s[k - 1]);
                }
                else {
                    if(h.size() == 2 && s[k] != s[0]) {
                        int[] count = new int[26];
                        for(int i = k; i < n; i++) count[s[i] - 'a']++;
                        int last = s[n - 1] - 'a';
                        int need = count[last] / k + Math.min(1, count[last] % k);
                        out.print(s[k - 1]);
                        for(int i = 0; i < need; i++) out.print(s[n - 1]);
                        out.println();
                    }
                    else {
                        for(int i = k - 1; i < n; i++) out.print(s[i]);
                        out.println();
                    }
                }
            }
        }
    }

    static void shuffle(int[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            int temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }

    static void shuffle(char[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            char temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }

    static void shuffle(long[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            long temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(new File(s)));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}


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

  public class B {

	InputStream is;
	static PrintWriter out;

	static int kmp(char txt[],char pat[],int k)
	{
		//char pat[]=pattern.toCharArray();

		int n=txt.length,m=pat.length;
		int lps[]=new int[m];
		lpsc(pat,m,lps);
		int i=0,j=0;
		int ans=-1;
		int ctr=0;
		while(i<n)
		{
			if(txt[i]==pat[j])
			{
				i++;
				j++;
			}
			if(j==m)
			{

				if((i-j+m)<=k && (i-j)!=0){
				ans=i-j;
				break;
				}
				j=lps[j-1];

			}
			else if(i<n && txt[i]!=pat[j])
			{
				if(j!=0)
					j=lps[j-1];
				else
					i=i+1;
			}
		}

		return ans;
	}

	static void lpsc(char pat[],int m,int lps[])
	{
		//char pat[]=pattern.toCharArray();
		int i=1,j=0;
		while(i<m)
		{
			if(pat[i]==pat[j])
			{
				j++;
				lps[i]=j;
				i++;
			}
			else
			{
				if(j!=0)
					j=lps[j-1];
				else
					i++;
			}
		}
	}

	void solve()
	{
		int t=ni();
		while(t-->0)
		{
			int n=ni(),k=ni();
			char ch[]=ns().toCharArray();
			Arrays.sort(ch);
			String s=String.valueOf(ch);

			String s1="",s2="";

			int f=0;
			for(int i=1;i<k;i++)
			{
				if(ch[i]!=ch[i-1]){
					f=1;break;}
			}

			if(f==1)
				out.println(ch[k-1]);
			else
			{

				String kk1="",kk2="";
				int st=0;
				if(n%k!=0)
					st=n%k-1;
				for(int i=st;i<n;i+=k)
				{
					s1+=ch[i];
				}
				/*for(int i=k-1;i<n;i+=k)
				{
					kk2+=ch[i];
				}
				if(kk1.compareTo(kk2)<=0)
					s1=kk2;
				else
					s1=kk1;*/

				s2=s.substring(k-1,n);
				//out.println(s1+" "+s2);
				if(s1.compareTo(s2)<=0)
					out.println(s1);
				else
					out.println(s2);

			}

		}
	}

    //---------- I/O Template ----------

    public static void main(String[] args) { new B().run(); }
    void run() {
        is = System.in;
        out = new PrintWriter(System.out);
        solve();
        out.flush();
    }

    byte input[] = new byte[1024];
    int len = 0, ptr = 0;

    int readByte() {
        if(ptr >= len) { ptr = 0;
            try { len = is.read(input); }
            catch(IOException e) { throw new InputMismatchException(); }
            if(len <= 0) { return -1; }
        } return input[ptr++];
    }
    boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }
    int skip() {
        int b = readByte();
        while(b != -1 && isSpaceChar(b)) { b = readByte(); }
        return b;
    }

    char nc() { return (char)skip(); }
    String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    String nLine() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    int ni() {
        int n = 0, b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        if(b == -1) { return -1; }  //no input
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }
    long nl() {
        long n = 0L;    int b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }

    double nd() { return Double.parseDouble(ns()); }
    float nf() { return Float.parseFloat(ns()); }
    int[] na(int n) {
        int a[] = new int[n];
        for(int i = 0; i < n; i++) { a[i] = ni(); }
        return a;
    }
    char[] ns(int n) {
        char c[] = new char[n];
        int i, b = skip();
        for(i = 0; i < n; i++) {
            if(isSpaceChar(b)) { break; }
            c[i] = (char)b; b = readByte();
        } return i == n ? c : Arrays.copyOf(c,i);
    }
	static void pa(int a[])
	{
		for(int i=0;i<a.length;i++)
		out.print(a[i]+" ");
		out.println();
	}
	 static void pa(long a[])
	{
		for(int i=0;i<a.length;i++)
		out.print(a[i]+" ");
		out.println();
	}

}


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class C {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();
        sc.nextLine();

        while (t-- > 0) {
            int n = sc.nextInt();
            int k = sc.nextInt();
            sc.nextLine();
            String s = sc.nextLine();
            HashMap<Character, Integer> map = initMap();
            StringBuilder[] strs = new StringBuilder[k];

            for (int i = 0; i < k; ++i) {
                strs[i] = new StringBuilder("");
            }

            for (int i = 0; i < n; ++i) {
                map.put(
                        s.charAt(i),
                        map.get(s.charAt(i)) + 1
                );
            }

            boolean f = true;
            int letters = 0;
            for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                if (entry.getValue() % k != 0) {
                    f = false;
                }
                if (entry.getValue() != 0) {
                    letters++;
                }
            }

            lab:
            if (!f) {
                int i = 0;
                int count = 0;
                boolean filled = false;
                for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                    while (entry.getValue() > 0) {
                        for (; i < strs.length; ) {
                            StringBuilder str = strs[i];
                            str.append(entry.getKey());
                            entry.setValue(entry.getValue() - 1);
                            if (i < strs.length - 1) {
                                ++i;
                            } else {
                                i = 0;
                                break;
                            }
                            if (entry.getValue() == 0)
                                break;
                        }
                        ++count;
                        if (i == 0) {
                            if (count == 1) {
                                boolean flag = true;
                                for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                    if (entryy.getKey() != strs[0].charAt(0) && entryy.getValue() > 0) {
                                        flag = false;
                                        break;
                                    }
                                }
                                StringBuilder ans = strs[0];

                                if (!flag) {
                                    if (letters == 2 && map.entrySet().stream().filter(e -> e.getValue() != 0).count() == 1) {
                                        for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                            if (entryy.getValue() > 0) {
                                                for (int j = 0; j < entryy.getValue() / k + 1; ++j) {
                                                    ans.append(entryy.getKey());
                                                }
                                            }
                                        }
                                    } else {
                                        for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                            for (int j = 0; j < entryy.getValue(); ++j) {
                                                ans.append(entryy.getKey());
                                            }
                                        }
                                    }
                                } else {
                                    for (int j = 0; j < entry.getValue() / k + 1; ++j) {
                                        ans.append(entry.getKey());
                                    }
                                }

                                System.out.println(ans);
                            } else {
                                System.out.println(strs[k - 1]);

                            }
                            break lab;
                        }
                    }
                }
            } else {
                StringBuilder ans = new StringBuilder();
                if (k == 1 || letters == 1 || (letters == 2 && map.entrySet().stream().allMatch(e -> e.getValue() == k || e.getValue() == 0))) {
                    if (k == 1) {
                        for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                            if (entry.getValue() > 0) {
                                for (int j = 0; j < entry.getValue(); ++j) {
                                    ans.append(entry.getKey());
                                }
                            }
                        }
                    } else if (letters == 1) {
                        for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                            if (entry.getValue() > 0) {
                                entry.setValue(entry.getValue() / k);
                                for (int j = 0; j < entry.getValue(); ++j) {
                                    ans.append(entry.getKey());
                                }
                            }
                        }
                    } else {
                        map.entrySet().stream().filter(e -> e.getValue() == k).forEach(e ->
                                System.out.print(e.getKey()));
                    }

                } else {
                    for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                        if (entry.getValue() > 0) {
                            entry.setValue(entry.getValue() - k);
                            ans.append(entry.getKey());
                            break;
                        }
                    }
                    for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                        for (int i = 0; i < entry.getValue() / k; ++i) {
                            ans.append(entry.getKey());
                        }
                    }
                }

                System.out.println(ans);
            }
        }
    }

    private static HashMap<Character, Integer> initMap() {
        HashMap<Character, Integer> map = new HashMap<>(26);

        for (char c = 'a'; c <= 'z'; ++c) {
            map.put(c, 0);
        }

        return map;
    }

}


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class C {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();
        sc.nextLine();

        while (t-- > 0) {
            int n = sc.nextInt();
            int k = sc.nextInt();
            sc.nextLine();
            String s = sc.nextLine();
            HashMap<Character, Integer> map = initMap();
            StringBuilder[] strs = new StringBuilder[k];

            for (int i = 0; i < k; ++i) {
                strs[i] = new StringBuilder("");
            }

            for (int i = 0; i < n; ++i) {
                map.put(
                        s.charAt(i),
                        map.get(s.charAt(i)) + 1
                );
            }

            boolean f = true;
            for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                if (entry.getValue() % k != 0) {
                    f = false;
                }
            }

            lab:
            if (!f) {
                int i = 0;
                int count = 0;
                boolean filled = false;
                for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                    while (entry.getValue() > 0) {
                        for (; i < strs.length; ) {
                            StringBuilder str = strs[i];
                            str.append(entry.getKey());
                            entry.setValue(entry.getValue() - 1);
                            if (i < strs.length - 1) {
                                ++i;
                            } else {
                                i = 0;
                                break;
                            }
                            if (entry.getValue() == 0)
                                break;
                        }
                        ++count;
                        if (i == 0) {
                            if (count == 1) {
                                boolean flag = true;
                                for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                    if (entryy.getKey() != strs[0].charAt(0) && entryy.getValue() > 0) {
                                        flag = false;
                                        break;
                                    }
                                }
                                StringBuilder ans = strs[0];

                                if(!flag){
                                    for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                        for(int j = 0; j < entryy.getValue(); ++j) {
                                            ans.append(entryy.getKey());
                                        }
                                    }
                                } else {
                                    for(int j = 0; j < entry.getValue()/k + 1; ++j) {
                                        ans.append(entry.getKey());
                                    }
                                }

                                System.out.println(ans);
                            } else {
                                System.out.println(strs[k - 1]);

                            }
                            break lab;
                        }
                    }
                }
            }else{
                    StringBuilder ans = new StringBuilder();
                    for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                        for (int i = 0; i < entry.getValue() / k; ++i) {
                            ans.append(entry.getKey());
                        }
                    }
                    System.out.println(ans);
                }
            }
        }

        private static HashMap<Character, Integer> initMap () {
            HashMap<Character, Integer> map = new HashMap<>(26);

            for (char c = 'a'; c <= 'z'; ++c) {
                map.put(c, 0);
            }

            return map;
        }

    }


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class C {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();
        sc.nextLine();

        while (t-- > 0) {
            int n = sc.nextInt();
            int k = sc.nextInt();
            sc.nextLine();
            String s = sc.nextLine();
            HashMap<Character, Integer> map = initMap();
            StringBuilder[] strs = new StringBuilder[k];

            for (int i = 0; i < k; ++i) {
                strs[i] = new StringBuilder("");
            }

            for (int i = 0; i < n; ++i) {
                map.put(
                        s.charAt(i),
                        map.get(s.charAt(i)) + 1
                );
            }

            boolean f = true;
            int letters = 0;
            for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                if (entry.getValue() % k != 0) {
                    f = false;
                } else if(entry.getValue() != 0) {
                    letters++;
                }
            }

            lab:
            if (!f) {
                int i = 0;
                int count = 0;
                boolean filled = false;
                for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                    while (entry.getValue() > 0) {
                        for (; i < strs.length;) {
                            StringBuilder str = strs[i];
                            str.append(entry.getKey());
                            entry.setValue(entry.getValue() - 1);
                            if (i < strs.length - 1) {
                                ++i;
                            } else {
                                i = 0;
                                break;
                            }
                            if (entry.getValue() == 0)
                                break;
                        }
                        ++count;
                        if (i == 0) {
                            if (count == 1) {
                                boolean flag = true;
                                for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                    if (entryy.getKey() != strs[0].charAt(0) && entryy.getValue() > 0) {
                                        flag = false;
                                        break;
                                    }
                                }
                                StringBuilder ans = strs[0];

                                if (!flag) {
                                    for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                        for (int j = 0; j < entryy.getValue(); ++j) {
                                            ans.append(entryy.getKey());
                                        }
                                    }
                                } else {
                                    for (int j = 0; j < entry.getValue() / k + 1; ++j) {
                                        ans.append(entry.getKey());
                                    }
                                }

                                System.out.println(ans);
                            } else {
                                System.out.println(strs[k - 1]);

                            }
                            break lab;
                        }
                    }
                }
            } else {
                StringBuilder ans = new StringBuilder();
                if(k == 1 || letters == 1 || (letters == 2 && map.get('a') == k && map.get('b') == k)) {
                    for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                        for (int i = 0; i < entry.getValue() / k; ++i) {
                            ans.append(entry.getKey());
                        }
                    }
                } else {
                    for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                        if (entry.getValue() > 0) {
                            entry.setValue(entry.getValue() - k);
                            ans.append(entry.getKey());
                            break;
                        }
                    }
                    for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                        for (int i = 0; i < entry.getValue(); ++i) {
                            ans.append(entry.getKey());
                        }
                    }
                }

                System.out.println(ans);
            }
        }
    }

    private static HashMap<Character, Integer> initMap() {
        HashMap<Character, Integer> map = new HashMap<>(26);

        for (char c = 'a'; c <= 'z'; ++c) {
            map.put(c, 0);
        }

        return map;
    }

}


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class C {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();
        sc.nextLine();

        while (t-- > 0) {
            int n = sc.nextInt();
            int k = sc.nextInt();
            sc.nextLine();
            String s = sc.nextLine();
            HashMap<Character, Integer> map = initMap();
            StringBuilder[] strs = new StringBuilder[k];

            for (int i = 0; i < k; ++i) {
                strs[i] = new StringBuilder("");
            }

            for (int i = 0; i < n; ++i) {
                map.put(
                        s.charAt(i),
                        map.get(s.charAt(i)) + 1
                );
            }

            boolean f = true;
            int letters = 0;
            for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                if (entry.getValue() % k != 0) {
                    f = false;
                }
                if (entry.getValue() != 0) {
                    letters++;
                }
            }

            lab:
            if (!f) {
                int i = 0;
                int count = 0;
                boolean filled = false;
                for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                    while (entry.getValue() > 0) {
                        for (; i < strs.length; ) {
                            StringBuilder str = strs[i];
                            str.append(entry.getKey());
                            entry.setValue(entry.getValue() - 1);
                            if (i < strs.length - 1) {
                                ++i;
                            } else {
                                i = 0;
                                break;
                            }
                            if (entry.getValue() == 0)
                                break;
                        }
                        ++count;
                        if (i == 0) {
                            if (count == 1) {
                                boolean flag = true;
                                for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                    if (entryy.getKey() != strs[0].charAt(0) && entryy.getValue() > 0) {
                                        flag = false;
                                        break;
                                    }
                                }
                                StringBuilder ans = strs[0];

                                if (!flag) {
                                    if (letters == 2 && map.entrySet().stream().filter(e -> e.getValue() != 0).count() == 1) {
                                        for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                            if (entryy.getValue() > 0) {
                                                for (int j = 0; j < entryy.getValue() / k + 1; ++j) {
                                                    ans.append(entryy.getKey());
                                                }
                                            }
                                        }
                                    } else {
                                        for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                            for (int j = 0; j < entryy.getValue(); ++j) {
                                                ans.append(entryy.getKey());
                                            }
                                        }
                                    }
                                } else {
                                    for (int j = 0; j < entry.getValue() / k + 1; ++j) {
                                        ans.append(entry.getKey());
                                    }
                                }

                                System.out.println(ans);
                            } else {
                                System.out.println(strs[k - 1]);

                            }
                            break lab;
                        }
                    }
                }
            } else {
                StringBuilder ans = new StringBuilder();
                if (k == 1 || letters == 1 || (letters == 2 && map.entrySet().stream().allMatch(e -> e.getValue() == k || e.getValue() == 0))) {
                    if (k == 1) {
                        for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                            if (entry.getValue() > 0) {
                                for (int j = 0; j < entry.getValue(); ++j) {
                                    ans.append(entry.getKey());
                                }
                            }
                        }
                    } else if (letters == 1) {
                        for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                            if (entry.getValue() > 0) {
                                entry.setValue(entry.getValue() / k);
                                for (int j = 0; j < entry.getValue(); ++j) {
                                    ans.append(entry.getKey());
                                }
                            }
                        }
                    } else {
                        map.entrySet().stream().filter(e -> e.getValue() == k).forEach(e ->
                                System.out.print(e.getKey()));
                    }

                } else {
                    for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                        if (entry.getValue() > 0) {
                            entry.setValue(entry.getValue() - k);
                            ans.append(entry.getKey());
                            break;
                        }
                    }
                    for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                        for (int i = 0; i < entry.getValue(); ++i) {
                            ans.append(entry.getKey());
                        }
                    }
                }

                System.out.println(ans);
            }
        }
    }

    private static HashMap<Character, Integer> initMap() {
        HashMap<Character, Integer> map = new HashMap<>(26);

        for (char c = 'a'; c <= 'z'; ++c) {
            map.put(c, 0);
        }

        return map;
    }

}


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class C {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();
        sc.nextLine();

        while (t-- > 0) {
            int n = sc.nextInt();
            int k = sc.nextInt();
            sc.nextLine();
            String s = sc.nextLine();
            HashMap<Character, Integer> map = initMap();
            StringBuilder[] strs = new StringBuilder[k];

            for (int i = 0; i < k; ++i) {
                strs[i] = new StringBuilder("");
            }

            for (int i = 0; i < n; ++i) {
                map.put(
                        s.charAt(i),
                        map.get(s.charAt(i)) + 1
                );
            }

            boolean f = true;
            int letters = 0;
            for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                if (entry.getValue() % k != 0) {
                    f = false;
                } else if (entry.getValue() != 0) {
                    letters++;
                }
            }

            lab:
            if (!f) {
                int i = 0;
                int count = 0;
                boolean filled = false;
                for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                    while (entry.getValue() > 0) {
                        for (; i < strs.length; ) {
                            StringBuilder str = strs[i];
                            str.append(entry.getKey());
                            entry.setValue(entry.getValue() - 1);
                            if (i < strs.length - 1) {
                                ++i;
                            } else {
                                i = 0;
                                break;
                            }
                            if (entry.getValue() == 0)
                                break;
                        }
                        ++count;
                        if (i == 0) {
                            if (count == 1) {
                                boolean flag = true;
                                for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                    if (entryy.getKey() != strs[0].charAt(0) && entryy.getValue() > 0) {
                                        flag = false;
                                        break;
                                    }
                                }
                                StringBuilder ans = strs[0];

                                if (!flag) {
                                    if (letters == 2 && map.entrySet().stream().filter(e -> e.getValue() != 0).count() == 1) {
                                        for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                            if (entryy.getValue() > 0) {
                                                for (int j = 0; j < entryy.getValue() / k + entryy.getValue() % k; ++j) {
                                                    ans.append(entryy.getKey());
                                                }
                                            }
                                        }
                                    } else {
                                        for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                            for (int j = 0; j < entryy.getValue(); ++j) {
                                                ans.append(entryy.getKey());
                                            }
                                        }
                                    }
                                } else {
                                    for (int j = 0; j < entry.getValue() / k + 1; ++j) {
                                        ans.append(entry.getKey());
                                    }
                                }

                                System.out.println(ans);
                            } else {
                                System.out.println(strs[k - 1]);

                            }
                            break lab;
                        }
                    }
                }
            } else {
                StringBuilder ans = new StringBuilder();
                if (k == 1 || letters == 1 || (letters == 2 && map.entrySet().stream().allMatch(e -> e.getValue() == k || e.getValue() == 0))) {
                    if (k == 1) {
                        for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                            if (entry.getValue() > 0) {
                                for (int j = 0; j < entry.getValue(); ++j) {
                                    ans.append(entry.getKey());
                                }
                            }
                        }
                    } else if (letters == 1) {
                        for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                            if (entry.getValue() > 0) {
                                entry.setValue(entry.getValue() / k);
                                for (int j = 0; j < entry.getValue(); ++j) {
                                    ans.append(entry.getKey());
                                }
                            }
                        }
                    } else {
                        map.entrySet().stream().filter(e -> e.getValue() == k).forEach(e ->
                                System.out.print(e.getKey()));
                    }

                } else {
                    for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                        if (entry.getValue() > 0) {
                            entry.setValue(entry.getValue() - k);
                            ans.append(entry.getKey());
                            break;
                        }
                    }
                    for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                        for (int i = 0; i < entry.getValue(); ++i) {
                            ans.append(entry.getKey());
                        }
                    }
                }

                System.out.println(ans);
            }
        }
    }

    private static HashMap<Character, Integer> initMap() {
        HashMap<Character, Integer> map = new HashMap<>(26);

        for (char c = 'a'; c <= 'z'; ++c) {
            map.put(c, 0);
        }

        return map;
    }

}


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class C {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();
        sc.nextLine();

        while (t-- > 0) {
            int n = sc.nextInt();
            int k = sc.nextInt();
            sc.nextLine();
            String s = sc.nextLine();
            HashMap<Character, Integer> map = initMap();
            StringBuilder[] strs = new StringBuilder[k];

            for (int i = 0; i < k; ++i) {
                strs[i] = new StringBuilder("");
            }

            for (int i = 0; i < n; ++i) {
                map.put(
                        s.charAt(i),
                        map.get(s.charAt(i)) + 1
                );
            }

            boolean f = true;
            int letters = 0;
            for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                if (entry.getValue() % k != 0) {
                    f = false;
                } else if (entry.getValue() != 0) {
                    letters++;
                }
            }

            lab:
            if (!f) {
                int i = 0;
                int count = 0;
                boolean filled = false;
                for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                    while (entry.getValue() > 0) {
                        for (; i < strs.length; ) {
                            StringBuilder str = strs[i];
                            str.append(entry.getKey());
                            entry.setValue(entry.getValue() - 1);
                            if (i < strs.length - 1) {
                                ++i;
                            } else {
                                i = 0;
                                break;
                            }
                            if (entry.getValue() == 0)
                                break;
                        }
                        ++count;
                        if (i == 0) {
                            if (count == 1) {
                                boolean flag = true;
                                for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                    if (entryy.getKey() != strs[0].charAt(0) && entryy.getValue() > 0) {
                                        flag = false;
                                        break;
                                    }
                                }
                                StringBuilder ans = strs[0];

                                if (!flag) {
                                    for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                        for (int j = 0; j < entryy.getValue(); ++j) {
                                            ans.append(entryy.getKey());
                                        }
                                    }
                                } else {
                                    for (int j = 0; j < entry.getValue() / k + 1; ++j) {
                                        ans.append(entry.getKey());
                                    }
                                }

                                System.out.println(ans);
                            } else {
                                System.out.println(strs[k - 1]);

                            }
                            break lab;
                        }
                    }
                }
            } else {
                StringBuilder ans = new StringBuilder();
                if (k == 1 || letters == 1 || (letters == 2 && map.get('a') == k && map.get('b') == k)) {
                    for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                        ans.append(entry.getKey());
                    }
                } else {
                    for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                        if (entry.getValue() > 0) {
                            entry.setValue(entry.getValue() - k);
                            ans.append(entry.getKey());
                            break;
                        }
                    }
                    for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                        for (int i = 0; i < entry.getValue(); ++i) {
                            ans.append(entry.getKey());
                        }
                    }
                }

                System.out.println(ans);
            }
        }
    }

    private static HashMap<Character, Integer> initMap() {
        HashMap<Character, Integer> map = new HashMap<>(26);

        for (char c = 'a'; c <= 'z'; ++c) {
            map.put(c, 0);
        }

        return map;
    }

}


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class C {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();
        sc.nextLine();

        while (t-- > 0) {
            int n = sc.nextInt();
            int k = sc.nextInt();
            sc.nextLine();
            String s = sc.nextLine();
            HashMap<Character, Integer> map = initMap();
            StringBuilder[] strs = new StringBuilder[k];

            for (int i = 0; i < k; ++i) {
                strs[i] = new StringBuilder("");
            }

            for (int i = 0; i < n; ++i) {
                map.put(
                        s.charAt(i),
                        map.get(s.charAt(i)) + 1
                );
            }

            boolean f = true;
            int letters = 0;
            for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                if (entry.getValue() % k != 0 && entry.getValue() != 0) {
                    f = false;
                } else {
                    letters++;
                }
            }

            lab:
            if (!f) {
                int i = 0;
                int count = 0;
                boolean filled = false;
                for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                    while (entry.getValue() > 0) {
                        for (; i < strs.length;) {
                            StringBuilder str = strs[i];
                            str.append(entry.getKey());
                            entry.setValue(entry.getValue() - 1);
                            if (i < strs.length - 1) {
                                ++i;
                            } else {
                                i = 0;
                                break;
                            }
                            if (entry.getValue() == 0)
                                break;
                        }
                        ++count;
                        if (i == 0) {
                            if (count == 1) {
                                boolean flag = true;
                                for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                    if (entryy.getKey() != strs[0].charAt(0) && entryy.getValue() > 0) {
                                        flag = false;
                                        break;
                                    }
                                }
                                StringBuilder ans = strs[0];

                                if (!flag) {
                                    for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                        for (int j = 0; j < entryy.getValue(); ++j) {
                                            ans.append(entryy.getKey());
                                        }
                                    }
                                } else {
                                    for (int j = 0; j < entry.getValue() / k + 1; ++j) {
                                        ans.append(entry.getKey());
                                    }
                                }

                                System.out.println(ans);
                            } else {
                                System.out.println(strs[k - 1]);

                            }
                            break lab;
                        }
                    }
                }
            } else {
                StringBuilder ans = new StringBuilder();
                if(letters <= 2) {
                    for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                        for (int i = 0; i < entry.getValue() / k; ++i) {
                            ans.append(entry.getKey());
                        }
                    }
                } else {
                    for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                        for (int i = 0; i < entry.getValue(); ++i) {
                            ans.append(entry.getKey());
                        }
                    }
                }

                System.out.println(ans);
            }
        }
    }

    private static HashMap<Character, Integer> initMap() {
        HashMap<Character, Integer> map = new HashMap<>(26);

        for (char c = 'a'; c <= 'z'; ++c) {
            map.put(c, 0);
        }

        return map;
    }

}


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class C {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();
        sc.nextLine();

        while (t-- > 0) {
            int n = sc.nextInt();
            int k = sc.nextInt();
            sc.nextLine();
            String s = sc.nextLine();
            HashMap<Character, Integer> map = initMap();
            StringBuilder[] strs = new StringBuilder[k];

            for (int i = 0; i < k; ++i) {
                strs[i] = new StringBuilder("");
            }

            for (int i = 0; i < n; ++i) {
                map.put(
                        s.charAt(i),
                        map.get(s.charAt(i)) + 1
                );
            }

            boolean f = true;
            int letters = 0;
            for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                if (entry.getValue() % k != 0) {
                    f = false;
                } else if (entry.getValue() != 0) {
                    letters++;
                }
            }

            lab:
            if (!f) {
                int i = 0;
                int count = 0;
                boolean filled = false;
                for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                    while (entry.getValue() > 0) {
                        for (; i < strs.length; ) {
                            StringBuilder str = strs[i];
                            str.append(entry.getKey());
                            entry.setValue(entry.getValue() - 1);
                            if (i < strs.length - 1) {
                                ++i;
                            } else {
                                i = 0;
                                break;
                            }
                            if (entry.getValue() == 0)
                                break;
                        }
                        ++count;
                        if (i == 0) {
                            if (count == 1) {
                                boolean flag = true;
                                for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                    if (entryy.getKey() != strs[0].charAt(0) && entryy.getValue() > 0) {
                                        flag = false;
                                        break;
                                    }
                                }
                                StringBuilder ans = strs[0];

                                if (!flag) {
                                    if (letters == 2 && map.entrySet().stream().filter(e -> e.getValue() != 0).count() == 1) {
                                        for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                            if (entryy.getValue() > 0) {
                                                for (int j = 0; j < entryy.getValue() / k + entryy.getValue() % k; ++j) {
                                                    ans.append(entryy.getKey());
                                                }
                                            }
                                        }
                                    } else {
                                        for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                            for (int j = 0; j < entryy.getValue(); ++j) {
                                                ans.append(entryy.getKey());
                                            }
                                        }
                                    }
                                } else {
                                    for (int j = 0; j < entry.getValue() / k + 1; ++j) {
                                        ans.append(entry.getKey());
                                    }
                                }

                                System.out.println(ans);
                            } else {
                                System.out.println(strs[k - 1]);

                            }
                            break lab;
                        }
                    }
                }
            } else {
                StringBuilder ans = new StringBuilder();
                if (k == 1 || letters == 1 || (letters == 2 && map.entrySet().stream().allMatch(e -> e.getValue() == k || e.getValue() == 0))) {
                    if (k == 1) {
                        for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                            if (entry.getValue() > 0) {
                                for (int j = 0; j < entry.getValue(); ++j) {
                                    ans.append(entry.getKey());
                                }
                            }
                        }
                    } else if (letters == 1) {
                        for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                            if (entry.getValue() > 0) {
                                entry.setValue(entry.getValue() / k);
                                for (int j = 0; j < entry.getValue(); ++j) {
                                    ans.append(entry.getKey());
                                }
                            }
                        }
                    } else {
                        map.entrySet().stream().filter(e -> e.getValue() == k).forEach(e ->
                                System.out.print(e.getValue()));
                        System.out.println();
                    }

                } else {
                    for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                        if (entry.getValue() > 0) {
                            entry.setValue(entry.getValue() - k);
                            ans.append(entry.getKey());
                            break;
                        }
                    }
                    for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                        for (int i = 0; i < entry.getValue(); ++i) {
                            ans.append(entry.getKey());
                        }
                    }
                }

                System.out.println(ans);
            }
        }
    }

    private static HashMap<Character, Integer> initMap() {
        HashMap<Character, Integer> map = new HashMap<>(26);

        for (char c = 'a'; c <= 'z'; ++c) {
            map.put(c, 0);
        }

        return map;
    }

}


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class C {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();
        sc.nextLine();

        while (t-- > 0) {
            int n = sc.nextInt();
            int k = sc.nextInt();
            sc.nextLine();
            String s = sc.nextLine();
            HashMap<Character, Integer> map = initMap();
            StringBuilder[] strs = new StringBuilder[k];

            for (int i = 0; i < k; ++i) {
                strs[i] = new StringBuilder("");
            }

            for (int i = 0; i < n; ++i) {
                map.put(
                        s.charAt(i),
                        map.get(s.charAt(i)) + 1
                );
            }

            boolean f = true;
            int letters = 0;
            for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                if (entry.getValue() % k != 0) {
                    f = false;
                } else if(entry.getValue() != 0) {
                    letters++;
                }
            }

            lab:
            if (!f) {
                int i = 0;
                int count = 0;
                boolean filled = false;
                for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                    while (entry.getValue() > 0) {
                        for (; i < strs.length;) {
                            StringBuilder str = strs[i];
                            str.append(entry.getKey());
                            entry.setValue(entry.getValue() - 1);
                            if (i < strs.length - 1) {
                                ++i;
                            } else {
                                i = 0;
                                break;
                            }
                            if (entry.getValue() == 0)
                                break;
                        }
                        ++count;
                        if (i == 0) {
                            if (count == 1) {
                                boolean flag = true;
                                for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                    if (entryy.getKey() != strs[0].charAt(0) && entryy.getValue() > 0) {
                                        flag = false;
                                        break;
                                    }
                                }
                                StringBuilder ans = strs[0];

                                if (!flag) {
                                    for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                        for (int j = 0; j < entryy.getValue(); ++j) {
                                            ans.append(entryy.getKey());
                                        }
                                    }
                                } else {
                                    for (int j = 0; j < entry.getValue() / k + 1; ++j) {
                                        ans.append(entry.getKey());
                                    }
                                }

                                System.out.println(ans);
                            } else {
                                System.out.println(strs[k - 1]);

                            }
                            break lab;
                        }
                    }
                }
            } else {
                StringBuilder ans = new StringBuilder();
                if(k == 1 || letters == 1 || (letters == 2 && map.get('a') == k && map.get('b') == k)) {
                    for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                        for (int i = 0; i < entry.getValue() / k; ++i) {
                            ans.append(entry.getKey());
                        }
                    }
                } else {
                    for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                        while (entry.getValue() > 0) {
                            entry.setValue(entry.getValue() - k + 1);
                        }
                    }
                    for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                        for (int i = 0; i < entry.getValue(); ++i) {
                            ans.append(entry.getKey());
                        }
                    }
                }

                System.out.println(ans);
            }
        }
    }

    private static HashMap<Character, Integer> initMap() {
        HashMap<Character, Integer> map = new HashMap<>(26);

        for (char c = 'a'; c <= 'z'; ++c) {
            map.put(c, 0);
        }

        return map;
    }

}


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class C {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();
        sc.nextLine();

        while (t-- > 0) {
            int n = sc.nextInt();
            int k = sc.nextInt();
            sc.nextLine();
            String s = sc.nextLine();
            HashMap<Character, Integer> map = initMap();
            StringBuilder[] strs = new StringBuilder[k];

            for (int i = 0; i < k; ++i) {
                strs[i] = new StringBuilder("");
            }

            for (int i = 0; i < n; ++i) {
                map.put(
                        s.charAt(i),
                        map.get(s.charAt(i)) + 1
                );
            }

            boolean f = true;
            int letters = 0;
            for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                if (entry.getValue() % k != 0) {
                    f = false;
                } else if(entry.getValue() != 0) {
                    letters++;
                }
            }

            lab:
            if (!f) {
                int i = 0;
                int count = 0;
                boolean filled = false;
                for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                    while (entry.getValue() > 0) {
                        for (; i < strs.length;) {
                            StringBuilder str = strs[i];
                            str.append(entry.getKey());
                            entry.setValue(entry.getValue() - 1);
                            if (i < strs.length - 1) {
                                ++i;
                            } else {
                                i = 0;
                                break;
                            }
                            if (entry.getValue() == 0)
                                break;
                        }
                        ++count;
                        if (i == 0) {
                            if (count == 1) {
                                boolean flag = true;
                                for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                    if (entryy.getKey() != strs[0].charAt(0) && entryy.getValue() > 0) {
                                        flag = false;
                                        break;
                                    }
                                }
                                StringBuilder ans = strs[0];

                                if (!flag) {
                                    for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                        for (int j = 0; j < entryy.getValue(); ++j) {
                                            ans.append(entryy.getKey());
                                        }
                                    }
                                } else {
                                    for (int j = 0; j < entry.getValue() / k + 1; ++j) {
                                        ans.append(entry.getKey());
                                    }
                                }

                                System.out.println(ans);
                            } else {
                                System.out.println(strs[k - 1]);

                            }
                            break lab;
                        }
                    }
                }
            } else {
                StringBuilder ans = new StringBuilder();
                if(k == 1 || letters == 1 || (letters == 2 && map.get('a') == k && map.get('b') == k)) {
                    if(k == 1) {
                        for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                            if(entry.getValue() > 0) {
                                for (int j = 0; j < entry.getValue(); ++j) {
                                    ans.append(entry.getKey());
                                }
                            }
                        }
                    } else if(letters == 1) {
                        for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                            if (entry.getValue() > 0) {
                                entry.setValue(entry.getValue() / k);
                                ans.append(entry.getKey());
                                for (int j = 0; j < entry.getValue(); ++j) {
                                    ans.append(entry.getKey());
                                }
                            }
                        }
                    } else {
                        System.out.println("ab");
                    }

                } else {
                    for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                        if (entry.getValue() > 0) {
                            entry.setValue(entry.getValue() - k);
                            ans.append(entry.getKey());
                            break;
                        }
                    }
                    for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                        for (int i = 0; i < entry.getValue(); ++i) {
                            ans.append(entry.getKey());
                        }
                    }
                }

                System.out.println(ans);
            }
        }
    }

    private static HashMap<Character, Integer> initMap() {
        HashMap<Character, Integer> map = new HashMap<>(26);

        for (char c = 'a'; c <= 'z'; ++c) {
            map.put(c, 0);
        }

        return map;
    }

}


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class C {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();
        sc.nextLine();

        while (t-- > 0) {
            int n = sc.nextInt();
            int k = sc.nextInt();
            sc.nextLine();
            String s = sc.nextLine();
            HashMap<Character, Integer> map = initMap();
            StringBuilder[] strs = new StringBuilder[k];

            for (int i = 0; i < k; ++i) {
                strs[i] = new StringBuilder("");
            }

            for (int i = 0; i < n; ++i) {
                map.put(
                        s.charAt(i),
                        map.get(s.charAt(i)) + 1
                );
            }

            boolean f = true;
            int letters = 0;
            for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                if (entry.getValue() % k != 0) {
                    f = false;
                } else if(entry.getValue() != 0) {
                    letters++;
                }
            }

            lab:
            if (!f) {
                int i = 0;
                int count = 0;
                boolean filled = false;
                for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                    while (entry.getValue() > 0) {
                        for (; i < strs.length;) {
                            StringBuilder str = strs[i];
                            str.append(entry.getKey());
                            entry.setValue(entry.getValue() - 1);
                            if (i < strs.length - 1) {
                                ++i;
                            } else {
                                i = 0;
                                break;
                            }
                            if (entry.getValue() == 0)
                                break;
                        }
                        ++count;
                        if (i == 0) {
                            if (count == 1) {
                                boolean flag = true;
                                for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                    if (entryy.getKey() != strs[0].charAt(0) && entryy.getValue() > 0) {
                                        flag = false;
                                        break;
                                    }
                                }
                                StringBuilder ans = strs[0];

                                if (!flag) {
                                    for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                        for (int j = 0; j < entryy.getValue(); ++j) {
                                            ans.append(entryy.getKey());
                                        }
                                    }
                                } else {
                                    for (int j = 0; j < entry.getValue() / k + 1; ++j) {
                                        ans.append(entry.getKey());
                                    }
                                }

                                System.out.println(ans);
                            } else {
                                System.out.println(strs[k - 1]);

                            }
                            break lab;
                        }
                    }
                }
            } else {
                StringBuilder ans = new StringBuilder();
                if(letters == 1 || (letters == 2 && map.get('a') == k && map.get('b') == k)) {
                    for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                        for (int i = 0; i < entry.getValue() / k; ++i) {
                            ans.append(entry.getKey());
                        }
                    }
                } else {

                    for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                        while (entry.getValue() > 0) {
                            entry.setValue(entry.getValue() - k);
                        }
                    }

                    for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                        for (int i = 0; i < entry.getValue(); ++i) {
                            ans.append(entry.getKey());
                        }
                    }
                }

                System.out.println(ans);
            }
        }
    }

    private static HashMap<Character, Integer> initMap() {
        HashMap<Character, Integer> map = new HashMap<>(26);

        for (char c = 'a'; c <= 'z'; ++c) {
            map.put(c, 0);
        }

        return map;
    }

}


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class C {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();
        sc.nextLine();

        while (t-- > 0) {
            int n = sc.nextInt();
            int k = sc.nextInt();
            sc.nextLine();
            String s = sc.nextLine();
            HashMap<Character, Integer> map = initMap();
            StringBuilder[] strs = new StringBuilder[k];

            for (int i = 0; i < k; ++i) {
                strs[i] = new StringBuilder("");
            }

            for (int i = 0; i < n; ++i) {
                map.put(
                        s.charAt(i),
                        map.get(s.charAt(i)) + 1
                );
            }

            boolean f = true;
            int letters = 0;
            for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                if (entry.getValue() % k != 0) {
                    f = false;
                }
                if (entry.getValue() != 0) {
                    letters++;
                }
            }

            lab:
            if (!f) {
                int i = 0;
                int count = 0;
                boolean filled = false;
                for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                    while (entry.getValue() > 0) {
                        for (; i < strs.length; ) {
                            StringBuilder str = strs[i];
                            str.append(entry.getKey());
                            entry.setValue(entry.getValue() - 1);
                            if (i < strs.length - 1) {
                                ++i;
                            } else {
                                i = 0;
                                break;
                            }
                            if (entry.getValue() == 0)
                                break;
                        }
                        ++count;
                        if (i == 0) {
                            if (count == 1) {
                                boolean flag = true;
                                for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                    if (entryy.getKey() != strs[0].charAt(0) && entryy.getValue() > 0) {
                                        flag = false;
                                        break;
                                    }
                                }
                                StringBuilder ans = strs[0];

                                if (!flag) {
                                    if (letters == 2 && map.entrySet().stream().filter(e -> e.getValue() != 0).count() == 1) {
                                        for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                            if (entryy.getValue() > 0) {
                                                for (int j = 0; j < entryy.getValue() / k + 1; ++j) {
                                                    ans.append(entryy.getKey());
                                                }
                                            }
                                        }
                                    } else {
                                        for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                            for (int j = 0; j < entryy.getValue(); ++j) {
                                                ans.append(entryy.getKey());
                                            }
                                        }
                                    }
                                } else {
                                    for (int j = 0; j < entry.getValue() / k + 1; ++j) {
                                        ans.append(entry.getKey());
                                    }
                                }

                                System.out.println(ans);
                            } else {
                                System.out.println(strs[k - 1]);

                            }
                            break lab;
                        }
                    }
                }
            } else {
                StringBuilder ans = new StringBuilder();
                if (k == 1 || letters == 1 || (letters == 2 && map.entrySet().stream().allMatch(e -> e.getValue() == k || e.getValue() == 0))) {
                    if (k == 1) {
                        for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                            if (entry.getValue() > 0) {
                                for (int j = 0; j < entry.getValue(); ++j) {
                                    ans.append(entry.getKey());
                                }
                            }
                        }
                    } else if (letters == 1) {
                        for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                            if (entry.getValue() > 0) {
                                entry.setValue(entry.getValue() / k);
                                for (int j = 0; j < entry.getValue(); ++j) {
                                    ans.append(entry.getKey());
                                }
                            }
                        }
                    } else {
                        map.entrySet().stream().filter(e -> e.getValue() == k).forEach(e ->
                                System.out.print(e.getKey()));
                    }

                } else {
                    if(map.entrySet().stream().filter(e -> e.getValue() > 0).count() == 2) {
                        for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                            if (entry.getValue() > 0) {
                                entry.setValue(entry.getValue() - k);
                                ans.append(entry.getKey());
                                break;
                            }
                        }
                        for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                            for (int i = 0; i < entry.getValue() / k; ++i) {
                                ans.append(entry.getKey());
                            }
                        }
                    } else {
                        for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                            if (entry.getValue() > 0) {
                                entry.setValue(entry.getValue() - k);
                                ans.append(entry.getKey());
                                break;
                            }
                        }
                        for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                            for (int i = 0; i < entry.getValue(); ++i) {
                                ans.append(entry.getKey());
                            }
                        }
                    }

                }

                System.out.println(ans);
            }
        }
    }

    private static HashMap<Character, Integer> initMap() {
        HashMap<Character, Integer> map = new HashMap<>(26);

        for (char c = 'a'; c <= 'z'; ++c) {
            map.put(c, 0);
        }

        return map;
    }

}


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class C {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();
        sc.nextLine();

        while (t-- > 0) {
            int n = sc.nextInt();
            int k = sc.nextInt();
            sc.nextLine();
            String s = sc.nextLine();
            HashMap<Character, Integer> map = initMap();
            StringBuilder[] strs = new StringBuilder[k];

            for (int i = 0; i < k; ++i) {
                strs[i] = new StringBuilder("");
            }

            for (int i = 0; i < n; ++i) {
                map.put(
                        s.charAt(i),
                        map.get(s.charAt(i)) + 1
                );
            }

            boolean f = true;
            int letters = 0;
            for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                if (entry.getValue() % k != 0) {
                    f = false;
                } else if(entry.getValue() != 0) {
                    letters++;
                }
            }

            lab:
            if (!f) {
                int i = 0;
                int count = 0;
                boolean filled = false;
                for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                    while (entry.getValue() > 0) {
                        for (; i < strs.length;) {
                            StringBuilder str = strs[i];
                            str.append(entry.getKey());
                            entry.setValue(entry.getValue() - 1);
                            if (i < strs.length - 1) {
                                ++i;
                            } else {
                                i = 0;
                                break;
                            }
                            if (entry.getValue() == 0)
                                break;
                        }
                        ++count;
                        if (i == 0) {
                            if (count == 1) {
                                boolean flag = true;
                                for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                    if (entryy.getKey() != strs[0].charAt(0) && entryy.getValue() > 0) {
                                        flag = false;
                                        break;
                                    }
                                }
                                StringBuilder ans = strs[0];

                                if (!flag) {
                                    for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                        for (int j = 0; j < entryy.getValue(); ++j) {
                                            ans.append(entryy.getKey());
                                        }
                                    }
                                } else {
                                    for (int j = 0; j < entry.getValue() / k + 1; ++j) {
                                        ans.append(entry.getKey());
                                    }
                                }

                                System.out.println(ans);
                            } else {
                                System.out.println(strs[k - 1]);

                            }
                            break lab;
                        }
                    }
                }
            } else {
                StringBuilder ans = new StringBuilder();
                if(k == 1 || letters == 1 || (letters == 2 && map.get('a') == k && map.get('b') == k)) {
                    for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                        for (int i = 0; i < entry.getValue() / k; ++i) {
                            ans.append(entry.getKey());
                        }
                    }
                } else {
                    for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                        while (entry.getValue() > 0) {
                            entry.setValue(entry.getValue() - k);
                        }
                    }
                    for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                        for (int i = 0; i < entry.getValue(); ++i) {
                            ans.append(entry.getKey());
                        }
                    }
                }

                System.out.println(ans);
            }
        }
    }

    private static HashMap<Character, Integer> initMap() {
        HashMap<Character, Integer> map = new HashMap<>(26);

        for (char c = 'a'; c <= 'z'; ++c) {
            map.put(c, 0);
        }

        return map;
    }

}


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class C {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();
        sc.nextLine();

        while (t-- > 0) {
            int n = sc.nextInt();
            int k = sc.nextInt();
            sc.nextLine();
            String s = sc.nextLine();
            HashMap<Character, Integer> map = initMap();
            StringBuilder[] strs = new StringBuilder[k];

            for (int i = 0; i < k; ++i) {
                strs[i] = new StringBuilder("");
            }

            for (int i = 0; i < n; ++i) {
                map.put(
                        s.charAt(i),
                        map.get(s.charAt(i)) + 1
                );
            }

            boolean f = true;
            int letters = 0;
            for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                if (entry.getValue() % k != 0) {
                    f = false;
                }
                if (entry.getValue() != 0) {
                    letters++;
                }
            }

            lab:
            if (!f) {
                int i = 0;
                int count = 0;
                boolean filled = false;
                for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                    while (entry.getValue() > 0) {
                        for (; i < strs.length; ) {
                            StringBuilder str = strs[i];
                            str.append(entry.getKey());
                            entry.setValue(entry.getValue() - 1);
                            if (i < strs.length - 1) {
                                ++i;
                            } else {
                                i = 0;
                                break;
                            }
                            if (entry.getValue() == 0)
                                break;
                        }
                        ++count;
                        if (i == 0) {
                            if (count == 1) {
                                boolean flag = true;
                                for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                    if (entryy.getKey() != strs[0].charAt(0) && entryy.getValue() > 0) {
                                        flag = false;
                                        break;
                                    }
                                }
                                StringBuilder ans = strs[0];

                                if (!flag) {
                                    if (letters == 2 && map.entrySet().stream().filter(e -> e.getValue() != 0).count() == 1) {
                                        for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                            if (entryy.getValue() > 0) {
                                                for (int j = 0; j < entryy.getValue() / k + 1; ++j) {
                                                    ans.append(entryy.getKey());
                                                }
                                            }
                                        }
                                    } else {
                                        for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                            for (int j = 0; j < entryy.getValue(); ++j) {
                                                ans.append(entryy.getKey());
                                            }
                                        }
                                    }
                                } else {
                                    for (int j = 0; j < entry.getValue() / k + 1; ++j) {
                                        ans.append(entry.getKey());
                                    }
                                }

                                System.out.println(ans);
                            } else {
                                System.out.println(strs[k - 1]);

                            }
                            break lab;
                        }
                    }
                }
            } else {
                StringBuilder ans = new StringBuilder();
                if (k == 1 || letters == 1 || (letters == 2 && map.entrySet().stream().allMatch(e -> e.getValue() == k || e.getValue() == 0))) {
                    if (k == 1) {
                        for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                            if (entry.getValue() > 0) {
                                for (int j = 0; j < entry.getValue(); ++j) {
                                    ans.append(entry.getKey());
                                }
                            }
                        }
                    } else if (letters == 1) {
                        for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                            if (entry.getValue() > 0) {
                                entry.setValue(entry.getValue() / k);
                                for (int j = 0; j < entry.getValue(); ++j) {
                                    ans.append(entry.getKey());
                                }
                            }
                        }
                    } else {
                        map.entrySet().stream().filter(e -> e.getValue() == k).forEach(e ->
                                System.out.print(e.getKey()));
                    }

                } else {
                    if(map.entrySet().stream().filter(e -> e.getValue() > 0).count() == 1) {
                        for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                            if (entry.getValue() > 0) {
                                entry.setValue(entry.getValue() - k);
                                ans.append(entry.getKey());
                                break;
                            }
                        }
                        for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                            for (int i = 0; i < entry.getValue() / k; ++i) {
                                ans.append(entry.getKey());
                            }
                        }
                    } else {
                        for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                            if (entry.getValue() > 0) {
                                entry.setValue(entry.getValue() - k);
                                ans.append(entry.getKey());
                                break;
                            }
                        }
                        for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                            for (int i = 0; i < entry.getValue(); ++i) {
                                ans.append(entry.getKey());
                            }
                        }
                    }

                }

                System.out.println(ans);
            }
        }
    }

    private static HashMap<Character, Integer> initMap() {
        HashMap<Character, Integer> map = new HashMap<>(26);

        for (char c = 'a'; c <= 'z'; ++c) {
            map.put(c, 0);
        }

        return map;
    }

}


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class C {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();
        sc.nextLine();

        while (t-- > 0) {
            int n = sc.nextInt();
            int k = sc.nextInt();
            sc.nextLine();
            String s = sc.nextLine();
            HashMap<Character, Integer> map = initMap();
            StringBuilder[] strs = new StringBuilder[k];

            for (int i = 0; i < k; ++i) {
                strs[i] = new StringBuilder("");
            }

            for (int i = 0; i < n; ++i) {
                map.put(
                        s.charAt(i),
                        map.get(s.charAt(i)) + 1
                );
            }

            boolean f = true;
            int letters = 0;
            for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                if (entry.getValue() % k != 0) {
                    f = false;
                } else if(entry.getValue() != 0) {
                    letters++;
                }
            }

            lab:
            if (!f) {
                int i = 0;
                int count = 0;
                boolean filled = false;
                for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                    while (entry.getValue() > 0) {
                        for (; i < strs.length;) {
                            StringBuilder str = strs[i];
                            str.append(entry.getKey());
                            entry.setValue(entry.getValue() - 1);
                            if (i < strs.length - 1) {
                                ++i;
                            } else {
                                i = 0;
                                break;
                            }
                            if (entry.getValue() == 0)
                                break;
                        }
                        ++count;
                        if (i == 0) {
                            if (count == 1) {
                                boolean flag = true;
                                for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                    if (entryy.getKey() != strs[0].charAt(0) && entryy.getValue() > 0) {
                                        flag = false;
                                        break;
                                    }
                                }
                                StringBuilder ans = strs[0];

                                if (!flag) {
                                    for (Map.Entry<Character, Integer> entryy : map.entrySet()) {
                                        for (int j = 0; j < entryy.getValue(); ++j) {
                                            ans.append(entryy.getKey());
                                        }
                                    }
                                } else {
                                    for (int j = 0; j < entry.getValue() / k + 1; ++j) {
                                        ans.append(entry.getKey());
                                    }
                                }

                                System.out.println(ans);
                            } else {
                                System.out.println(strs[k - 1]);

                            }
                            break lab;
                        }
                    }
                }
            } else {
                StringBuilder ans = new StringBuilder();
                if(letters <= 2) {
                    for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                        for (int i = 0; i < entry.getValue() / k; ++i) {
                            ans.append(entry.getKey());
                        }
                    }
                } else {
                    for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                        for (int i = 0; i < entry.getValue(); ++i) {
                            ans.append(entry.getKey());
                        }
                    }
                }

                System.out.println(ans);
            }
        }
    }

    private static HashMap<Character, Integer> initMap() {
        HashMap<Character, Integer> map = new HashMap<>(26);

        for (char c = 'a'; c <= 'z'; ++c) {
            map.put(c, 0);
        }

        return map;
    }

}