Phoenix has a string $s$ consisting of lowercase Latin letters. He wants to distribute all the letters of his string into $k$ non-empty strings $a_1, a_2, \dots, a_k$ such that every letter of $s$ goes to exactly one of the strings $a_i$. The strings $a_i$ do not need to be substrings of $s$. Phoenix can distribute letters of $s$ and rearrange the letters within each string $a_i$ however he wants.

For example, if $s = $ baba and $k=2$, Phoenix may distribute the letters of his string in many ways, such as:   ba and ba  a and abb  ab and ab  aa and bb 

But these ways are invalid:   baa and ba  b and ba  baba and empty string ($a_i$ should be non-empty) 

Phoenix wants to distribute the letters of his string $s$ into $k$ strings $a_1, a_2, \dots, a_k$ to minimize the lexicographically maximum string among them, i. e. minimize $max(a_1, a_2, \dots, a_k)$. Help him find the optimal distribution and print the minimal possible value of $max(a_1, a_2, \dots, a_k)$.

String $x$ is lexicographically less than string $y$ if either $x$ is a prefix of $y$ and $x \ne y$, or there exists an index $i$ ($1 \le i \le min(|x|, |y|))$ such that $x_i$ < $y_i$ and for every $j$ $(1 \le j < i)$ $x_j = y_j$. Here $|x|$ denotes the length of the string $x$.


-----Input-----

The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) — the number of test cases. Each test case consists of two lines.

The first line of each test case consists of two integers $n$ and $k$ ($1 \le k \le n \le 10^5$) — the length of string $s$ and the number of non-empty strings, into which Phoenix wants to distribute letters of $s$, respectively.

The second line of each test case contains a string $s$ of length $n$ consisting only of lowercase Latin letters.

It is guaranteed that the sum of $n$ over all test cases is $\le 10^5$.


-----Output-----

Print $t$ answers — one per test case. The $i$-th answer should be the minimal possible value of $max(a_1, a_2, \dots, a_k)$ in the $i$-th test case.


-----Example-----
Input
6
4 2
baba
5 2
baacb
5 3
baacb
5 3
aaaaa
6 4
aaxxzz
7 1
phoenix

Output
ab
abbc
b
aa
x
ehinopx



-----Note-----

In the first test case, one optimal solution is to distribute baba into ab and ab. 

In the second test case, one optimal solution is to distribute baacb into abbc and a.

In the third test case, one optimal solution is to distribute baacb into ac, ab, and b.

In the fourth test case, one optimal solution is to distribute aaaaa into aa, aa, and a.

In the fifth test case, one optimal solution is to distribute aaxxzz into az, az, x, and x.

In the sixth test case, one optimal solution is to distribute phoenix into ehinopx.

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Greedy algorithms

String algorithms

Sorting

Constructive algorithms


Solutions:
import sys
from collections import deque
input = sys.stdin.buffer.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = list(map(chr, list(input().strip())))
	s.sort()
	flag = False
	if s[k - 1] > s[0]:
		print(s[k - 1])
		continue
	if k == n:
		print(s[0])
		continue
	i = k
	if s[i] == s[-1]:
		print(s[0], end='')
		if n % k == 0:
			print(s[i] * ((n - k) // k))
		else:
			print(s[i] * ((n - k) // k + 1))
	else:
		print(s[0], end='')
		while i < n:
			print(s[i], end='')
			i += 1
		print()


def solve(s, n, k):
	s = sorted(s)
	if s[0] != s[k - 1]:
		return s[k - 1]
	worst = s[0]
	if k < n and s[k] != s[-1]:
		return worst + ''.join(s[k:])
	else:
		return worst + s[-1] * ((n - 1) // k)
T = int(input())
for _ in range(T):
	_nk = input().split()
	n = int(_nk[0])
	k = int(_nk[1])
	s = input().strip()
	print(solve(s, n, k))


from collections import Counter

def f(s, k):
	l = list(s)
	l = sorted(l)
	base = l[:k]
	tt = l[k:]
	cnt = Counter(tt)
	cnt2 = Counter(base)
	mns = min(base)
	if tt:
		mn = max(tt)
		if len(cnt) == 1:
			i = mn
			k = cnt2[mns]
			tc = cnt[i]
			cc = cnt[i] // k
			tc -= cnt[i] // k * k
			t = i * cc
			for id in range(len(base)):
				if tc:
					base[id] += t + i
					tc -= 1
				else:
					base[id] += t
					break
		else:
			for i in cnt:
				base[0] += i * cnt[i]
	return max(base)
for _ in range(int(input())):
	(N, K) = map(int, input().strip().split())
	s = input()
	print(f(s, K))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	A = input()
	A = list(A)
	A.sort()
	if k == n:
		print(A[-1])
	elif A[0] == A[k - 1]:
		C = list(set(A[k:]))
		if len(C) == 1:
			t = A[0] + ''.join(A[k] * (len(A[k:]) // k))
			if len(A[k:]) % k != 0:
				t += A[k]
			print(t)
		else:
			B = A[k:]
			print(A[0] + ''.join(B))
	else:
		print(A[k - 1])


from math import ceil
T = int(input())
for _ in range(T):
	(N, K) = map(int, input().split())
	S = input()
	count = {}
	for car in S:
		if car in count:
			count[car] += 1
		else:
			count[car] = 1
	count = list(count.items())
	count.sort(key=lambda x: x[0])
	if count[0][1] < K:
		i = 0
		for elt in count:
			i += elt[1]
			if i >= K:
				print(elt[0])
				break
	elif count[0][1] == K:
		if len(count) == 2:
			print(count[0][0] + count[1][0] * ceil(count[1][1] / K))
		else:
			ans = count[0][0]
			for elt in count[1:]:
				ans += elt[0] * elt[1]
			print(ans)
	elif len(count) == 1:
		print(count[0][0] * ceil(count[0][1] / K))
	else:
		ans = count[0][0] * (count[0][1] - K + 1)
		for elt in count[1:]:
			ans += elt[0] * elt[1]
		print(ans)


import sys
readline = sys.stdin.readline
T = int(readline())
Ans = [None] * T
for qu in range(T):
	(N, K) = map(int, readline().split())
	S = list(map(lambda x: ord(x) - 97, readline().strip()))
	S.sort()
	if len(set(S[:K])) != 1:
		Ans[qu] = chr(97 + S[K - 1])
		continue
	L = len(set(S[K:]))
	if L == 1:
		res = [S[0]] + [S[K]] * -((K - N) // K)
	else:
		res = [S[0]] + S[K:]
	Ans[qu] = ''.join(map(lambda x: chr(x + 97), res))
print('\n'.join(map(str, Ans)))


t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	s = str(input())
	arr = [[] for j in range(26)]
	for j in range(n):
		arr[ord(s[j]) - 97].append(s[j])
	count = []
	for j in range(26):
		l = len(arr[j])
		if l != 0:
			count.append(l)
	str1 = ''
	for j in range(26):
		for l in arr[j]:
			str1 += l
	if k == 1:
		print(str1)
	else:
		lis = []
		for j in range(k):
			lis.append(str1[j])
		if lis[0] != lis[-1]:
			print(str1[k - 1])
		elif str1[0] != str1[-1]:
			if str1[0] == str1[k]:
				ans = str1[0]
				ans += str1[k:]
				print(ans)
			else:
				l = len(count)
				if l > 2:
					ans = str1[0]
					ans += str1[k:]
					print(ans)
				else:
					z = count[1]
					ans = str1[0]
					x = z // k
					y = z % k
					if y == 0:
						print(ans + str1[k] * x)
					else:
						print(ans + str1[k] * (x + 1))
		else:
			x = n // k
			y = n % k
			if y == 0:
				print(str1[0] * x)
			else:
				print(str1[0] * (x + 1))


import sys
import bisect
import heapq
from math import *
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = pow(10, 9) + 7

def inp():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def solve():
	(n, k) = sep()
	s = inp()
	s = sorted(s)
	stng = ''
	for i in range(0, len(s)):
		stng += s[i]
	if k == 1:
		out(stng)
		nextline()
	elif stng[k - 1] == s[0]:
		ans = stng[0]
		if n > k:
			f = 0
			for i in range(k, n):
				if stng[i] != stng[k]:
					f = 1
			if f == 0:
				if (n - k) % k == 0:
					temp = (n - k) // k
				else:
					temp = (n - k) // k + 1
				ans += stng[k] * temp
			else:
				ans += stng[k:n]
			out(ans)
			nextline()
		else:
			out(ans)
			nextline()
	else:
		out(stng[k - 1])
		nextline()
testcase(int(inp()))


def split(word):
	return [char for char in word]

def convert(s):
	new = ''
	for x in s:
		new += x
	return new
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	s = input()
	slist = split(s)
	slist.sort()
	last = slist[n - 1]
	m = []
	for i in range(k):
		m.append([])
	for i in range(k):
		m[i].append(slist[i])
	if m[0] != m[k - 1] or k == n:
		print(m[k - 1][0])
	elif slist[k] == slist[0] or not slist[k] == slist[n - 1]:
		if slist[0] != slist[n - 1]:
			for i in range(k, n):
				m[0].append(slist[i])
			print(convert(m[0]))
		else:
			for i in range(k, n):
				if i % k == 0:
					m[0].append(slist[i])
			print(convert(m[0]))
	else:
		for i in range(k, n):
			if i % k == 0:
				m[0].append(slist[i])
		print(convert(m[0]))


def solve():
	(N, K) = map(int, input().split())
	S = input()
	S = sorted(S)
	if len(set(S[:K])) == 1:
		if len(set(S[K:])) == 1:
			print(''.join(map(str, [v for v in S[::K]])))
		else:
			print(''.join(S[K - 1:]))
	else:
		print(S[K - 1])
for _ in range(int(input())):
	solve()


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = input()
	a = list(a)
	a.sort()
	if a[0] != a[k - 1] or n == k:
		print(a[k - 1])
	elif a[0] == a[k - 1]:
		s = a[0]
		if a[k] != a[n - 1]:
			for j in range(k, n):
				s += a[j]
		else:
			for j in range(0, (n - k + k - 1) // k):
				s += a[n - 1]
		print(s)


import math

def main():
	t = int(input())
	for test in range(t):
		(n, k) = list(map(int, input().split()))
		s = [x for x in input()]
		s.sort()
		if k != 1:
			anserw = ''
			test = set(s[:k])
			anserw += max(test)
			if len(test) == 1:
				test2 = set(s[k:])
				if len(test2) == 1:
					anserw += s[k] * math.ceil((n - k) / k)
				else:
					anserw = list(anserw) + s[k:]
					anserw = ''.join(anserw)
			print(anserw)
		else:
			print(''.join(s))
main()


import sys
import collections
readline = sys.stdin.readline
flush = sys.stdout.flush
T = int(readline())
for t in range(1, T + 1):
	line1 = readline().split()
	line2 = readline().split()[0]
	(n, k) = (int(line1[0]), int(line1[1]))
	s = sorted(line2)
	if s[0] == s[k - 1]:
		if k == len(s) or s[k] != s[-1]:
			print(s[0] + ''.join(s[k:]))
		else:
			print(s[0] + ''.join(s[k:k + (len(s) + k - 1) // k - 1]))
	else:
		print(str(s[k - 1]))


t = int(input())
for _ in range(t):
	(n, k) = [int(i) for i in input().split()]
	a = input()
	al = [0 for _ in range(26)]
	for i in a:
		al[ord(i) - ord('a')] += 1
	cou = 0
	ov_cou = 0
	idx = None
	last = None
	pref = 0
	for i in range(26):
		if al[i] != 0:
			ov_cou += 1
			last = i
	for i in range(26):
		if al[i] != 0:
			pref += al[i]
			cou += 1
			idx = i
			if pref >= k:
				break
	if cou > 1:
		print(chr(idx + ord('a')))
	else:
		ans = chr(idx + ord('a'))
		al[idx] -= k
		start = None
		for i in range(26):
			if al[i] != 0:
				start = i
				break
		if start is None:
			print(ans)
		else:
			if start == last:
				ans += (al[last] // k + (1 if al[last] % k != 0 else 0)) * chr(last + ord('a'))
			else:
				for i in range(26):
					if al[i] != 0:
						ans += al[i] * chr(i + ord('a'))
			print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = ''.join(sorted(input()))
	if s[0] != s[k - 1] or k == n:
		print(s[k - 1])
	elif s[0] == s[k - 1]:
		if s[k] != s[n - 1]:
			print(s[0] + s[k:])
		else:
			print(s[0] + s[k] * ((n - k) // k + [0, 1][(n - k) % k > 0]))


from sys import stdin, stdout
from math import ceil
for case in range(int(stdin.readline())):
	(n, k) = [int(x) for x in stdin.readline().split()]
	kC = k
	s = stdin.readline().strip()
	counts = {chr(97 + x): 0 for x in range(26)}
	letters = [chr(97 + x) for x in range(26)]
	done = False
	for l in s:
		counts[l] += 1
	c = 122
	while c >= 97:
		if counts[chr(c)]:
			high = c
			break
		c -= 1
	if n == k:
		print(chr(high))
		continue
	low = 97
	while counts[chr(low)] == 0:
		low += 1
	current = 97
	k = kC
	while k > 0:
		k -= counts[chr(current)]
		counts[chr(current)] = max(0, -k)
		current += 1
	print(chr(current - 1), end='')
	if current - 1 != low:
		done = True
	if not done:
		low = 97
		while counts[chr(low)] == 0:
			low += 1
		if low != high:
			for x in letters:
				print(x * counts[x], end='')
		else:
			print(chr(high) * int(ceil(counts[chr(high)] / kC)), end='')
	print()


def solver(n, k, s):
	if s[0] != s[k - 1] or k == n:
		return s[k - 1]
	elif s[k] == s[-1]:
		return s[0] + s[k] * ((n - 1) // k)
	else:
		return s[k - 1:]
for _ in range(int(input())):
	(N, K) = [int(i) for i in input().split()]
	t = ''.join(sorted(input()))
	print(solver(N, K, t))


t = int(input())
for i10 in range(t):
	(n, k) = map(int, input().split())
	s = input()
	a = []
	for i in range(len(s)):
		a.append(s[i])
	a.sort()
	b = [[] for i in range(k)]
	j = 0
	for i in range(k):
		b[i % k].append(a[i])
	if b[0][0] != b[-1][0]:
		print(b[-1][0])
	else:
		f = True
		for i in range(k, n):
			if a[-1] != a[i]:
				print(*b[0], sep='', end='')
				for j in range(i, n):
					print(a[j], end='')
					f = False
				print()
			else:
				b[i % k].append(a[i])
			if f == False:
				break
		if f == True:
			print(*b[0], sep='')


from collections import Counter
import math
nrew = int(input())
for wew in range(nrew):
	n = list(map(int, input().split(' ')))
	li = list(input())
	li.sort()
	if li[0] != li[n[1] - 1]:
		print(li[n[1] - 1])
	else:
		ans = ''
		ans += str(li[0])
		li = li[n[1]:]
		dis = len(Counter(li).keys())
		if dis == 1:
			t = int(math.ceil(len(li) / n[1]))
			for i in range(t):
				ans += str(li[0])
		else:
			for i in li:
				ans += str(i)
		print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for r in range(t):
	(n, k) = map(int, input().split())
	s = input().strip('\n')
	d = {}
	for i in s:
		try:
			d[i] += 1
		except:
			d[i] = 1
	l = []
	for i in d:
		l.append([i, d[i]])
	l.sort(key=lambda x: x[0])
	ans = []
	for i in range(k):
		ans.append([])
	current = 0
	for i in range(k):
		if l[current][1] > 0:
			ans[i].append(l[current][0])
			d[l[current][0]] -= 1
			l[current][1] -= 1
		else:
			current += 1
			ans[i].append(l[current][0])
			d[l[current][0]] -= 1
			l[current][1] -= 1
	if current != 0:
		tt = max(ans)
		st = ''
		for i in tt:
			st += i
		print(i)
	else:
		count = 0
		for i in l:
			if i[1] > 0:
				count += 1
		if count == 1:
			letter = ''
			counter = 0
			for i in d:
				if d[i] > 0:
					letter = i
					counter = d[i]
			times = 0
			if counter % k == 0:
				times = counter // k
			else:
				times = counter // k + 1
			tt = ans[0][0]
			tt += letter * times
			print(tt)
		else:
			tt = ans[0][0]
			for i in l:
				tt += i[0] * i[1]
			print(tt)


def solve():
	(N, K) = [int(el) for el in input().split()]
	s = input()
	s = ''.join(sorted(s))
	if s[K - 1] != s[0]:
		return s[K - 1]
	elif len(set(s[K:])) == 1:
		cnt = len(s[K:]) // K
		if len(s[K:]) % K != 0:
			cnt += 1
		return s[0] + s[K] * cnt
	else:
		return s[0] + s[K:]
for t in range(1, int(input()) + 1):
	print(solve())


def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		s = list(input())
		s.sort()
		if len(set(s)) == 1:
			print(''.join(s[:n // k + 1 if n % k != 0 else n // k]))
		elif s[0] != s[k - 1]:
			print(s[k - 1])
		elif len(set(s)) == 2 and s.count(s[0]) == k:
			res = s[0] + s[-1] * (s.count(s[-1]) // k)
			res += s[-1] if s.count(s[-1]) % k != 0 else ''
			print(res)
		else:
			print(''.join([s[0]] + s[k:]))
main()


T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	Str = list(input())
	Str.sort()
	if Str[0] != Str[k - 1]:
		print(Str[k - 1])
	elif Str[0] == Str[k - 1]:
		if k < n and Str[k] != Str[n - 1]:
			print(''.join(Str[k - 1:]))
		else:
			print(Str[k - 1] + Str[n - 1] * ((n - 1) // k))


import sys
input = sys.stdin.readline
from collections import *
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = list(input()[:-1])
	s.sort()
	M = max(s)
	l = [[] for _ in range(k)]
	for i in range(k):
		l[i].append(s[i])
	if n == k:
		print(''.join(l[-1]))
		continue
	flag = True
	for i in range(k):
		flag &= l[i] == l[0]
	if not flag:
		print(''.join(l[-1]))
		continue
	if s[k] == M:
		for i in range(k, n):
			l[i % k].append(s[i])
	else:
		for i in range(k, n):
			l[0].append(s[i])
	for i in range(k):
		l[i] = ''.join(l[i])
	print(max(l))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = input()
	a = sorted(s)
	if a[0] != a[k - 1]:
		ans = a[k - 1]
	elif len(set(a[k:])) == 1:
		q = (n - k) // k
		r = (n - k) % k
		if r == 0:
			ans = a[0] + a[k] * q
		else:
			ans = a[0] + a[k] * (q + 1)
	else:
		y = ''.join((str(x) for x in a[k:]))
		ans = a[0] + y
	print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
testcases = int(input())
for j in range(testcases):
	(n, k) = map(int, input().split())
	string1 = [k for k in input()]
	dict1 = {}
	string1.sort()
	string1.reverse()
	outy = [''] * k
	for s in range(k):
		outy[s] += string1.pop()
	if outy[0] == outy[-1]:
		if len(string1) > 0:
			if string1[0] == string1[-1]:
				for s in range(len(string1)):
					outy[s % k] += string1.pop()
			else:
				for s in range(len(string1)):
					outy[0] += string1.pop()
	else:
		stop = 1
		for s in range(1, k):
			if outy[s] == outy[s - 1]:
				stop = s + 1
			else:
				break
		if len(string1) > 0:
			if string1[0] == string1[-1]:
				for s in range(len(string1)):
					outy[s % stop] += string1.pop()
			else:
				for s in range(len(string1)):
					outy[0] += string1.pop()
	val1 = outy[0]
	val2 = outy[-1]
	broke = False
	for s in range(min(len(val1), len(val2))):
		if val2[s] > val1[s]:
			broke = True
	if broke == False:
		print(val1)
	else:
		print(val2)


from sys import stdin, stdout
T = int(stdin.readline().strip())
for caso in range(T):
	(n, k) = map(int, stdin.readline().strip().split())
	s = list(stdin.readline().strip())
	s.sort()
	s1 = ''
	for i in s:
		s1 += i
	s = s1
	if k == 1:
		print(s1)
		continue
	if s[0] != s[k - 1] or k == len(s):
		print(s[k - 1])
		continue
	if s[k] == s[-1]:
		x = len(s) - k
		y = x // k
		if x % k != 0:
			y += 1
		print(s[k - 1] + s[k] * y)
		continue
	print(s1[k - 1:])


from collections import Counter
import string

def solve(s, k):
	counts = Counter(s)
	sorteds = []
	for c in string.ascii_lowercase:
		if c in counts:
			for _ in range(counts[c]):
				sorteds.append(c)
	if sorteds[0] != sorteds[k - 1] or len(s) == k:
		return sorteds[k - 1]
	if sorteds[k] != sorteds[-1]:
		return ''.join(sorteds[0:1] + sorteds[k:])
	return ''.join(sorteds[0:1] + sorteds[k:(len(s) - k + k - 1) // k + k])
m = int(input())
for _ in range(m):
	(n, k) = list(map(int, input().split()))
	s = input()
	print(solve(s, k))


t = int(input())
for i in range(t):
	s = input().split()
	n = int(s[0])
	k = int(s[1])
	l = []
	for j in range(26):
		l.append(0)
	s = input()
	for j in range(n):
		l[ord(s[j]) - 97] += 1
	x = []
	a = 0
	for j in range(26):
		if l[j] != 0:
			x.append([])
			x[a].append(j)
			x[a].append(l[j])
			a += 1
	p = []
	p1 = -1
	for j in range(len(x)):
		if x[j][1] % k != 0:
			p2 = x[j][0]
			p1 = j
			break
	if x[0][1] > k and len(x) != 1:
		for a in range(x[0][1] - k + 1):
			p.append(x[0][0])
		for a in range(1, len(x)):
			for b in range(x[a][1]):
				p.append(x[a][0])
	elif len(x) == 1:
		if x[0][1] % k == 0:
			a = x[0][1] // k
		else:
			a = x[0][1] // k + 1
		for j in range(a):
			p.append(x[0][0])
	elif x[0][1] < k:
		count = 0
		flag = 0
		for a in range(len(x)):
			for b in range(x[a][1]):
				count += 1
				if count == k:
					p.append(x[a][0])
					flag = 1
			if flag == 1:
				break
	elif x[0][1] == k and len(x) == 2:
		p.append(x[0][0])
		if x[1][1] % k == 0:
			a = x[1][1] // k
		else:
			a = x[1][1] // k + 1
		for j in range(a):
			p.append(x[1][0])
	elif x[0][1] == k:
		p.append(x[0][0])
		for a in range(1, len(x)):
			for b in range(x[a][1]):
				p.append(x[a][0])
	for j in range(len(p)):
		p[j] = chr(p[j] + 97)
	for j in range(len(p)):
		print(p[j], end='')
	print('')


q = int(input())
while q:
	q -= 1
	(n, k) = map(int, input().strip().split(' '))
	s = list(input())
	s.sort()
	j = set(s[:k])
	v = set(s[k:])
	if len(j) == 1:
		t = s[k - 1]
		if len(v) == 1:
			t += s[k] * ((n - k) // k) + s[k] * min(1, (n - k) % k)
		else:
			t = t + ''.join(s[k:])
		print(t)
	else:
		print(s[k - 1])


from collections import Counter

def LongTail(stats):
	return ''.join(sorted(stats.elements()))
count = int(input())
for _ in range(count):
	(n, parts) = [int(num) for num in input().split()]
	word = input()
	stats = Counter(word)
	not_max = parts
	answer = ''
	if parts == 1:
		answer = LongTail(stats)
	elif len(stats) == 1:
		answer = min(stats) * ((len(word) - 1) // parts + 1)
		stats = Counter()
	elif stats[min(stats)] == parts:
		answer += min(stats)
		del stats[min(stats)]
		if len(stats) > 1:
			answer += LongTail(stats)
		else:
			answer += min(stats) * ((stats[min(stats)] - 1) // parts + 1)
	elif stats[min(stats)] > parts:
		stats[min(stats)] -= parts - 1
		answer = LongTail(stats)
	else:
		for letter in sorted(list(stats)):
			if parts > stats[letter]:
				parts -= stats[letter]
			else:
				answer = letter
				break
	print(answer)


t = int(input())
while t != 0:
	t -= 1
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	s = input()
	s = list(s)
	s.sort()
	s = ''.join(s)
	if s[0] != s[k - 1]:
		print(s[k - 1])
	else:
		p = set(s[k:])
		if len(p) == 1:
			lt = [s[0] for _ in range(k)]
			for i in range(k, n):
				lt[i % k] += s[i]
			print(max(lt))
		else:
			ans = s[0] + s[k:]
			print(ans)


import math
for i in range(int(input())):
	(n, k) = map(int, input().split())
	fin = ''
	st = input()
	string = sorted(st)
	if n == k:
		print(string[-1])
		continue
	if string[k - 1] != string[0]:
		print(string[k - 1])
		continue
	else:
		fin += string[k - 1]
		if string[-1] == string[k]:
			diff = math.ceil((n - k) / k)
			fin += string[-1] * diff
		else:
			fin += ''.join(string[k:n])
	print(fin)


import sys
input = sys.stdin.readline
from math import ceil
from collections import Counter
from string import ascii_lowercase as letters

def print(val):
	sys.stdout.write(val + '\n')

def prog():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		s = Counter(input().strip())
		if len(s) == 1:
			for val in s:
				print(val * ceil(s[val] / k))
		else:
			for letter in letters:
				if s[letter] != 0:
					if s[letter] > k or (s[letter] == k and len(s) > 2):
						output = [letter] * (s[letter] - (k - 1))
						last = letter
						for letter in letters:
							if s[letter] != 0 and letter != last:
								output.extend([letter] * s[letter])
						print(''.join(output))
						break
					elif s[letter] == k:
						output = letter
						last = letter
						for letter in s:
							if letter != last:
								output += letter * ceil(s[letter] / k)
						print(output)
					else:
						for letter in letters:
							if k - s[letter] > 0:
								k -= s[letter]
							else:
								print(letter)
								break
					break
prog()


import math

def task(n, k, s):
	s = [char for char in s]
	s.sort()
	mn = min(s[0:k])
	mx = max(s[0:k])
	if mn != mx or k == n:
		print(mx)
		return
	a = [mn]
	mn = min(s[k:])
	mx = max(s[k:])
	if mn != mx:
		a += s[k:]
		print(''.join(map(str, a)))
		return
	repeats = math.ceil((n - k) / k)
	a += repeats * mx
	print(''.join(map(str, a)))
t = int(input())
for i in range(0, t):
	(n, k) = map(int, input().split())
	s = input()
	task(n, k, s)


from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def powmod(a, b):
	a %= mod
	if a == 0:
		return 0
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % mod
		a = a * a % mod
		b >>= 1
	return res

def solve():
	for _ in range(ii()):
		(n, k) = mi()
		s = si()
		x = [0] * 26
		for i in s:
			x[ord(i) - ord('a')] += 1
		p = []
		for i in range(26):
			if x[i] > 0:
				p.append(i)
		s1 = 0
		f1 = 0
		f = 0
		for i in range(26):
			s1 += x[i]
			if s1 >= k:
				c = chr(97 + i)
				if f1:
					print(c)
				elif len(p) > 2:
					ans = c * (s1 - k + 1)
					for j in range(i + 1, 26):
						c = chr(97 + j)
						ans += c * x[j]
					print(ans)
				elif len(p) == 1:
					print(c * ceil(s1 / k))
				elif s1 == k:
					ans = c
					if len(p) > 1:
						ans += chr(97 + p[1]) * ceil(x[p[1]] / k)
					print(ans)
				else:
					ans = c * (s1 - k + 1)
					if len(p) > 1:
						ans += chr(97 + p[1]) * x[p[1]]
					print(ans)
				break
			if x[i] > 0:
				f1 = 1
solve()


import math
from collections import Counter, deque
L = lambda : list(map(int, input().split()))
M = lambda : map(int, input().split())
I = lambda : int(input())
IN = lambda : input()
mod = 10 ** 9 + 7

def s(a):
	print(' '.join(list(map(str, a))))
for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = input()
	x = list(a)
	x.sort()
	if x[k - 1] > x[0] or n == k:
		print(x[k - 1])
	else:
		print(x[0], end='')
		x = x[k:]
		n -= k
		if x[0] == x[-1]:
			print(x[0] * ((n - 1) // k + 1))
		else:
			print(*x, sep='')


import os
import sys
from io import BytesIO, IOBase
import threading
from math import floor
from bisect import bisect_right
from collections import Counter
from math import gcd
mod = 998244353

def main():
	for i in range(int(input())):
		(n, k) = map(int, input().split())
		s = input()
		l = [c for c in s]
		l.sort()
		s = Counter(l)
		val = list(s.values())
		b = True
		for i in val:
			if i != k:
				b = False
		if l[k - 1] != l[0]:
			print(l[k - 1])
		else:
			s = Counter(l[k:])
			ans = [l[0]]
			if len(list(s.keys())) == 1:
				for i in range(k, n, k):
					ans.append(l[i])
				print(''.join(ans))
			else:
				print(''.join(l[k - 1:]))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import math
t = int(input())
for numtests in range(t):
	nums = input().split()
	n = int(nums[0])
	k = int(nums[1])
	string = input()
	s = [char for char in string]
	s.sort()
	if s[k - 1] != s[0] or k == n:
		print(s[k - 1])
	else:
		if s[k] == s[n - 1]:
			print(s[0], end='')
			for i in range(math.ceil((n - k) / k)):
				print(s[k], end='')
		else:
			print(s[0], end='')
			for i in range(n - k):
				print(s[k + i], end='')
		if numtests != t - 1:
			print('')


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	s = input()
	s = sorted(s)
	if n == k:
		print(s[-1])
		continue
	if s[0] != s[k - 1]:
		print(s[k - 1])
		continue
	if s[k] == s[-1]:
		l = (len(s) - 1) // k
		print(s[0] + s[k] * l)
		continue
	print(s[0] + ''.join(s[k:]))


import math
from collections import Counter

def solve():
	(n, k) = map(int, input().split())
	l1 = list(input())
	l1.sort()
	s1 = ''.join(l1)
	if k == 1:
		print(s1)
		return
	d = Counter(s1)
	v = list(d.items())
	v.sort()
	if 1:
		c = len(d)
		if c == 1:
			kk = v[0][1]
			gg = math.ceil(kk / k)
			print(v[0][0] * gg)
			return
		elif c == 2:
			if v[0][1] < k:
				print(v[1][0])
				return
			else:
				if v[0][1] == k:
					c1 = 1
					c2 = math.ceil(v[1][1] / k)
				else:
					c1 = v[0][1] - k + 1
					c2 = v[1][1]
				print(v[0][0] * c1 + v[1][0] * c2)
				return
		else:
			if v[0][1] < k:
				print(s1[k - 1])
				return
			else:
				if v[0][1] == k:
					c1 = 1
				else:
					c1 = v[0][1] - k + 1
				d1 = v[0][0] * c1
				for i in range(1, c):
					d1 += v[i][0] * v[i][1]
			print(d1)
			return
for _ in range(int(input())):
	solve()


import math

def solve():
	(n, k) = map(int, input().split())
	s = input()
	s = ''.join(sorted(s))
	if n == k and n == 1:
		print(s)
		return None
	if s[0] != s[k - 1]:
		print(s[k - 1])
		return None
	print(s[0], end='')
	if n != k and s[k] != s[n - 1]:
		print(s[k:])
	else:
		for _ in range(math.ceil((n - k) / k)):
			print(s[k], end='')
		print()
	return None
t = int(input())
for _ in range(t):
	solve()


def solve(s, k):
	if len(s) <= k:
		return [s[-1]]
	if s[0] != s[k - 1]:
		return [s[k - 1]]
	if s[k] != s[-1]:
		return [s[0]] + s[k:]
	return [s[0]] + s[k:k + (len(s) - 1) // k]
for _ in range(int(input())):
	(n, k) = (int(x) for x in input().split())
	s = sorted(list(input()))
	print(''.join(solve(s, k)))


t = int(input())
for _ in range(t):
	(_, k) = map(int, input().split())
	s = list(input())
	s.sort(reverse=True)
	r = []
	for _ in range(k):
		r.append(s.pop())
	if r[k - 1] > r[0] or not s:
		print(r[k - 1])
		continue
	max_c = max(s)
	next_c = s[-1]
	if next_c != max_c:
		while s:
			r[k - 1] += s.pop()
		print(r[k - 1])
		continue
	while s:
		r[0] += s.pop()
		r.sort()
	print(r[k - 1])


import math
T = int(input())
for t in range(T):
	(N, K) = [int(_) for _ in input().split()]
	S = sorted(input())
	if S[K - 1] != S[0] or K == len(S):
		print(S[K - 1])
		continue
	if S[K] == S[-1]:
		print(S[0] + S[K] * math.ceil((len(S) - K) / K))
	else:
		print(S[0] + ''.join(S[K:]))


for testcase in range(int(input())):
	(n, k) = map(int, input().split())
	s = ''.join(sorted(input().strip()))
	if k == 1:
		print(s)
		continue
	if s[0] != s[k - 1]:
		print(s[k - 1])
		continue
	d = [0] * 26
	for i in s[k:]:
		d[ord(i) - ord('a')] += 1
	n -= k
	ans = s[k - 1]
	for i in range(26):
		if d[i] == 0:
			continue
		c = chr(i + ord('a'))
		if d[i] == n:
			ans += c * ((d[i] + k - 1) // k)
			break
		ans += c * d[i]
		for f in range(i + 1, 26):
			ans += chr(f + ord('a')) * d[f]
		break
	print(ans)


import sys
import math
input = sys.stdin.readline

def pi():
	return int(input())

def ti():
	return list(map(int, input().split()))

def ts():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def main():
	t = pi()
	while t > 0:
		t -= 1
		[n, k] = ti()
		s = ts()
		if len(s) == 1:
			print(s[0])
			continue
		s = sorted(s)
		if s[0] != s[k - 1]:
			print(s[k - 1])
			continue
		res = s[0]
		if k < n and s[k] == s[n - 1]:
			d = n - k
			for i in range(int(d / k)):
				res += s[k]
			if d % k != 0:
				res += s[k]
			print(res)
		else:
			for i in range(k, n, 1):
				res += s[i]
			print(res)
main()


t = int(input())
ans = ''
while t > 0:
	t -= 1
	(n, k) = list(map(int, input().split(' ')))
	s = sorted(input())
	res = s[k - 1]
	n = len(s)
	if s[0] != s[k - 1]:
		pass
	elif k <= n - 1 and s[k] == s[n - 1]:
		for i in range(k, n, k):
			res += s[i]
	else:
		for i in range(k, n):
			res += s[i]
	ans += res
	ans += '\n'
print(ans)


def main_function():
	from sys import stdin
	input = stdin.readline
	t = int(input())
	for _ in range(t):
		(n, k) = list(map(int, input().split()))
		a = list(input()[:-1])
		a.sort()
		if len(set(a)) == 1:
			print(''.join(a[:n // k + 1 if n % k != 0 else n // k]))
			continue
		if a[k - 1] != a[0]:
			print(a[k - 1])
		elif len(set(a)) == 2 and a.count(a[0]) == k:
			tmp = a[0] + a[-1] * (a.count(a[-1]) // k)
			tmp += a[-1] if a.count(a[-1]) % k != 0 else ''
			print(tmp)
		else:
			print(''.join([a[0]] + a[k:]))
main_function()


import bisect as bi
import sys
import collections as cc
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(n, m) = I()
	s = sorted(input())
	if m == 1:
		print(''.join(s))
	elif m == n:
		print(s[m - 1])
	else:
		ans = ''
		temp = s[:m]
		if temp[0] != temp[-1]:
			print(temp[-1])
		else:
			te = s[m:]
			ans = temp[-1]
			if te[0] == te[-1]:
				t = te[0] * ((n - 1) // m)
				print(ans + t)
			else:
				ans += ''.join(te)
				print(ans)


import sys
stdin = sys.stdin
ns = lambda : stdin.readline().rstrip()
ni = lambda : int(stdin.readline().rstrip())
nm = lambda : map(int, stdin.readline().split())
nl = lambda : list(map(int, stdin.readline().split()))

def solve():
	(n, k) = nm()
	s = list(ns())
	s.sort()
	if s[0] != s[k - 1]:
		print(s[k - 1])
		return
	if len(set(s[k:])) == 1:
		ret = s[::k]
	else:
		ret = [s[0]] + s[k:]
	print(''.join(ret))
	return
t = ni()
for _ in range(t):
	solve()


import sys
input = sys.stdin.readline
inf = 100000000000000000
mod = 998244353
for CASES in range(int(input())):
	(n, m) = map(int, input().split())
	S = input().strip()
	S = sorted(list(S))
	if S[0] != S[m - 1]:
		print(S[m - 1])
	else:
		ANS1 = ''.join(map(str, S[0])) + ''.join(map(str, S[m:]))
		ANS2 = ''
		for i in range(m):
			ANS2 = max(ANS2, ''.join(map(str, S[i::m])))
		ANS = min(ANS1, ANS2)
		print(ANS)


from collections import Counter
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(input())
	a.sort()
	b = Counter(a)
	c = list(b.keys())
	d = ''
	d = d.join(a)
	if len(b) == 1:
		if b[c[0]] % k == 0:
			print(c[0] * (b[c[0]] // k))
		else:
			print(c[0] * (b[c[0]] // k) + c[0])
	elif b[c[0]] == k and len(b) == 2:
		if b[c[1]] <= k:
			print(c[0] + c[1])
		elif b[c[1]] % k == 0:
			print(c[0] + c[1] * (b[c[1]] // k))
		else:
			print(c[0] + c[1] * (b[c[1]] // k + 1))
	elif b[c[0]] >= k:
		print(d[k - 1:])
	else:
		no = 0
		for i in c:
			no += b[i]
			if no >= k:
				print(i)
				break


def main():
	from bisect import bisect_left as bl, bisect_right as br, insort
	import sys, heapq, math
	from collections import defaultdict as dd, deque

	def data():
		return sys.stdin.readline().strip()

	def mdata():
		return list(map(int, data().split()))
	out = sys.stdout.write
	INF = int(1000000000.0)
	mod = int(1000000000.0) + 7
	for i in range(int(data())):
		(n, k) = mdata()
		s = sorted(data())
		ind = 0
		if k == 1:
			out(''.join(s) + '\n')
		elif s[0] < s[k - 1]:
			out(s[k - 1] + '\n')
		else:
			ans = ''
			d = dd(int)
			for i in s:
				d[i] += 1
			l = sorted(d.keys())
			if len(l) == 1:
				ans = d[l[0]] // k * l[0]
				if d[l[0]] % k != 0:
					ans += l[0]
			elif len(l) == 2 and d[l[0]] == k:
				ans = l[0] + d[l[1]] // k * l[1]
				if d[l[1]] % k != 0:
					ans += l[1]
			else:
				ans = ''.join(s[k - 1:])
			out(ans + '\n')
main()


def min_string(s, k):
	S = sorted(s)
	n = len(s)
	a = int(n / k)
	L = [''] * k
	for i in range(k):
		L[i] = L[i] + S[i]
	if n == k:
		return L[k - 1]
	elif L[k - 1] != L[0]:
		return S[k - 1]
	elif S[n - 1] != S[k]:
		p = ''
		for i in range(k - 1, n):
			p = p + S[i]
		return p
	else:
		for i in range(k, n):
			b = i % k
			L[b] = L[b] + S[i]
		return L[0]
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	s = input()
	print(min_string(s, k))


def split(k, s):
	sl = sorted(list(s))
	if k == 1:
		print(''.join(sl))
		return
	elif sl[k - 1] != sl[0]:
		print(sl[k - 1])
		return
	counts = {}
	for i in sl[k:]:
		if i not in counts:
			counts[i] = 1
		else:
			counts[i] += 1
	if len(counts) == 1:
		nl = counts[sl[-1]] // k
		if k * nl < counts[sl[-1]]:
			nl += 1
		print(''.join(sl[:1] + [sl[-1] for i in range(nl)]))
		return
	print(''.join(sl[:1] + sl[k:]))
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	split(k, input())


t = int(input())
for t1 in range(t):
	(n, k) = map(int, input().split())
	s = input()
	sch = list(s)
	sch.sort()
	if k == 1:
		print(''.join(sch))
		continue
	if sch[0] != sch[k - 1]:
		print(''.join(sch[k - 1]))
		continue
	se = set()
	firstDif = -1
	for i in range(len(sch)):
		se.add(sch[i])
		if i > 0 and sch[i] != sch[i - 1] and (firstDif == -1):
			firstDif = i
	if len(se) > 2:
		print(''.join(sch[k - 1:n]))
		continue
	if len(se) == 1:
		ost = (1, 0)[n % k == 0]
		print(''.join(sch[0:n // k + ost]))
		continue
	if firstDif > k:
		print(''.join(sch[k - 1:n]))
	else:
		ost = (1, 0)[(n - firstDif) % k == 0]
		print(''.join(sch[0:firstDif // k]) + ''.join(sch[firstDif:firstDif + (n - firstDif) // k + ost]))


import math
import sys
from collections import defaultdict, Counter, deque, OrderedDict
import bisect
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]
from itertools import accumulate, groupby
for _ in range(int(input())):
	(n, k) = ilele()
	s = input()
	S = [*s]
	S.sort()
	T = S[:k]
	f = len(set(T))
	if f == 1 and len(set(S[k:])) == 1:
		z = T[0] + (n - k) // k * S[-1]
		if (n - k) % k != 0:
			z += S[-1]
		print(z)
	else:
		z = T[0] + ''.join(S[k:])
		print(max(z, T[-1]))


from collections import Counter
from string import ascii_lowercase as al
t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	ct = [0] * 26
	s = input()
	for c in s:
		ct[ord(c) - ord('a')] += 1
	ctp = []
	ctpc = []
	for (ctr, c) in zip(ct, al):
		if ctr:
			ctp.append(ctr)
			ctpc.append(c)
	if ctp[0] < k:
		print(list(sorted(list(s)))[k - 1])
		continue
	if len(ctp) == 1:
		print(ctpc[0] * ((ctp[0] + k - 1) // k))
		continue
	if ctp[0] == k and len(ctp) == 2:
		print(ctpc[0] + ctpc[1] * ((ctp[1] + k - 1) // k))
		continue
	res = [ctpc[0]] * (ctp[0] - k + 1)
	for (c, ct) in zip(ctpc[1:], ctp[1:]):
		res.extend([c] * ct)
	print(''.join(res))


t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	a = list(input())
	a.sort()
	if n == k:
		print(a[-1])
	elif a[k - 1] != a[0]:
		print(a[k - 1])
	elif a[k] == a[n - 1]:
		x = n - k
		print(a[0], end='')
		for i in range(0, x, k):
			print(a[k], end='')
		print()
	else:
		for i in range(k - 1, n):
			print(a[i], end='')
		print()
	t -= 1


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	s = input()
	chars = sorted([c for c in s])
	if chars[k - 1] > chars[0]:
		print(chars[k - 1])
	elif chars[0] == chars[n - 1]:
		print(''.join([chars[0]] * ((n + k - 1) // k)))
	elif chars[k] != chars[0] and chars[k] == chars[n - 1]:
		print(''.join([chars[0]] + [chars[k]] * ((n - 1) // k)))
	else:
		print(''.join(chars[k - 1:]))


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = list(reversed(sorted(input())))
	ss = ['' for _ in range(k)]
	for i in range(k):
		ss[i] += s.pop()
	if ss[0] != ss[-1] or len(s) == 0:
		print(ss[-1])
	elif s[0] == s[-1]:
		print(ss[0] + math.ceil(len(s) / k) * s[0])
	else:
		while len(s):
			ss[0] += s.pop()
		print(ss[0])


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	string = input()
	arr = []
	for i in string:
		arr += [i]
	arr.sort()
	worststring = ''
	slicearr = arr[:k]
	if slicearr[-1] == slicearr[0]:
		worststring += slicearr[0]
	else:
		worststring = slicearr[-1]
		print(worststring)
		continue
	slicearr = arr[k:]
	if slicearr != []:
		if slicearr[0] == slicearr[-1]:
			worststring += slicearr[0] * ((n - k - 1) // k + 1)
		else:
			worststring += ''.join(slicearr)
	print(worststring)


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict, Counter
import math

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
t = int(input())
while t > 0:
	t -= 1
	(n, k) = listIn()
	s = input()
	st = sorted(s)
	di = Counter(s)
	if st[k - 1] != st[0]:
		print(st[k - 1])
	else:
		left = ''.join(st[k:])
		if len(set(left)) == 1:
			print(st[0] + left[0:math.ceil((n - k) / k)])
		else:
			print(st[0] + left)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = I()
	rr = []
	for _ in range(t):
		(n, k) = LI()
		s = S()
		c = sorted(collections.Counter(s).items())
		if c[0][1] < k:
			t = 0
			for (a, b) in c:
				t += b
				if t >= k:
					r = a
					break
		elif len(c) == 1:
			r = c[0][0] * ((c[0][1] + k - 1) // k)
		elif c[0][1] == k:
			if len(c) == 2:
				r = c[0][0] + c[1][0] * ((c[1][1] + k - 1) // k)
			else:
				r = c[0][0]
				for (a, b) in c[1:]:
					r += a * b
		else:
			c[0] = (c[0][0], c[0][1] - k)
			r = c[0][0]
			for (a, b) in c:
				r += a * b
		rr.append(r)
	return JA(rr, '\n')
print(main())


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = sorted(input())
	string = ''
	if s[0] == s[k - 1]:
		string += s[0]
		if k != n:
			if s[k] == s[-1]:
				if s[k] == s[0]:
					string = s[-1] * ((n + k - 1) // k)
				else:
					string += s[-1] * ((n - 1) // k)
			else:
				string += ''.join(s[k:])
	else:
		string = s[k - 1]
	print(string)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort()
	x = 1
	if len(set(s)) == 1:
		print(''.join([s[0]] * math.ceil(n / k)))
	elif k == 1:
		print(''.join(s))
	else:
		for i in range(1, n):
			if s[i] == s[0]:
				x += 1
			else:
				break
		if k > x:
			print(s[k - 1])
		elif k < x:
			print(''.join(s[k - 1:]))
		elif len(set(s)) == 2:
			if s.count(s[0]) >= s.count(s[k]):
				print(s[0] + s[k])
			elif s.count(s[k]) % s.count(s[0]) == 0:
				print(''.join([s[0]] + [s[k]] * (s.count(s[k]) // s.count(s[0]))))
			else:
				print(''.join([s[0]] + [s[k]] * (s.count(s[k]) // s.count(s[0]) + 1)))
		else:
			print(''.join(s[k - 1:]))


def solve():
	t = int(input())
	for i in range(t):
		(n, k) = list(map(int, input().split(' ')))
		word = sorted(input())
		add = len
		if k == 1:
			print(''.join(word))
			continue
		lst = []
		for j in range(k):
			lst.append([])
		if add(set(word[:k])) != 1:
			print(word[k - 1])
			continue
		for m in range(k):
			lst[m].append(word.pop(0))
		if add(set(word)) != 1:
			print(''.join(lst[0] + word))
			continue
		elif add(word) <= k:
			lst[0].append(word[0])
			print(''.join(lst[0]))
			continue
		while add(word) > k:
			for m in range(k):
				lst[m].append(word.pop(0))
		lst[0].append(word[0])
		print(''.join(lst[0]))
solve()


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 10 ** 9 + 7

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	(n, k) = li()
	s = ''.join(sorted(st()))
	l1 = [''] * k
	l2 = [''] * k
	if k == 1:
		print(s)
		continue
	if k == n:
		print(s[-1])
		continue
	for i in range(k):
		l1[i] += s[i]
		l2[i] += s[i]
	for i in range(k, n):
		l1[0] += s[i]
		l2[i % k] += s[i]
	l1.sort()
	l2.sort()
	print(min(l1[-1], l2[-1]))


from collections import Counter, defaultdict, deque
import heapq as hq
import math
import sys
input = sys.stdin.readline

def solve():
	(n, k) = [int(x) for x in input().split()]
	arr = [x for x in input().strip()]
	arr.sort()
	first = arr[:k]
	if first[0] == first[-1]:
		rest = arr[k:]
		if len(Counter(rest)) == 1:
			print(first[0] + rest[0] * math.ceil(len(rest) / k))
		else:
			print(first[0] + ''.join(rest))
	else:
		print(first[-1])
tt = int(input())
for test in range(tt):
	solve()


import collections as c
m = int(input())
for j in range(m):
	(n, k) = map(int, input().split())
	s = input()
	a = c.Counter(s)
	b = dict(a)
	a = list(b.keys())
	a.sort()
	ans = ''
	last = -1
	for i in range(len(a)):
		if b[a[i]] % k != 0:
			last = i
			break
	if b[a[0]] < k:
		s = sorted(list(s))
		print(s[k - 1])
	elif len(a) == 1:
		ans += b[a[0]] // k * a[0]
		if b[a[0]] % k != 0:
			ans += a[0]
	elif len(a) == 2 and b[a[0]] == k:
		ans += b[a[0]] // k * a[0]
		ans += b[a[1]] // k * a[1]
		if b[a[1]] % k != 0:
			ans += a[1]
	else:
		ans += a[0]
		ans += ''.join(sorted(list(s)))[k:]
	print(ans)


from math import ceil
t = int(input())
while t:
	t -= 1
	(n, k) = [int(i) for i in input().split()]
	s = input()
	a = []
	for i in s:
		a.append(ord(i) - 97)
	a.sort()
	a1 = a[:k]
	ans = []
	if a1[0] == a1[-1]:
		ans.append(a[0])
		aset = set(a)
		if k < len(a):
			if a[k] == a[0] and len(aset) != 1 and (len(aset) != 2):
				ans.extend(a[k:])
			elif len(aset) == 2:
				if a[k] != a[0]:
					for i in range(ceil((n - k) / k)):
						ans.append(a[k])
				else:
					ans.extend(a[k:])
			elif len(aset) == 1:
				for i in range(ceil((n - k) / k)):
					ans.append(a[k])
			else:
				ans.extend(a[k:])
	else:
		ans.append(a1[-1])
	s = ''
	for i in ans:
		s += chr(i + 97)
	print(s)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
import random
from queue import PriorityQueue
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
import sys
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort()
	cnt = 0
	ans = []
	for i in range(k):
		ans.append(s[i])
	j = k
	i = 0
	z1 = ans[0] + ''.join(s[k:])
	z3 = ans.copy()
	z3.append(z1)
	z3.sort()
	z1 = z3[-1]
	while j < len(s):
		z = i % k
		ans[z] = ans[z] + s[j]
		j += 1
		i += 1
	ans.sort()
	z2 = ans[-1]
	la = [z1, z2]
	la.sort()
	print(la[0])


T = int(input())

def ans():
	(n, k) = input().split(' ')
	k = int(k)
	s = input()
	s = sorted(s)
	ret = []
	for i in range(k):
		ret += [[]]
	for i in range(k):
		ret[i] += [s[i]]
	if ret[0][0] != ret[-1][0]:
		return ret[-1][0]
	s = s[k:]
	if len(set(s)) > 1:
		return ret[0][0] + ''.join(s)
	for i in range(len(s)):
		ret[i % k] += [s[i]]
	return ''.join(ret[0])
	return '?'
for t in range(T):
	print(ans())


import sys
input = sys.stdin.readline
T = int(input())
for testcase in range(T):
	(n, k) = map(int, input().split())
	s = list(input())
	s.pop()
	s.sort()
	res = []
	idx = 0
	while idx < n:
		if idx + k >= n:
			res.append(s[-1])
			break
		if s[idx] == s[idx + k - 1]:
			res.append(s[idx])
		else:
			res.append(s[idx + k - 1])
			break
		idx += k
	ans = ''.join(res)
	if s[0] == s[k - 1]:
		ans2 = ''.join(s[k - 1:])
		print(min(ans, ans2))
	else:
		print(ans)


def rd(n):
	if n == 0:
		return input('')
	if n == 1:
		return int(input())
	if n == 2:
		return map(int, input().split())
	if n == 3:
		return list(map(int, input().split()))

def solve():
	t = rd(1)
	for _ in range(t):
		(n, k) = rd(2)
		A = rd(0)
		s = list(A)
		s.sort()
		ans = s[:k]
		l = ans[-1]
		if ans[0] != l:
			print(l)
			continue
		c = ans.count(l)
		ans = ans[-1:]
		del s[:k]
		if len(set(s)) == 1:
			n = len(s)
			n = n // k + (n % k != 0)
			s = s[:n]
		for i in s:
			ans.append(i)
		final = ''
		for i in ans:
			final += i
		print(final)
solve()


from sys import stdin
cin = lambda : stdin.readline()
mi = lambda : map(int, cin().split())
li = lambda : list(mi())
ri = lambda : int(cin())
for _ in range(ri()):
	(n, k) = mi()
	s = list(cin().strip())
	s.sort()
	ans = ''
	ss = set(s)
	l = len(ss)
	if s[0] != s[k - 1]:
		ans = s[k - 1]
	elif l == 2 or l == 1:
		if l == 2:
			n1 = s.count(s[0])
			n2 = s.count(s[-1])
			if n1 == k:
				ans = s[0] + s[-1] * (n2 // k)
				if n2 % k != 0:
					ans += s[-1]
			else:
				ans = s[0] + s[0] * (n1 - k) + s[-1] * n2
		else:
			ans = s[0] * (n // k)
			if n % k != 0:
				ans += s[0]
	else:
		for i in range(k - 1, n):
			ans += s[i]
	print(ans)


def solve(n, k, s):
	s = sorted(s)
	if k == 1:
		return ''.join(s)
	if s[k - 1] != s[0] or k == n:
		return s[k - 1]
	if s[k] != s[n - 1]:
		return str(s[0]) + ''.join(s[k:])
	return str(s[0]) + str(s[k]) * ((n - 1) // k)
tests = int(input())
for test in range(tests):
	(n, k) = map(int, input().split())
	s = input()
	print(solve(n, k, s))


T = int(input())
for tc in range(T):
	(n, k) = map(int, input().split())
	s = input()
	sorted_list = sorted(s)
	i = 0
	max_ind = i
	while i < k:
		if i > 0 and sorted_list[i] > sorted_list[i - 1]:
			max_ind = i
		i += 1
	if max_ind != 0 or i == n:
		print(sorted_list[max_ind])
		continue
	if sorted_list[i] != sorted_list[n - 1]:
		res = ''
		for i in range(k - 1, n):
			res = res + sorted_list[i]
		print(res)
		continue
	res = ''
	for i in range(0, n, k):
		res = res + sorted_list[i]
	print(res)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	x = list(input())
	x.sort()
	if x[k - 1] != x[0]:
		print(x[k - 1])
	else:
		if len(set(x)) == 1:
			fraction = n // k
			if n % k != 0:
				fraction += 1
			l = x[0] * fraction
		elif len(set(x)) == 2 and x.count(x[0]) == k:
			b_copies = x.count(x[-1])
			fraction = b_copies // k
			if b_copies % k != 0:
				fraction += 1
			l = x[0] + x[-1] * fraction
		else:
			l = [x[0]] + x[k:]
		print(''.join((val for val in l)))


def solve():
	(n, k) = map(int, input().split())
	s = ''.join(sorted(input()))
	if s[0] != s[k - 1] or k == n:
		return s[k - 1]
	if s[k] == s[-1]:
		return s[0] + s[k] * ((n - 1) // k)
	return s[k - 1:]
for _ in range(int(input())):
	print(solve())


import sys
input = sys.stdin.readline
read = lambda : map(int, input().split())
read_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(councils, a, k):
	summ = 0
	for x in a:
		summ += min(x, councils)
	return summ // councils >= k
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
from itertools import permutations
import math
import bisect as bis
import random
import sys

def contains(s):
	s = list(s)
	c = 0
	for i in range(len(s) - 6):
		if ''.join(s[i:i + 7]) == 'abacaba':
			c += 1
	return c

def process(s):
	ans = ''
	for x in s:
		if x == '?':
			ans = ans + 'd'
		else:
			ans = ans + x
	return ans

def solve():
	(n, k) = read()
	s = input().rstrip()
	news = ''.join(list(sorted(s)))
	if news[0] != news[k - 1]:
		print(news[k - 1])
	elif k < n and news[k] == news[-1]:
		print(news[0] + news[k] * ((n - k) // k + ((n - k) % k > 0)))
	else:
		print(news[0] + news[k:])
for _ in range(int(input())):
	solve()


import sys
import math

def read_line():
	return sys.stdin.readline()[:-1]

def read_int():
	return int(sys.stdin.readline())

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]

def read_float_line():
	return [float(v) for v in sys.stdin.readline().split()]
t = read_int()
for i in range(t):
	(n, k) = read_int_line()
	s = read_line()
	ans = [''] * k
	l = [i for i in s]
	l.sort()
	s = l
	f = False
	for i in range(1, k):
		if s[i - 1] != s[i]:
			f = True
	if f:
		print(s[k - 1])
	else:
		for i in range(k):
			ans[i] = s[i]
		for i in range(k + 1, n):
			if s[i - 1] != s[i]:
				f = True
		if not f:
			j = k
			i = 0
			while j < n:
				ans[i % k] += s[j]
				i += 1
				j += 1
			print(max(ans))
		else:
			st = ''
			for i in range(k, n):
				st += s[i]
			ans[0] = ans[0] + st
			print(max(ans))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = sorted(input())
	string = ''.join(s)
	res = [string[i] for i in range(k)]
	if res[-1] == res[0]:
		if len(set(string[k:])) != 1:
			print(res[0] + string[k:])
		else:
			x = (n - k) // k
			if (n - k) % k != 0:
				x += 1
			print(res[0] + string[k] * x)
	else:
		print(res[-1])


t = int(input())
for T in range(t):
	(n, k) = map(int, input().split())
	s = input()
	l = list(s)
	l.sort()
	init = set(l[:k])
	if len(init) > 1:
		print(l[k - 1])
	else:
		init = set(l[k:])
		if len(init) == 1:
			if (n - k) % k == 0:
				ans = (n - k) // k
			else:
				ans = (n - k) // k + 1
			print(''.join(l[k - 1:k - 1 + ans + 1]))
		else:
			print(''.join(l[k - 1:]))


def solve(case):
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort()
	if k == 1:
		print(''.join(s))
	else:
		idx = 0
		fs = ''
		ls = ''
		if s[0] != s[k - 1]:
			print(s[k - 1])
		elif k < n and s[k] != s[n - 1]:
			out = s[k - 1]
			for i in range(k, n):
				out += s[i]
			print(out)
		else:
			while True:
				fs += s[idx]
				ls += s[idx + k - 1]
				idx += k
				if idx >= n:
					print(ls)
					break
				if idx + k - 1 >= n:
					print(fs + s[n - 1])
					break
for _ in range(int(input())):
	solve(1)


import itertools

def brute(s, k):
	n = len(s)
	result = 'z' * len(s)
	for assignments in itertools.product(list(range(k)), repeat=n):
		buckets = [[] for _ in range(k)]
		for (c, assign) in zip(s, assignments):
			buckets[assign].append(c)
		if any((len(bucket) == 0 for bucket in buckets)):
			continue
		currStr = max((''.join((c for c in sorted(bucket))) for bucket in buckets))
		result = min(result, currStr)
	return result

def fast(s, k):
	sSorted = sorted(s)
	if k == 1:
		return ''.join(sSorted)
	if sSorted[0] != sSorted[k - 1]:
		return sSorted[k - 1]
	elif len(set(sSorted[k:])) == 1:
		resultArr = [sSorted[0]]
		ctr = 0
		for c in sSorted[k:]:
			if c != resultArr[-1]:
				resultArr.append(c)
				ctr = 1
			else:
				if ctr == 0:
					resultArr.append(c)
				ctr = (ctr + 1) % k
		return ''.join(resultArr)
	return ''.join([sSorted[0]] + sSorted[k:])
import random
import string

def randomTest():
	t = 10000
	for i in range(1, t + 1):
		n = random.randint(1, 6)
		s = ''.join([random.choice(string.ascii_lowercase) for _ in range(n)])
		k = random.randint(1, n)
		print(i, s, k)
		b = brute(s, k)
		f = fast(s, k)
		if b != f:
			print('Broken!')
			print(b, f)
			return

def main():
	t = int(input())
	for _ in range(t):
		(n, k) = [int(x) for x in input().split()]
		s = input()
		result = fast(s, k)
		print(result)

def test():
	s = 'lww'
	k = 1
	b = brute(s, 1)
	f = fast(s, 1)
	print(b, f)
main()


import math
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	b = input()
	c = []
	for j in range(n):
		c.append(b[j])
	c.sort()
	p = c[k - 1]
	if k < n:
		q = c[k]
	r = 0
	s = 0
	for j in range(k - 1):
		if c[j] != p:
			r += 1
	for j in range(k, n):
		if c[j] != q:
			s += 1
	if r > 0:
		print(p)
	elif s > 0:
		print(''.join(c[k - 1:]))
	else:
		y = math.ceil((n - k) / k)
		if k == n:
			print(p)
		else:
			print(p + q * y)


import sys
import math

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]
import math
t = int(input())
for q in range(t):
	(n, k) = inputnums()
	s = inputstring()
	s.sort()
	if k == 1:
		for i in s:
			print(i, end='')
		print()
		continue
	l = []
	for i in range(k):
		l.append(s[i])
	s = s[k:]
	setl = list(set(l))
	sets = list(set(s))
	ll = len(setl)
	ls = len(sets)
	if ls < ll:
		print(l[-1])
		continue
	elif ll == 1 and ls > 1:
		for x in range(len(s)):
			l[-1] += s[x]
	elif ll == 1:
		l[0] += s[0] * max(1, math.ceil(len(s) / k))
	l.sort()
	print(l[-1])


_IS_DEBUG_MODE = False

def Problem():
	if _IS_DEBUG_MODE == True:
		testcaseList = []
		testcaseList.append([4, 2, list('baba')])
		testcaseList.append([5, 2, list('baacb')])
		testcaseList.append([5, 3, list('baacb')])
		testcaseList.append([5, 3, list('aaaaa')])
		testcaseList.append([6, 4, list('aaxxzz')])
		testcaseList.append([7, 1, list('phoenix')])
		testcaseList.append([6, 2, list('aaabbc')])
		testcaseList.append([10, 10, list('aaaaabbbbb')])
		testcaseList.append([5, 2, list('aaaaa')])
		testcaseList.append([1, 1, list('a')])
		testcaseList.append([2, 2, list('aa')])
	else:
		t = int(input())
		testcaseList = []
		for testcaseIndex in range(t):
			(n, k) = list(map(int, input().split()))
			s = list(input())
			testcaseList.append([n, k, s])
	return testcaseList

def Solver(testcaseList):
	for (n, k, s) in testcaseList:
		if _IS_DEBUG_MODE == True:
			print('testcase', n, k, s)
		s.sort()
		if k == 1:
			print(''.join(s))
			continue
		aList = []
		for i in range(k):
			aList.append(s.pop(0))
		if aList[0] < aList[-1] or len(s) == 0:
			print(aList[-1])
			continue
		if len(s) == 1:
			print(aList[0] + s[0])
			continue
		if s[0] < s[-1]:
			aList[0] += ''.join(s)
			print(aList[0])
			continue
		for i in range(int(len(s) / k)):
			aList[0] += s[0]
		if len(s) % k > 0:
			aList[0] += s[0]
		print(aList[0])
if _IS_DEBUG_MODE == True:
	import time
	startTime = time.time()
testcaseList = Problem()
Solver(testcaseList)
if _IS_DEBUG_MODE == True:
	endTime = time.time()
	print('time', endTime - startTime)


from collections import Counter
from collections import defaultdict
import math
import sys
input = sys.stdin.readline
rs = lambda : input().strip()
ri = lambda : int(input())
rl = lambda : list(map(int, input().split()))
rls = lambda : list(map(str, input().split()))
from collections import deque
t = int(input())
for _ in range(0, t):
	(n, k) = rl()
	s = list(rs())
	s.sort()
	if s[0] != s[k - 1]:
		print(s[k - 1])
		continue
	ans = ''
	if k < n and s[k] != s[-1]:
		ans = s[0]
		for i in range(k, n):
			ans = ans + s[i]
		print(ans)
	else:
		ans = s[0]
		ans = ans + s[-1] * ((n - 1) // k)
		print(ans)


from sys import stdin
from math import gcd, sqrt
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
hg = lambda x, y: (y + x - 1) // x * x
for _ in range(I()):
	(n, k) = R()
	s = ''.join(sorted(S()))
	if s[0] != s[k - 1] or k == n:
		print(s[k - 1])
	elif s[k] == s[-1]:
		print(s[0] + s[k] * ((n - 1) // k))
	else:
		print(s[k - 1:])


import sys
input = sys.stdin.readline
MOD = 1000000007
MOD2 = 998244353
ii = lambda : int(input().strip('\n'))
si = lambda : input().strip('\n')
dgl = lambda : list(map(int, input().strip('\n')))
f = lambda : map(int, input().strip('\n').split())
il = lambda : list(map(int, input().strip('\n').split()))
ls = lambda : list(input().strip('\n'))
let = 'abcdefghijklmnopqrstuvwxyz'
for _ in range(ii()):
	(n, k) = f()
	s = ''.join(sorted(si()))
	if s[k - 1] != s[0] or k == n:
		print(s[k - 1])
	elif s[k] == s[n - 1]:
		print(s[k - 1] + s[k] * ((n - 1) // k))
	else:
		print(s[0] + s[k:])


from sys import stdin

def inp():
	return stdin.buffer.readline().rstrip().decode('utf8')

def itg():
	return int(stdin.buffer.readline())

def mpint():
	return map(int, stdin.buffer.readline().split())
from math import ceil
for case in range(itg()):
	(n, k) = mpint()
	s = list(inp())
	s.sort()
	if k == 1:
		print(''.join(s))
		continue
	arr = s[:k]
	s = s[k:]
	for i in range(1, k):
		if arr[i - 1] != arr[i]:
			print(arr[-1])
			break
	else:
		ans = arr[0]
		st = set(s)
		if len(st) == 1:
			ans += st.pop() * ceil(len(s) / k)
		else:
			ans += ''.join(s)
		print(ans)


from math import ceil
t = int(input())
while t:
	(n, k) = [int(x) for x in input().split()]
	s = input()
	s = list(s)
	s.sort()
	if s[0] != s[k - 1] or k == n:
		print(s[k - 1])
	else:
		poss = True
		for i in range(k + 1, len(s)):
			if s[k] != s[i]:
				poss = False
		if poss:
			print(str(s[0]) + ''.join(s[k] * ceil((n - k) / k)))
		else:
			print(str(s[0]) + ''.join(s[k:]))
	t -= 1


from math import ceil
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = sorted(input())
	cnt = 0
	for c in s:
		if c == s[0]:
			cnt += 1
		else:
			break
	if cnt < k:
		print(s[k - 1])
	else:
		print(s[0], end='')
		if n > k:
			rem = set(s[k:])
			if len(rem) > 1:
				print(*s[k:], sep='')
			else:
				print(*ceil((n - k) / k) * s[k], sep='')
		else:
			print()


import math
testCases = int(input())
for _ in range(testCases):
	(n, k) = map(int, input().split())
	a = ''.join(sorted(input()))
	if n == k or a[0] != a[k - 1]:
		print(a[k - 1])
	elif a[k] == a[-1]:
		print(a[0] + a[k] * ((n - 1) // k))
	else:
		print(a[k - 1:])


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	s = input()
	s = list(s)
	s.sort()
	if n == k:
		print(s[-1])
	elif len(set(s[:k])) >= 2:
		print(s[k - 1])
	elif len(set(s[k:])) >= 2:
		ans = s[0]
		for i in range(k, n):
			ans += s[i]
		print(ans)
	else:
		print(s[0] + s[k] * ((n - 1) // k))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = sorted(input())
	start = s[:k].copy()
	flag = 1 if len(set(start)) == 1 else 0
	flag2 = 1 if len(set(s[k:])) == 1 else 0
	if flag == 1 and flag2 == 1:
		print(start[0] + s[k] * ((n - k) // k + (1 if (n - k) % k != 0 else 0)))
	elif flag == 1:
		print(s[0] + ''.join(s[k:]))
	else:
		print(s[k - 1])


from math import ceil
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = sorted(input())
	min_s = s[0]
	n_min = 0
	for i in s:
		if i == min_s:
			n_min += 1
		else:
			break
	unique = len(set(s))
	if n_min < k:
		print(s[k - 1])
	elif unique == 1:
		print(''.join(s[0] * ceil(n / k)))
	elif unique == 2 and n_min == k:
		if n % k == 0:
			print(''.join(s[k - 1::k]))
		else:
			print(''.join(s[0] + s[k] * ceil((n - k) / k)))
	else:
		print(''.join(s[k - 1:]))


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = input()
	s = sorted(s)
	t = s[:k]
	ans = []
	p = s[k:]
	ans += max(t)
	if len(p) == 0:
		print(''.join(ans))
	elif len(set(p)) < 2 and len(set(t)) < 2:
		ans += p[:math.ceil(len(p) / k)]
		print(''.join(ans))
	else:
		if len(set(t)) == 1:
			ans += p
		print(''.join(ans))


cases = int(input())
for _ in range(cases):
	(a, b) = [int(s) for s in input().split()]
	s = input().strip()
	s_sort = sorted(s)
	dicc = {}
	for l in s:
		if l in dicc:
			dicc[l] += 1
		else:
			dicc[l] = 1
	set_s = set(s_sort)
	if b == 1:
		print(''.join(s_sort))
	elif len(set_s) == 1:
		if a % b == 0:
			print(a // b * s[0])
		else:
			print((1 + a // b) * s[0])
	elif s_sort[b - 1] != s_sort[0]:
		print(s_sort[b - 1])
	elif len(set(s_sort[b:])) == 1:
		count_new = len(s_sort[b:])
		if count_new % dicc[s_sort[0]] == 0:
			print(s_sort[0] + count_new // dicc[s_sort[0]] * s_sort[b])
		else:
			print(s_sort[0] + (1 + count_new // dicc[s_sort[0]]) * s_sort[b])
	else:
		print(s_sort[0] + ''.join(s_sort[b:]))


import math
from collections import Counter
for _ in range(int(input())):
	(_, k) = [int(x) for x in input().split()]
	s = sorted(input())
	if k == 1:
		print(''.join(s))
		continue
	symbols = sorted(Counter(s).items())
	ans = []
	if symbols[0][1] < k:
		print(s[k - 1])
	else:
		(sym, count) = symbols[0]
		ans = [sym]
		if count <= k:
			symbols = symbols[1:]
		else:
			symbols = [(sym, count - k)] + symbols[1:]
		if len(symbols) == 1:
			(sym, count) = symbols[0]
			ans += [sym] * math.ceil(count / k)
		else:
			for (sym, count) in symbols:
				ans += [sym] * count
		print(''.join(ans))


import math
t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	s = input()
	l = list(s)
	l.sort()
	s = ''.join(l)
	res = ''
	if s[k - 1] != s[0]:
		res = s[k - 1]
	else:
		res = s[0]
		if len(s) > k:
			if s[k] == s[len(s) - 1]:
				count = s[k:].count(s[k])
				res += math.ceil(count / k) * s[k]
			else:
				res += s[k:]
	print(res)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort()
	result = []
	result.append(s[k - 1])
	toAdd = s[k:]
	index = k - 1
	while index - 1 >= 0 and s[index - 1] == s[k - 1]:
		index -= 1
	if index > 0:
		index -= 1
	if s[index] != s[k - 1]:
		print(''.join(result))
	else:
		if len(set(toAdd)) == 1 and len(toAdd) > 0:
			(q, r) = divmod(len(toAdd), k)
			timesToAdd = q + bool(r)
			for _ in range(timesToAdd):
				result.append(toAdd[0])
		else:
			result.extend(toAdd)
		print(''.join(result))


import collections
import itertools
from functools import lru_cache
import sys
import math

def helper():
	pass

def solve():
	(n, k) = map(int, input().split(' '))
	s = input()
	slist = sorted(list(s))
	if k == 1:
		print(''.join(slist))
	elif len(set(slist)) == 1:
		print(slist[0] * math.ceil(n / k))
	elif k == n:
		print(slist[k - 1])
	elif slist[0] == slist[k - 1]:
		if len(set(slist[k:])) == 1:
			print(''.join(slist[0]) + slist[k] * math.ceil(len(slist[k:]) / k))
		else:
			print(''.join(slist[0]) + ''.join(slist[k:]))
	else:
		print(slist[k - 1])
t = int(input())
for _ in range(t):
	solve()


tt = int(input())
for ttt in range(tt):
	(n, k) = [int(x) for x in input().split(' ')]
	s = input()
	a = []
	for x in s:
		a.append(x)
	a.sort()
	p = set(a)
	if k == 1:
		for x in a:
			print(x, end='')
		print()
	elif len(p) == 1:
		if n % k == 0:
			for i in range(round(n / k)):
				print(a[0], end='')
			print()
		else:
			q = 1 + int(n / k)
			for i in range(q):
				print(a[0], end='')
			print()
	elif len(p) == 2:
		q = 0
		while a[q] == a[0]:
			q += 1
		if k > q:
			print(a[k - 1])
		elif k == q:
			print(a[0], end='')
			q1 = len(a) - q
			if q1 % k == 0:
				for i in range(round(q1 / k)):
					print(a[q], end='')
				print()
			else:
				for i in range(1 + int(q1 / k)):
					print(a[q], end='')
				print()
		else:
			for i in range(k - 1, len(a)):
				print(a[i], end='')
			print()
	else:
		q = 0
		while a[q] == a[0]:
			q += 1
		if k > q:
			print(a[k - 1])
		else:
			for i in range(k - 1, len(a)):
				print(a[i], end='')
			print()


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as c
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	(n, k) = sp()
	s = list(data())
	s.sort()
	if k == 1:
		out(''.join(s))
		continue
	if k == n:
		out(s[-1])
		continue
	cnt = c(s)
	temp = list(sorted(cnt.keys()))
	if cnt[s[0]] >= k:
		cnt[s[0]] -= k
		if cnt[s[0]] == 0:
			temp.remove(s[0])
		answer = [s[0]]
		if len(temp) == 1:
			for j in range(ceil(cnt[temp[0]] / k)):
				answer.append(temp[0])
		else:
			for i in temp:
				for j in range(cnt[i]):
					answer.append(i)
		out(''.join(answer))
		continue
	out(s[k - 1])


import sys
import math
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(x, y) = list(map(int, input().split()))
	s = input().rstrip()
	s = ''.join(sorted(s))
	if y == 1:
		print(s)
	elif s[0] != s[y - 1]:
		print(s[y - 1])
	elif s[0] == s[-1]:
		print(s[0] * math.ceil(x / y))
	elif s[y] == s[-1]:
		print(s[0] + s[y] * math.ceil((x - y) / y))
	else:
		print(s[0] + s[y:])


input = __import__('sys').stdin.readline
print = __import__('sys').stdout.write
from collections import Counter
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	inputted = ''.join(sorted(list(input().strip())))
	if inputted[0] == inputted[k - 1]:
		setset = set(list(inputted[k:]))
		if len(setset) == 1:
			tmptmp = len(inputted[k:])
			r = tmptmp // k + (1 if tmptmp % k else 0)
			print(f'{inputted[0] + inputted[k] * r}\n')
		else:
			print(f'{inputted[0] + inputted[k:]}\n')
	else:
		print(f'{inputted[k - 1]}\n')
	tmp = iter([i for i in range(k)] * (n // k + 1))


for t in range(int(input())):
	(n, k) = map(int, input().split())
	s = input()
	s = sorted(s)
	if s[k - 1] != s[0] or n == k:
		print(s[k - 1])
	else:
		ans = s[0]
		rem = s[k:]
		if rem.count(rem[0]) == len(rem):
			i = 0
			while i < len(rem):
				ans += rem[i]
				i += k
		else:
			for i in rem:
				ans += i
		print(ans)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest

def primeFactors(n):
	pf = []
	while n % 2 == 0:
		pf.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			pf.append(int(i))
			n = n / i
	if n > 2:
		pf.append(int(n))
	return pf

def main():
	mod = 1000000007
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = ri()
	for _ in range(tc):
		(n, k) = ria()
		s = rs()
		z = [''] * k
		ind = 0
		t = 0
		a = sorted(list(s))
		if a[0] != a[k - 1]:
			print(a[k - 1])
		else:
			g = a[k:]
			d = Counter(g)
			if len(d) == 1:
				t = 1
			if t:
				for i in range(n):
					ind += 1
					if ind > k:
						ind = 1
					z[ind - 1] += a[i]
				print(max(z))
			else:
				z = [a[0]] + a[k:]
				print(''.join(z))
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


from collections import defaultdict
for ii in range(int(input())):
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort()
	dic = defaultdict(int)
	for i in s:
		dic[i] += 1
	arr = ['' for i in range(k)]
	ind = 0
	while ind != k:
		arr[ind % k] += s[ind]
		ind += 1
	if arr[0] != arr[-1]:
		print(''.join(arr[-1]))
	elif len(set(s[k:])) == 1:
		print(arr[-1] + ''.join(s[k] * ((n - k) // k + 1 if (n - k) % k != 0 else (n - k) // k)))
	else:
		print(arr[-1] + ''.join(s[k:]))


def solve(arr, k):
	if arr[0] != arr[k - 1]:
		return arr[k - 1]
	aux = [arr[0]]
	if arr[k] != arr[n - 1]:
		aux.extend(arr[k:n])
	else:
		aux.extend(arr[k:k + (n - 1) // k])
	return aux
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(input().rstrip())
	arr.sort()
	arr.append(-1)
	ans = solve(arr, k)
	print(*ans, sep='')


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = sorted(input().strip())
	if s[0] != s[k - 1]:
		print(s[k - 1])
		continue
	even = True
	i = 0
	ans = ''
	for (i, c) in enumerate(s):
		if i % k == 0:
			ans += c
		elif c != ans[-1]:
			even = False
	a1 = ''.join([s[0]] + s[k:])
	if even:
		a1 = min(a1, ans)
	if len(set(s)) == 1:
		a1 = min(a1, ''.join(s[:math.ceil(n / k)]))
	print(a1)


import sys
import math
from collections import defaultdict

def solve(t):
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort()
	res1 = ['' for i in range(k)]
	i = 0
	for c in s:
		res1[i] += c
		i = (i + 1) % k
	res1.sort()
	res2 = ['' for i in range(k)]
	for c in range(k):
		res2[c] += s[c]
	res2[0] += ''.join(s[k:])
	res2.sort()
	ans = min(res1[-1], res2[-1])
	print(ans)
test_cases = int(input())
for t in range(1, test_cases + 1):
	solve(t)


def get_result(s, k):
	r = ''
	s = list(s)
	n = len(s)
	s = sorted(s)
	if n == k:
		return s[k - 1]
	r = r + s[k - 1]
	if s[0] == s[k - 1]:
		if s[k] == s[-1]:
			r = r + int((n - 1) / k) * s[k]
		else:
			r = r + ''.join(s[k:n])
	return r
nt = int(input())
for i in range(nt):
	(n, k) = map(int, input().split())
	s = input()
	print(get_result(s, k))


t = int(input())
for i in range(t):
	(n, k) = [int(j) for j in input().split()]
	s = list(input())
	s.sort()
	if k == 1:
		print(''.join(s))
	elif s[0] != s[k - 1]:
		print(s[k - 1])
	else:
		a = [s[0]] + s[k:]
		b = []
		c = []
		r = (n - 1) % k
		for j in range(n // k):
			b.append(s[r + j * k])
			c.append(s[k - 1 + j * k])
		if r != k - 1:
			b.append(s[r + n // k * k])
		print(min(''.join(a), max(''.join(b), ''.join(c))))


from collections import Counter
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = sorted(input())
	c = Counter(s)
	if len(c) == 1:
		print(''.join(s[0] * ((n - 1) // k + 1)))
	elif len(c) == 2 and c[s[0]] == k:
		print(''.join(s[0] + s[-1] * ((n - k - 1) // k + 1)))
	elif s[k - 1] == s[0]:
		print(''.join(s[k - 1:]))
	else:
		print(s[k - 1])


import sys
from collections import defaultdict
from copy import copy
R = lambda t=int: t(input())
RL = lambda t=int: [t(x) for x in input().split()]
RLL = lambda n, t=int: [RL(t) for _ in range(n)]

def solve():
	(n, k) = RL()
	s = sorted(R(str))
	if n == k:
		print(s[-1])
		return
	if s[0] < s[k - 1]:
		print(s[k - 1])
		return
	if s[-1] == s[k]:
		print(s[0] + ''.join(s[k:][:(n - 1) // k]))
		return
	print(s[0] + ''.join(s[k:]))
T = R()
for _ in range(T):
	solve()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = sorted([c for c in input()])
	if s[k - 1] != s[0]:
		print(s[k - 1])
	else:
		fi = s[0]
		se = None
		three = False
		for i in range(n):
			if s[i] != fi:
				if se == None:
					se = s[i]
				elif s[i] != se:
					three = True
					break
		if three:
			print(''.join(s[k - 1:]))
		else:
			i = 0
			while i < n and s[0] == s[i]:
				i += 1
			if i == n:
				string = [s[0]] * (n // k)
				if n % k != 0:
					string += [s[0]]
				print(''.join(string))
			elif i == k:
				if (n - i) % k == 0:
					print(s[0] + s[i] * ((n - i) // k))
				else:
					print(s[0] + s[i] * ((n - i) // k + 1))
			else:
				print(''.join(s[k - 1:]))


def solve():
	occ = [0] * 26
	for ch in s:
		occ[ord(ch) - 97] += 1
	ans = [''] * k
	last = 0
	for i in range(len(occ)):
		if occ[i] != 0:
			last = i
	count = 0
	for i in range(len(occ)):
		if count < k:
			for j in range(occ[i]):
				ans[count] += chr(i + 97)
				count += 1
				occ[i] -= 1
				if count == k:
					break
			if occ[i] == 0:
				continue
		if i != last:
			ans[0] += chr(i + 97) * occ[i]
			occ[i] = 0
		else:
			if ans[0] == ans[k - 1]:
				for ii in range(k):
					ans[ii] += occ[i] // k * chr(i + 97)
					if occ[i] % k > ii:
						ans[ii] += 1 * chr(i + 97)
			else:
				ans[0] += chr(i + 97) * occ[i]
				occ[i] = 0
			return ans
	return ans
t = int(input())
for i in range(1, t + 1):
	(n, k) = [int(s) for s in input().split(' ')]
	s = input()
	ans = solve()
	if ans[0][0] != ans[-1][0]:
		print(ans[-1])
	else:
		print(ans[0])


from collections import Counter as c
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	st = input()
	s = c(st)
	t = sorted(s.keys())
	ans = ''
	if s[t[0]] < b:
		print(sorted(st)[b - 1])
	elif b == 1:
		print(''.join(sorted(st)))
	elif s[t[0]] == a:
		from math import ceil
		print(t[0] * ceil(a / b))
	else:
		s[t[0]] -= b
		ans += t[0]
		if s[t[0]]:
			for i in t:
				ans += i * s[i]
		elif len(t) == 2:
			from math import ceil
			ans += t[1] * ceil(s[t[1]] / b)
		else:
			for i in t:
				ans += i * s[i]
		print(ans)


from random import randint as rn

def brute(s):
	result = 'zzzzzzzz'
	for i in range(1, 255):
		temp1 = []
		temp2 = []
		for bit in range(8):
			if 1 << bit & i:
				temp1.append(s[bit])
			else:
				temp2.append(s[bit])
		temp1.sort()
		temp2.sort()
		temp1 = ''.join(temp1)
		temp2 = ''.join(temp2)
		if temp1 > temp2:
			result = min(result, temp1)
		else:
			result = min(result, temp2)
	return result
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	chars = []
	chars = list(input())
	chars.sort()
	if k == 1:
		print(''.join(chars))
	else:
		counts = [0] * 26
		for c in chars:
			counts[ord(c) - 97] += 1
		left = 26 - counts.count(0)
		result = []
		for i in range(26):
			if counts[i] == 0:
				continue
			left -= 1
			if left == 0:
				x = 0
				if counts[i] % k != 0:
					x += 1
				result.append(chr(i + 97) * (counts[i] // k + x))
				break
			else:
				if counts[i] == k and left == 1:
					result.append(chr(i + 97))
					continue
				if counts[i] >= k:
					result.append(chr(i + 97) * (counts[i] + 1 - k))
					for j in range(i + 1, 26):
						result.append(chr(j + 97) * counts[j])
					break
				else:
					temp = k
					for j in range(i, 26):
						temp -= counts[j]
						if temp <= 0:
							result.append(chr(j + 97))
							break
					break
		print(''.join(result))


for t in range(int(input())):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	s = input()
	s = sorted(list(s))
	a = ''.join(s)
	ans = a[k - 1]
	if ans == a[0]:
		if n != k and len(list(set(list(a[k:])))) == 1:
			ans += a[k] * ((n - k - 1) // k + 1)
		elif n != k:
			ans += a[k:]
	print(ans)


def read_int():
	return int(input())

def read_ints():
	return map(int, input().split(' '))

def solve():
	(n, k) = read_ints()
	text = input()
	chars = sorted(text)
	buckets = [''] * k
	bucket_id = 0
	res = ''
	for i in range(k):
		buckets[bucket_id] += chars[i]
		if buckets[bucket_id] > res:
			res = buckets[bucket_id]
		bucket_id = (bucket_id + 1) % k
	first_letter = chars[0]
	first_buckets_cnt = 0
	for i in range(k):
		if buckets[i][0] == first_letter:
			first_buckets_cnt += 1
	if n == k:
		print(res)
		return
	same_remaining = True
	after = chars[k]
	for i in range(k + 1, n):
		if chars[i] != after:
			same_remaining = False
			break
	if same_remaining:
		for i in range(k, n):
			buckets[bucket_id] += chars[i]
			if buckets[bucket_id] > res:
				res = buckets[bucket_id]
			bucket_id = (bucket_id + 1) % first_buckets_cnt
	else:
		for i in range(k, n):
			buckets[0] += chars[i]
			if buckets[bucket_id] > res:
				res = buckets[bucket_id]
	print(res)
t = read_int()
for case_num in range(t):
	solve()


from sys import stdin
from collections import Counter
T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	ls = list(input())
	ls.sort()
	res = []
	if len(Counter(ls[0:k])) > 1:
		res = [max(ls[0:k])]
	elif len(Counter(ls[k:n])) == 1:
		res = [ls[0]] + [ls[k]] * ((n + k - 1) // k - 1)
	else:
		res = [ls[0]] + ls[k:]
	print(''.join(res))


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = []
	s = input()
	for i in s:
		arr.append(i)
	arr.sort()
	if arr[k - 1] > arr[0] or k == n:
		print(arr[k - 1])
		continue
	elif arr[0] == arr[k - 1]:
		ans = arr[k - 1]
		if arr[k] == arr[n - 1]:
			for i in range(math.ceil((n - k) / k)):
				ans += arr[k]
		else:
			for i in range(k, n):
				ans += arr[i]
		print(ans)


TT = int(input())
while TT > 0:
	TT -= 1
	(n, k) = map(int, input().split())
	s = input()
	r = {}
	for c in s:
		if c in r:
			r[c] += 1
		else:
			r[c] = 1
	m = sorted(list(r.keys()))
	res = ''
	if k == 1:
		for b in m:
			res += b * r[b]
	elif r[m[0]] < k:
		x = k
		i = 0
		while x > 0:
			x -= r[m[i]]
			if x > 0:
				i += 1
		res = m[i]
	elif len(m) == 1:
		res = m[0] * ((n + k - 1) // k)
	elif r[m[0]] == k:
		res = m[0]
		if len(m) == 2:
			res += m[1] * ((r[m[1]] + k - 1) // k)
		else:
			for j in range(1, len(m)):
				res += m[j] * r[m[j]]
	else:
		res = m[0] * (r[m[0]] - k + 1)
		for j in range(1, len(m)):
			res += m[j] * r[m[j]]
	print(res)


import math
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	s = input()
	s1 = [i for i in s]
	s1.sort()
	s = ''.join(s1)
	if m == n:
		print(s[n - 1])
		continue
	if m == 1:
		print(s)
		continue
	lis = [[s[i]] for i in range(m)]
	pos = -1
	for i in range(m - 1):
		if lis[i] == lis[m - 1]:
			pos = i
			break
	if pos == -1:
		print(*lis[m - 1])
		continue
	pp = pow(2, 10)
	for i in range(20):
		pp += i
	if pos == 0:
		if s[m] == s[n - 1]:
			print(s[0] + s[m] * math.ceil((n - m) / m))
		else:
			print(s[0] + s[m:])
	else:
		print(*lis[m - 1])


from sys import stdin, gettrace
if not gettrace():

	def input():
		return next(stdin)[:-1]

def main():

	def solve():
		(n, k) = map(int, input().split())
		ss = list(input())
		ss.sort()
		if k == 1:
			print(''.join(ss))
			return
		if ss[0] == ss[-1]:
			print(''.join(ss[0] * ((n - 1) // k + 1)))
			return
		if ss[k - 1] != ss[0] or k == n:
			print(ss[k - 1])
			return
		if ss[k] == ss[-1]:
			print(''.join(ss[k - 1] + ss[k] * ((n - 1) // k)))
			return
		print(''.join(ss[k - 1:]))
	q = int(input())
	for _ in range(q):
		solve()
main()


t = int(input())
from math import ceil
for _ in range(t):
	(n, k) = map(int, input().split())
	s = input()
	ls = sorted(s)
	li = set(ls[:k])
	if len(li) >= 2:
		print(ls[k - 1])
	else:
		se = set(ls[k:])
		if len(se) == 0:
			print(ls[k - 1])
		elif len(se) > 1:
			print(ls[0] + ''.join(ls[k:]))
		else:
			l = n - k
			print(ls[0] + ls[k] * ceil(l / k))


def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))

def solve():
	(n, k) = rl()
	s = input().strip()
	occ = {chr(i): 0 for i in range(ord('a'), ord('z') + 1)}
	chars = []
	charset = set()
	for c in s:
		occ[c] += 1
		if c not in charset:
			charset.add(c)
			chars.append(c)
	worst = ''
	chars.sort()
	lowest = chars[0]
	if occ[lowest] < k:
		for c in range(ord(lowest), ord('z') + 1):
			k -= occ[chr(c)]
			if k <= 0:
				print(chr(c))
				return
	elif len(chars) == 1:
		reps = (n + k - 1) // k
		print(chars[0] * reps)
		return
	elif len(chars) == 2 and occ[lowest] == k:
		ret = chars[0] * (occ[lowest] // k)
		reps = (occ[chars[1]] + k - 1) // k
		print(ret + chars[1] * reps)
		return
	else:
		ret = chars[0] * (occ[lowest] - k + 1)
		for c in chars[1:]:
			ret += c * occ[c]
		print(ret)
		return
t = ri()
for i in range(t):
	solve()


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	n1 = input()
	d = [i for i in n1]
	d.sort()
	qn = 5
	qpt = -1
	p = [[] for i in range(k)]
	flag = 0
	for i in range(n // k):
		q = i * k
		l = d[q + 0]
		for j in range(k):
			p[j].append(d[q + j])
			if d[q + j] != l:
				qn = i
				qpt = j
				flag = 1
				break
		if flag == 1:
			break
	if flag == 0:
		pt = n - n % k
		if n % k != 0:
			ll = d[pt]
		for i in range(n % k):
			p[i].append(d[pt + i])
			if ll != d[pt + i]:
				qpt = i
				l = d[pt + i]
				flag = 1
				break
	if k == 1:
		print(''.join(d))
	elif d.count(d[0]) == n:
		z = math.ceil(n / k)
		print(d[0] * z)
	elif flag == 0:
		if n % k == 0:
			t1 = ''.join(p[-1])
		else:
			t1 = ''.join(p[n % k - 1])
		print(min(''.join(d[k - 1:]), t1))
	elif qn == 0:
		print(d[k - 1])
	else:
		print(''.join(d[k - 1:]))


T = int(input())
for case in range(T):
	(n, k) = [int(x) for x in input().split()]
	s = input()
	ls = sorted(list(s))
	ret = ''
	alset = set(ls[:k])
	if len(alset) == 1:
		ret += ls[0]
		if len(set(ls[k:])) == 1:
			ret += str(ls[k]) * ((len(ls[k:]) - 1) // k + 1)
		else:
			ret += ''.join(ls[k:])
	else:
		ret += ls[k - 1]
	print(ret)


from collections import Counter
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter
import math
for _ in range(int(input())):
	(a, k) = map(int, input().split())
	s = input()
	s = list(s)
	s.sort()
	if len(set(s[:k])) >= 2:
		print(s[k - 1])
	elif k < a and len(set(s[k:])) > 1:
		print(''.join(s[k - 1:]))
	else:
		var = ''
		var += s[k - 1]
		if k <= a - 1:
			var += s[k] * ((a - k) // k)
			if (a - k) % k >= 1:
				var += s[k]
		print(var)


import math
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	s = list(input())
	counter = {}
	for i in s:
		if i not in counter.keys():
			counter[i] = 1
		else:
			counter[i] += 1
	s = list(set(s))
	s.sort()
	cnt = 0
	summ = 0
	while summ < k:
		summ += counter[s[cnt]]
		cnt += 1
	if cnt != 1:
		print(s[cnt - 1])
	elif len(s) == 1:
		print(math.ceil(n / k) * s[0])
	elif counter[s[0]] == k and len(s) == 2:
		print(s[0] + math.ceil(counter[s[1]] / k) * s[1])
	else:
		print(s[0], end='')
		for j in range(len(s)):
			if j != 0:
				print(counter[s[j]] * s[j], end='')
			elif counter[s[0]] > k:
				print((counter[s[0]] - k) * s[0], end='')
		print()


from collections import defaultdict
import heapq
t = int(input())
for _ in range(t):
	(n, K) = list(map(int, input().strip().split()))
	s = input().strip()
	letters = defaultdict(int)
	for char in s:
		letters[ord(char)] += 1
	curr_strings = []
	k = K
	for key in sorted(letters.keys()):
		while letters[key] > 0 and k > 0:
			curr_strings.append(chr(key))
			letters[key] -= 1
			k -= 1
		if letters[key] == 0:
			letters.pop(key)
	if curr_strings[0] < curr_strings[-1]:
		print(curr_strings[-1])
		continue
	if len(letters) == 0:
		print(curr_strings[-1])
		continue
	if len(letters) == 1:
		key = list(letters.keys())[0]
		cnt = letters[key]
		if cnt % K == 0:
			print(curr_strings[-1] + chr(key) * (cnt // K))
		else:
			print(curr_strings[-1] + chr(key) * (cnt // K + 1))
		continue
	output = curr_strings[-1]
	for key in sorted(letters.keys()):
		output += chr(key) * letters[key]
	print(output)


import sys
import math
import collections
import heapq
t = int(input())
for w in range(t):
	(n, k) = (int(i) for i in input().split())
	s = sorted(list(input()))
	c = 0
	ans = []
	k1 = s.count(s[0])
	s2 = list(set(s))
	s2.sort()
	if k == 1:
		print(''.join(s))
	elif len(s2) == 1:
		print(s[0] * math.ceil(n / k))
	elif len(s2) == 2:
		if k > k1:
			print(s[k - 1])
		elif k == k1:
			for i in range(n):
				if i % k == 0:
					ans.append(s[i])
			print(''.join(ans))
		else:
			ans.append(s[0])
			for i in range(k, n):
				ans.append(s[i])
			print(''.join(ans))
	elif k > k1:
		print(s[k - 1])
	else:
		ans.append(s[0])
		for i in range(k, n):
			ans.append(s[i])
		print(''.join(ans))


import math

def main():
	for q in range(int(input())):
		(N, K) = map(int, input().split())
		st = input()
		dp = [0] * 26
		for i in range(len(st)):
			dp[ord(st[i]) - ord('a')] += 1
		emp = -1
		for i in range(26):
			if dp[i] != 0:
				emp = i
				break
		if dp[emp] < K:
			ans = ''
			for i in range(26):
				K -= dp[i]
				if K <= 0:
					ans = chr(i + 97)
					break
			print(ans)
		else:
			ans = ''
			noe = 0
			for i in range(26):
				if dp[i] != 0:
					noe += 1
			if noe == 1:
				for i in range(dp[emp] // K):
					ans += chr(emp + 97)
				if dp[emp] % K != 0:
					ans += chr(emp + 97)
			elif noe == 2:
				for i in range(dp[emp] - K + 1):
					ans += chr(97 + emp)
				nex = -1
				for i in range(emp + 1, 26):
					if dp[i] != 0:
						nex = i
				if K < dp[emp]:
					for j in range(dp[nex]):
						ans += chr(97 + nex)
				else:
					for i in range(dp[nex] // K):
						ans += chr(97 + nex)
					if dp[nex] % K != 0:
						ans += chr(97 + nex)
			else:
				for i in range(dp[emp] - K + 1):
					ans += chr(97 + emp)
				for i in range(emp + 1, 26):
					for j in range(dp[i]):
						ans += chr(97 + i)
			print(ans)
main()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = input()
	letters = sorted(set(a))
	counts = [a.count(x) for x in letters]
	if len(letters) == 1:
		length = n // k
		if n % k != 0:
			length += 1
		print(letters[0] * length)
		continue
	if len(letters) > 2:
		count = 0
		max_letter = letters[0]
		for (i, c) in enumerate(counts):
			count += c
			if count >= k:
				max_letter = letters[i]
				break
		if max_letter != letters[0]:
			print(max_letter)
			continue
		print(letters[0] * (counts[0] - k + 1), end='')
		for i in range(1, len(counts)):
			print(letters[i] * counts[i], end='')
		print()
	if len(letters) == 2:
		count = 0
		max_letter = letters[0]
		for (i, c) in enumerate(counts):
			count += c
			if count >= k:
				max_letter = letters[i]
				break
		if max_letter != letters[0]:
			print(max_letter)
			continue
		if counts[0] == k:
			print(letters[0], end='')
			length = counts[1] // k
			if counts[1] % k != 0:
				length += 1
			print(letters[1] * length)
			continue
		print(letters[0] * (counts[0] - k + 1), end='')
		print(letters[1] * counts[1])


def next():
	return [int(x) for x in input().split()]

def f(s, k):
	if s[0] != s[k - 1] or len(s) == k:
		return s[k - 1]
	elif len(s) == k + 1 or s[k] != s[-1]:
		return ''.join(s[k - 1:])
	else:
		return s[0] + ''.join((len(s) - 1) // k * [s[k]])
(cas,) = next()
for _ in range(cas):
	(n, k) = next()
	s = sorted(input().strip())
	if k == 1:
		print(''.join(s))
	else:
		print(f(s, k))


def main():
	(n, k) = map(int, input().split())
	line = input()
	line = sorted(line)
	line1 = ''
	for i in line:
		line1 += i
	line = line1
	fst = line[0]
	for i in range(0, k):
		if fst != line[i]:
			print(line[k - 1])
			return
	same = True
	if len(line) == k:
		print(line[-1])
		return
	to_same = line1[k]
	for i in range(k, len(line)):
		if to_same != line[i]:
			same = False
			break
	if same:
		if n % k == 0:
			print(fst + (n // k - 1) * line[k])
		else:
			print(fst + n // k * line[k])
	else:
		print(fst + line[k:])
t = int(input())
for i in range(t):
	main()


t = int(input())
from collections import Counter
for _ in range(t):
	(n, k) = map(int, input().split())
	string = input()
	string = sorted([x for x in string])
	freq = dict(Counter(string))
	keys = sorted(list(freq.keys()))
	mn = 0
	if k == 1:
		print(''.join(string))
	elif len(keys) == 1:
		print(keys[mn] * (n // k) + (keys[mn] if n % k else ''))
	elif freq[keys[mn]] < k:
		print(''.join(string[k - 1]))
	elif freq[keys[mn]] > k:
		print(''.join(string[k - 1:]))
	elif len(keys) == 2:
		ans = keys[mn]
		n = freq[keys[mn + 1]]
		ans += keys[mn + 1] * (n // k) + (keys[mn + 1] if n % k else '')
		print(ans)
	else:
		print(''.join(string[k - 1:]))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort()
	ans = []
	if k == n:
		print(s[k - 1])
	elif s[0] == s[k - 1] and s[k] == s[n - 1]:
		ans_s = s[0] + s[k] * ((n - k) // k)
		if n % k == 0:
			print(ans_s)
		else:
			print(ans_s + s[k])
	elif s[0] == s[k - 1]:
		print(s[0] + ''.join(list(map(str, s[k:]))))
	else:
		print(s[k - 1])


from math import *
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(input())
	l.sort()
	l = ''.join(l)
	if l[0] != l[k - 1]:
		print(l[k - 1])
	elif k < n and l[k] == l[n - 1]:
		print(l[0] + l[k] * int(ceil((n - k) / k)))
	elif l[0] == l[k - 1]:
		print(l[0] + l[k:])


te = int(input())
while te > 0:
	(n, k) = map(int, input().split())
	s = input()
	s = sorted(s)
	ans = ''
	if s[0] != s[k - 1]:
		print(s[k - 1])
	else:
		ans += s[0]
		flag = 0
		for i in range(k, n - 1):
			if s[i] == s[i + 1]:
				pass
			else:
				flag = 1
				break
		if flag == 1:
			for i in range(k, n):
				ans += s[i]
		else:
			l = (n - k) // k
			if (n - k) % k != 0:
				l += 1
			for i in range(l):
				ans += s[k]
		print(ans)
	te -= 1


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort()
	if k == 1:
		print(''.join(s))
	elif k == n:
		print(s[-1])
	else:
		ans = ''
		if s[0] == s[k - 1]:
			ans += s[0]
			f = s[k]
			if s[-1] == s[k]:
				ans += s[k] * ((n - k) // k)
				if n % k == 0:
					pass
				else:
					ans += s[k]
			else:
				ans += ''.join(s[k:])
		else:
			ans = s[k - 1]
		print(ans)


for ii in range(int(input())):
	a = [int(i) for i in input().split()]
	b = input()
	n = a[0]
	k = a[1]
	c = sorted(b)
	s = ['' for i in range(k)]
	p = c[0]
	for i in range(k):
		s[i] = c[i]
	if s[-1] != p:
		print(s[-1])
	else:
		x = c[k:]
		if x == []:
			print(c[0])
		elif len(set(x)) == 1:
			q = len(x) // k
			if len(x) % k != 0:
				q += 1
			ans = c[0]
			for i in range(q):
				ans = ans + x[0]
			print(ans)
		else:
			print(c[0] + ''.join(x))


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	word = input()
	arr = list(map(str, word))
	arr.sort()
	brr = ['' for i in range(m)]
	temp = ['' for i in range(m)]
	for i in range(m):
		brr[i % m] += arr[i]
		temp[i % m] += arr[i]
	for i in range(m, n):
		brr[0] += arr[i]
		temp[i % m] += arr[i]
	a = brr[0]
	b = temp[0]
	for i in range(1, m):
		a = max(brr[i], a)
		b = max(temp[i], b)
	print(min(a, b))


import sys
from collections import Counter
input = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(input())

def read_int_n():
	return list(map(int, input().split()))

def read_str():
	return input().strip()

def slv(N, K, S):
	S = [c for c in S]
	S.sort(reverse=True)
	ans = [list() for _ in range(K)]
	for a in ans:
		a.append(S.pop())
	if ans[0][0] != ans[-1][0]:
		return ''.join(ans[-1])
	elif not S:
		return ''.join(ans[-1])
	elif S[0] != S[-1]:
		return ''.join(ans[-1] + list(reversed(S)))
	else:
		n = -(-len(S) // K)
		return ''.join(ans[-1] + [S[0] * n])

def main():
	T = read_int()
	for _ in range(T):
		(N, K) = read_int_n()
		S = read_str()
		print(slv(N, K, S))
main()


import sys
import heapq
import math
import bisect

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def rinput():
	return map(int, input().split())

def rlinput():
	return list(map(int, input().split()))

def srlinput():
	return sorted(list(map(int, input().split())))

def main():
	(n, k) = rinput()
	s = input()
	q = sorted(list(s))
	w = dict()
	t = sorted(list(set(q)))
	if k == 1:
		print(''.join(q))
		return 0
	for i in q:
		if i in w:
			w[i] += 1
		else:
			w[i] = 1
	if q[0] != q[k - 1]:
		print(q[k - 1])
		return 0
	elif len(w) > 2:
		print(q[0] + ''.join(q[k:]))
	elif len(w) == 1:
		print(q[0] * ((n + k - 1) // k))
	else:
		w[q[0]] -= k
		if w[q[0]] > 0:
			print(q[0] + ''.join(q[k:]))
		else:
			print(q[0] + t[1] * ((w[t[1]] + k - 1) // k))
for sdfghjkl in range(iinput()):
	main()


from collections import Counter
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = sorted(input())
	t = list(Counter(s).items())
	if len(t) == 1:
		print(s[0] * -(-n // k))
		continue
	now = s[0]
	ans = s[k - 1]
	if now != ans:
		print(''.join(ans))
	elif len(t) >= 3:
		print(''.join(s[k - 1:]))
	elif t[0][1] == k:
		print(t[0][0] + t[1][0] * (-(-n // k) - 1))
	else:
		print(''.join(s[k - 1:]))


T = int(input())
for _ in range(T):
	(N, K) = map(int, input().split())
	chars = list(input())
	chars.sort()
	dist = [[] for _ in range(K)]
	if chars[0] != chars[K - 1] or K == N:
		print(chars[K - 1])
		continue
	if chars[K] != chars[-1]:
		print(''.join([chars[0]] + chars[K:]))
		continue
	print(chars[0] + chars[K] * ((N - 1) // K))


from math import ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = sorted(list(input()))
	ans = ''
	ind = s.index(s[-1])
	if s[0] != s[k - 1]:
		ans = s[k - 1]
	elif s[-1] == s[0]:
		ans = ceil(n / k) * s[0]
	elif k == n:
		ans = s[-1]
	elif len(set(s)) == 2 and s[k] != s[0]:
		ans += s[0]
		ans += ceil((n - ind) / k) * s[ind]
	else:
		for i in range(k - 1, n):
			ans += s[i]
	print(ans)


from collections import defaultdict
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split(' '))
	s = input()
	s1 = s
	s = sorted(s)
	m = list(set(s))
	x = max(s[:k])
	y = min(s[:k])
	if x == y:
		if len(list(set(s[k:]))) == 1:
			ans1 = ''
			for i in range(0, n, k):
				ans1 = ans1 + s[i]
			ans = ''
			for i in range(k - 1, n, k):
				ans = ans + s[i]
			print(max(ans, ans1))
		else:
			for i in range(k, n):
				y = y + s[i]
			print(y)
	else:
		print(x)


from collections import defaultdict
con = 10 ** 9 + 7

def getlist():
	return list(map(int, input().split()))

def main():
	T = int(input())
	for i in range(T):
		(N, K) = getlist()
		s = sorted(list(input()))
		if N == K:
			print(s[-1])
		elif s[0] != s[K - 1]:
			print(s[K - 1])
		elif s[0] == s[-1]:
			var = 0
			if N % K == 0:
				var = int(N // K)
			else:
				var = int(N // K) + 1
			ans = s[0] * var
			print(ans)
		elif s[K] == s[-1]:
			ans = s[0]
			var = 0
			if (N - K) % K == 0:
				var = int(N // K) - 1
			else:
				var = int(N // K)
			ans += var * s[-1]
			print(ans)
		else:
			ans = s[0]
			for j in range(K, N):
				ans += s[j]
			print(ans)
main()


def solve():
	(x, y) = map(int, input().split())
	s = sorted(input())
	if y == 1:
		print(*s, sep='')
		return
	if x == y:
		print(s[-1])
		return
	if s[0] != s[y - 1]:
		print(s[y - 1])
		return
	res = s[0]
	if s[y] != s[x - 1]:
		for n in range(y, x):
			res += s[n]
		print(res)
		return
	else:
		for n in range(0, (x - 1) // y):
			res += s[x - 1]
		print(res)
for _ in range(int(input())):
	solve()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = input()
	ss = sorted(s)
	if k == 1:
		print(''.join(sorted(s)))
		continue
	lst = [0] * 26
	pref = [0] * 26
	for c in s:
		lst[ord(c) - ord('a')] += 1
	for i in range(0, len(lst)):
		pref[i] = lst[i] + (pref[i - 1] if i > 0 else 0)
	st = 0
	while lst[st] == 0:
		st += 1
	ssum = lst[st]
	en = st
	while ssum < k:
		en += 1
		ssum += lst[en]
	res1 = ''.join([chr(en + ord('a'))] + ss[:pref[en] - k] + ss[pref[en]:])
	res = ''
	if True:
		c = 0
		while c < len(lst) and lst[c] % k == 0:
			res += ''.join([chr(c + ord('a'))] * (lst[c] // k))
			c += 1
		if c != len(lst):
			res += ''.join([chr(c + ord('a'))] * (lst[c] // k))
			lst[c] %= k
			c_last = True
			for i in range(c + 1, len(lst)):
				if lst[i] > 0:
					c_last = False
			if c_last:
				res += chr(c + ord('a'))
			else:
				ok = False
				ssum = 0
				for i in range(c, len(lst)):
					ssum += lst[i]
					if ssum >= k:
						res += chr(i + ord('a'))
						ok = True
						break
				if not ok:
					res = ''.join([chr(ord('z') + 1)])
	print(min([res1, res]))


import sys
from math import ceil
from itertools import islice, cycle
from collections import Counter
stdin = sys.stdin
t = int(stdin.readline())
for line in stdin:
	if not line:
		break
	(n, k) = line.split()
	(n, k) = (int(n), int(k))
	s = stdin.readline().strip()
	s = list(s)
	s_set = set(s)
	s_u = sorted(s_set)
	s = sorted(s)
	cnt = Counter(s)
	if k == 1:
		print(''.join(s))
		continue
	if s[k - 1] != s[0]:
		print(s[k - 1])
		continue
	if len(s_set) == 1:
		result = ceil(len(s) / k)
		result = s[0] * result
		result = ''.join(result)
		print(result)
		continue
	if len(s_set) == 2:
		u1 = cnt[s[0]]
		if u1 > k:
			pass
		else:
			snd_l = s_u[1]
			result = ceil(cnt[snd_l] / k)
			result = s[0] + snd_l * result
			result = ''.join(result)
			print(result)
			continue
	my_str = ''.join(s[k - 1:])
	print(my_str)


T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort()
	if s[0] != s[k - 1]:
		print(s[k - 1])
		continue
	else:
		string = s[0]
		S = s[k:]
		if S and S[0] == S[-1]:
			L = len(S)
			(u, v) = divmod(L, k)
			if v != 0:
				base = S[0] * (u + 1)
			else:
				base = S[0] * u
			print(string + base)
		else:
			print(string + ''.join(S))


import math
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().strip().split()))
	st = input()
	sst = sorted(st)
	if len(sst) == 1 or n == k:
		print(sst[-1])
		continue
	if sst[0] == sst[k - 1]:
		if sst[k] == sst[-1]:
			extra = (n - k) / k
			print(sst[k - 1], end='')
			print(sst[k] * math.ceil(extra))
		else:
			for i in range(k - 1, n):
				print(sst[i], end='')
			print()
	else:
		print(sst[k - 1])


from math import *
mod = 10 ** 9 + 7

def _in():
	return [int(x) for x in input().split(' ')]

def check(s, c):
	for i in s:
		if i != c:
			return False
	return True

def main():
	(n, k) = _in()
	s = sorted(input())
	if n == k:
		return s[n - 1]
	elif s[0] != s[k - 1]:
		print(s[k - 1], end='')
	else:
		print(s[0], end='')
		if s[k] == s[n - 1]:
			for i in range((n - 1) // k):
				print(s[n - 1], end='')
		else:
			for i in range(k, n):
				print(s[i], end='')
	return ''
for _ in range(int(input())):
	print(main())


import math
t = int(input())
for test in range(t):
	(n, k) = list(map(int, input().split()))
	s = input()
	alpha_list = []
	for i in range(len(s)):
		alpha_list.append(s[i])
	alpha_list.sort()
	alpha_dict = {}
	for i in range(len(alpha_list)):
		if alpha_list[i] in alpha_dict:
			alpha_dict[alpha_list[i]] += 1
		else:
			alpha_dict[alpha_list[i]] = 1
	ans = ''
	if k == 1:
		for i in range(len(alpha_list)):
			ans = ans + alpha_list[i]
		print(ans)
		continue
	elif len(alpha_dict.keys()) == 1:
		key_list = list(alpha_dict.keys())
		x = math.ceil(alpha_dict[key_list[0]] / k)
		for i in range(x):
			ans = ans + key_list[0]
		print(ans)
		continue
	else:
		key_list = list(alpha_dict.keys())
		key_list.sort()
		if alpha_dict[key_list[0]] < k:
			ans = ''
			cum = 0
			for i in range(len(key_list)):
				cum += alpha_dict[key_list[i]]
				if cum >= k:
					ans = key_list[i]
					break
			print(ans)
			continue
		else:
			if alpha_dict[key_list[0]] == k and len(key_list) == 2:
				ans = key_list[0] + key_list[1] * math.ceil(alpha_dict[key_list[1]] / k)
			else:
				alpha_dict[key_list[0]] -= k
				ans = key_list[0]
				for i in range(len(key_list)):
					ans += key_list[i] * alpha_dict[key_list[i]]
			print(ans)
			continue


from collections import Counter
T = int(input().strip())
for t in range(T):
	(n, k) = list(map(int, input().split()))
	rem = sorted(input().strip()[:n])
	minc = min(rem[:k])
	maxc = max(rem[:k])
	if minc < maxc:
		print(maxc)
		continue
	start = maxc
	rem = rem[k:]
	if rem:
		minc = min(rem)
		maxc = max(rem)
		if minc < maxc:
			start += ''.join(rem)
			print(''.join(start))
			continue
		p = len(rem)
		start += maxc * (p // k)
		if p % k:
			start += maxc
	print(''.join(start))


t = int(input())
for i in range(t):
	(n, k) = [int(x) for x in input().split()]
	s = input()
	sn = ''.join(sorted(s))
	ans = [sn[i] for i in range(k)]
	if len(set(ans)) > 1:
		print(ans[-1])
	elif len(set(sn[k:])) > 1:
		print(ans[0] + sn[k:])
	else:
		rem = n - k
		if rem <= k:
			rem = min(rem, 1)
		num = rem // k + [0, 1][rem % k > 0]
		print(ans[0] + sn[-1] * num)


import math
T = int(input())
for _ in range(T):
	(n, k) = list(map(int, input().split()))
	s = input()
	s = sorted(s)
	cnt = {}
	for c in s:
		if c not in cnt:
			cnt[c] = 0
		cnt[c] += 1
	if k == 1:
		ans = list(s)
	else:
		ans = [s[k - 1]]
		if k < n:
			n_first = 0
			for i in range(k):
				if s[i] == s[k - 1]:
					n_first += 1
			if s[k - 1] == s[0]:
				if s[k] == s[-1]:
					used = 0 if s[k] != s[k - 1] else n_first
					ans = ans + [s[k]] * math.ceil((cnt[s[-1]] - used) * 1.0 / n_first)
				else:
					ans = ans + s[k:]
	print(''.join(ans))


import math

def preproc(s):
	x = list(s)
	x.sort()
	ch = x[0]
	dic = []
	dic.append([ch, 1])
	ind = 0
	for i in range(1, len(x)):
		c = x[i]
		if x[i] == x[i - 1]:
			dic[ind][1] += 1
		else:
			dic.append([c, 1])
			ind += 1
	return (dic, ind + 1)
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	s = input()
	(letters, l) = preproc(s)
	out = ''
	f = letters[0][1]
	if l == 1:
		f = letters[0][1]
		for i in range(math.ceil(f / k)):
			out += letters[0][0]
	elif l == 2 and letters[0][1] == k:
		out = letters[0][0]
		f = letters[1][1]
		for i in range(math.ceil(f / k)):
			out += letters[1][0]
	elif f < k:
		ind = 0
		while k > 0:
			f = letters[ind][1]
			k -= f
			ind += 1
		out = letters[ind - 1][0]
	else:
		num = f - k + 1
		c = letters[0][0]
		for i in range(num):
			out += c
		for i in range(1, l):
			c = letters[i][0]
			f = letters[i][1]
			for j in range(f):
				out += c
	print(out)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	given = sorted(input())
	if len(set(given[:k])) != 1:
		ans = given[k - 1]
	else:
		ans = ''
		if len(set(given[k:])) == 1:
			for i in range(0, n, k):
				ans += given[i]
		else:
			ans = ''.join(given[k - 1:])
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	st = ['a'] + list(input().strip()) + ['z']
	st.sort()
	if st[1] != st[k]:
		print(st[k])
	elif st[k + 1] != st[n]:
		print(st[1] + ''.join(st[k + 1:-1]))
	else:
		x = (n - k) // k + (n % k != 0)
		print(st[1] + st[-2] * x)


from sys import stdin
input = stdin.readline
import bisect
import math
for xoxo in range(1):
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		s = input()
		s = s[:n]
		l = list(s)
		l.sort()
		ans = ''
		i = 0
		ans = ['' for i in range(k)]
		ans1 = ['' for i in range(k)]
		if k == 1:
			for i in range(n):
				print(l[i], end='')
			print()
			continue
		for i in range(k):
			ans[i] += str(l[i])
			ans1[i] += str(l[i])
		for i in range(k, n):
			ans[0] += str(l[i])
			ans1[i % k] += str(l[i])
		ans.sort()
		ans1.sort()
		print(min(ans[-1], ans1[-1]))


def solve(s, k):
	n = len(s)
	sorted_letters = sorted([c for c in s])
	words = ['' for _ in range(k)]
	for i in range(k):
		words[i] = [sorted_letters[i]]
	remaining = [sorted_letters[i] for i in range(k, n)]
	distinct_r = len(set(remaining))
	if distinct_r == 1 and words[0][0] == words[-1][0]:
		p = 0
		for c in remaining:
			words[p].append(c)
			p = (p + 1) % k
	else:
		words[0].extend(remaining)
	for i in range(k):
		words[i] = ''.join([str(c) for c in words[i]])
	return sorted(words)[-1]

def main():
	T = int(input().strip())
	for _ in range(T):
		(n, k) = list(map(int, input().strip().split()))
		s = input().strip()
		r = solve(s, k)
		print(r)
main()


import math
from collections import defaultdict
a = int(input())
for i in range(a):
	(x, k) = map(int, input().split())
	s = input()
	ans = [s[i] for i in range(len(s))]
	ans.sort()
	al = defaultdict(int)
	for i in range(len(s)):
		al[s[i]] += 1
	fin = []
	for i in range(k):
		fin.append(ans[i])
	gam = ans[k:]
	if fin.count(max(fin)) != len(fin):
		print(max(fin))
	else:
		flag = 1
		if s.count(fin[0]) == k and len(set(ans)) == 2:
			flag = 0
		if flag == 1:
			t = []
			if len(set(gam)) == 1:
				t.extend(max(fin))
				r = gam[0] * math.ceil(len(gam) / k)
				t.extend(r)
				print(''.join(map(str, t)))
				continue
			gam = sorted(gam)
			t.extend(max(fin))
			t.extend(gam)
			print(''.join(map(str, t)))
		else:
			t = ''
			ans = list(set(ans))
			for i in range(len(ans)):
				t += ans[i] * math.ceil(al[ans[i]] / k)
			t = sorted(t)
			print(''.join(map(str, t)))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = input().rstrip()
	s = [s[i] for i in range(n)]
	s.sort()
	cnt = 0
	for i in range(n):
		if s[i] == s[0]:
			cnt += 1
		else:
			break
	if cnt >= k:
		if cnt == n:
			L = (n - 1) // k + 1
			res = [s[0] for i in range(L)]
			print(''.join(res))
		else:
			res = [s[0]]
			s = s[k:]
			n = len(s)
			if all((s[0] == s[i] for i in range(n))):
				L = (n - 1) // k + 1
				res += [s[0] for i in range(L)]
			else:
				res += s
			print(''.join(res))
	else:
		print(s[k - 1])


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	st = list(input())
	st.sort()
	if n == k:
		print(st[-1])
	elif st[0] == st[k - 1]:
		ans = st[0]
		li = st[k:].copy()
		dic = {}
		for i in li:
			if i in dic:
				dic[i] += 1
			else:
				dic[i] = 1
		kke = list(dic.keys())
		if len(kke) == 1:
			print(ans + kke[0] * abs(int(-dic[kke[0]] // k)))
		else:
			print(ans + ''.join(li))
	else:
		print(st[k - 1])


from collections import Counter
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	for _ in range(II()):
		(n, k) = MI()
		s = list(SI())
		s.sort()
		cc = Counter(s)
		if cc[s[0]] < k:
			print(s[k - 1])
		elif len(cc) == 1:
			c = s[0]
			print(c * ((cc[c] + k - 1) // k))
		elif len(cc) == 2 and cc[s[0]] == k:
			c = s[k]
			print(s[0] + c * ((cc[c] + k - 1) // k))
		else:
			ans = s[0] + ''.join(s[k:])
			print(ans)
main()


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(input().rstrip())
	a.sort()
	s = set(a)
	cnt = 0
	for x in range(n):
		if a[0] == a[x]:
			cnt += 1
		else:
			break
	if cnt < k:
		print(a[k - 1])
		continue
	elif cnt > k:
		if len(s) == 1:
			print(a[0] * ((n - 1) // k + 1))
		else:
			print(a[0] + ''.join(a[k:]))
	elif len(s) == 1:
		print(a[0])
	elif len(s) == 2:
		print(a[0] + a[-1] * ((n - cnt - 1) // k + 1))
	else:
		print(a[0] + ''.join(a[k:]))


inp = lambda cast=int: [cast(x) for x in input().split()]
printf = lambda s='', *args, **kwargs: print(str(s).format(*args), flush=True, **kwargs)

def solve(S, n, k):
	if n == k or S[0] != S[k - 1]:
		return S[k - 1]
	if S[k] == S[-1]:
		return S[0] + S[k] * ((n - k) // k + int(n % k > 0))
	return S[0] + S[k:]
(t,) = inp()
for _ in range(t):
	(n, k) = inp()
	S = ''.join(sorted(list(inp(str)[0])))
	print(solve(S, n, k))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = sorted(input())
	if len(set(a[0:k])) > 1 or n == k:
		print(a[k - 1])
	elif a[k] != a[n - 1]:
		print(a[k - 1] + ''.join(a[k:n]))
	else:
		print(a[k - 1] + ''.join(a[k] * ((n - k) // k + int((n - k) % k > 0))))


N = int(input())
for _ in range(N):
	(n, k) = map(int, input().split())
	s = list(input().strip())
	s = sorted(s)
	res = []
	if s[0] != s[k - 1]:
		res += [s[k - 1]]
	else:
		res += s[k - 1]
		s = s[k:]
		if len(s) > 0:
			if s[0] == s[-1]:
				if len(s) % k == 0:
					res += [s[0]] * (len(s) // k)
				else:
					res += [s[0]] * (len(s) // k + 1)
			else:
				res += s
	print(''.join(res))


from math import ceil
for _ in ' ' * int(input()):
	(n, k) = map(int, input().split())
	s = sorted(input())
	print(s[k - 1] if s[0] != s[k - 1] else s[k - 1] + s[-1] * ceil((n - k) / k) if len(set(s[k:])) == 1 else ''.join(s[k - 1:]))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(input())
	a.sort()
	if a[k - 1] != a[0]:
		print(a[k - 1])
	elif a[0] != a[-1]:
		if len(set(a)) > 2:
			for i in a[k - 1:]:
				print(i, end='')
			print()
		elif a.count(a[0]) == k:
			b = a.count(a[-1])
			print(a[0] + a[-1] * (b // k + int(b % k != 0)))
		else:
			for i in a[k - 1:]:
				print(i, end='')
			print()
	else:
		print(a[0] * (n // k + int(n % k != 0)))


for _ in range(int(input())):
	(n, k) = tuple(map(int, input().split()))
	s = [i for i in input()]
	s.sort()
	words = [[s[i]] for i in range(k)]
	ost = s[k:]
	if len(ost) == 0 or words[0][0] != words[-1][0]:
		print(words[-1][0])
		continue
	if ost.count(ost[0]) != len(ost):
		print(*words[-1] + ost, sep='')
		continue
	if len(ost) % k == 0:
		ost = ost[:len(ost) // k]
	else:
		ost = ost[:len(ost) // k + 1]
	print(*words[-1] + ost, sep='')


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = sorted(input())
	has = [0] * 26
	for i in s:
		has[ord(i) - ord('a')] += 1
	ss = sorted(set(s))
	if len(ss) == 2 and has[ord(ss[0]) - ord('a')] == k:
		aa = has[ord(ss[1]) - ord('a')]
		ans = s[0] + ss[1] * math.ceil(aa / k)
		print(*ans, sep='')
	elif len(ss) == 1:
		aa = has[ord(s[0]) - ord('a')]
		ans = s[0] * math.ceil(aa / k)
		print(*ans, sep='')
	else:
		ans = ''
		if has[ord(ss[0]) - ord('a')] < k:
			ans = s[k - 1]
		else:
			ans = s[k - 1:]
		print(*ans, sep='')


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = input()
	d = sorted(s)
	front = d[:k]
	if len(set(front)) != 1:
		print(d[k - 1])
	else:
		f_letter = d[0]
		back = d[k:len(d)]
		if len(set(back)) == 1:
			print(d[0] + d[k] * math.ceil((len(d) - k) / k))
		else:
			print(d[0] + ''.join(back))


import math
for i in range(int(input())):
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort()
	ans = ''
	if k == n:
		print(s[n - 1])
		continue
	if s[k - 1] == s[0]:
		for j in range(k - 1, n):
			ans += s[j]
	else:
		ans = s[k - 1]
	if s[k - 1] == s[0] and s[k] == s[n - 1]:
		ans = s[k - 1] + s[n - 1] * int(math.ceil(s[k:].count(s[n - 1]) / k))
	print(ans)


import math
test = int(input())
for tes in range(test):
	(n, k) = list(map(int, input().split()))
	s = str(input())
	ls = [x for x in s]
	ls.sort()
	res = [ls[i] for i in range(k)]
	if res[-1] != res[0]:
		print(res[-1])
		continue
	if k == n:
		print(ls[-1])
		continue
	first = ls[k]
	dum = True
	for i in range(k, n):
		if ls[i] != first:
			dum = False
	if dum:
		print(res[0] + first * math.ceil((n - k) / k))
	else:
		ans = res[0]
		for i in range(k, n):
			ans += ls[i]
		print(ans)


from collections import deque
from collections import OrderedDict
import math
import sys
import os
from io import BytesIO
for t in range(int(input())):
	(n, k) = map(int, input().split())
	str1 = str(input())
	str1 = sorted(str1)
	if str1[0] != str1[k - 1]:
		print(str1[k - 1])
		continue
	dic = dict()
	for i in range(n):
		if str1[i] in dic:
			dic[str1[i]] += 1
		else:
			dic[str1[i]] = 1
	if len(dic) > 2:
		print(str1[0], end='')
		for i in range(k, n):
			print(str1[i], end='')
	elif len(dic) == 1:
		leng = n // k
		if n % k != 0:
			leng += 1
		for i in range(leng):
			print(str1[0], end='')
	elif dic[str1[0]] // k == 1 and dic[str1[0]] % k == 0:
		leng = dic[str1[n - 1]] // k
		print(str1[0], end='')
		if dic[str1[n - 1]] % k != 0:
			leng += 1
		for i in range(leng):
			print(str1[n - 1], end='')
	else:
		print(str1[0], end='')
		for i in range(k, n):
			print(str1[i], end='')
	print('\n')


from sys import stdin, stdout
import math

def f1(keys, counter, k):
	first_el = keys[0]
	first_count = counter[first_el] - (k - 1)
	answer = first_el * first_count
	for i in range(1, len(keys)):
		el = keys[i]
		count = counter[el]
		part = el * count
		answer = answer + part
	return answer

def f2(keys, counter, k):
	first_el = keys[0]
	first_count = counter[first_el]
	if first_count % k == 0:
		big = first_el * (first_count // k)
		small = big
		equal = True
	else:
		big = first_el * math.ceil(first_count / k)
		small = first_el * math.floor(first_count / k)
		equal = False
	for i in range(1, len(keys)):
		el = keys[i]
		if not equal:
			return small + el
		count = counter[el]
		if count % k == 0:
			part_common = el * (count // k)
			big += part_common
			small = big
		else:
			part_big = el * math.ceil(count / k)
			big += part_big
			part_small = el * math.floor(count / k)
			small += part_small
			equal = False
	return big

def main():
	t = int(input())
	for _ in range(t):
		(n, k) = [int(i) for i in input().split()]
		s = input()
		counter = {}
		for el in s:
			if el not in counter:
				counter[el] = 0
			counter[el] += 1
		keys = sorted(counter.keys())
		count = 0
		count_type = 0
		for el in keys:
			count += counter[el]
			count_type += 1
			if count >= k:
				break
		if count_type > 1:
			print(keys[count_type - 1])
			continue
		v1 = f1(keys, counter, k)
		v2 = f2(keys, counter, k)
		if v1 < v2:
			print(v1)
		else:
			print(v2)
main()


I = input
exec(int(I()) * "n,k=map(int,I().split());s=''.join(sorted(I()));c=s[k-1];print(c+(c==s[0])*s[k::k**(s[k%n]==s[-1])]);")


from collections import *
from bisect import *
from math import *
import sys
input = sys.stdin.readline
t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	a = input().rstrip('\n')
	if k == 1:
		s = list(a)
		s.sort()
		print(''.join(s))
		continue
	f = set()
	s = list(a)
	s.sort()
	for i in range(k):
		f.add(s[i])
	if len(f) >= 2:
		print(max(f))
		continue
	g = Counter(a)
	if len(f) == 1 and s.count(min(s)) == k and (s.count(max(s)) == n - k):
		c = ceil(s.count(max(s)) / k)
		print(min(s) + max(s) * c)
		continue
	if len(f) == 1 and s.count(s[0]) == n:
		c = ceil(n / k)
		print(s[0] * c)
		continue
	flag = 0
	h = ''
	for i in range(k - 1, len(s)):
		h += s[i]
	print(h)


import os
import sys
import math
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for jj in range(int(input())):
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort()
	sb = ''
	if k == n:
		print(s[n - 1])
		continue
	if s[k - 1] == s[0]:
		for j in range(k - 1, n):
			sb += s[j]
	else:
		sb = s[k - 1]
	if s[k - 1] == s[0] and s[k] == s[n - 1]:
		sb = s[k - 1] + s[n - 1] * int(math.ceil(s[k:].count(s[n - 1]) / k))
	print(sb)


from collections import deque
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	x = sorted(input())
	base = x[:k]
	x = x[k:]
	if len(set(base)) > 1 or len(x) <= 0:
		print(max(base))
		continue
	if len(set(x)) == 1:
		print(base[0] + (len(x) // k + (1 if len(x) % k > 0 else 0)) * x[0])
	else:
		print(base[0] + ''.join(x))


def min_max_lexicographic(string, k):
	s = sorted(list(string))
	n = len(s)
	if s[0] != s[k - 1] or k == n:
		return s[k - 1]
	if s[k] != s[n - 1]:
		return ''.join(s[k - 1:])
	return ''.join([s[0]] + [s[k]] * ((n - k - 1) // k + 1))
t = int(input())
for _ in range(t):
	(n, k) = [int(k) for k in input().split()]
	s = input()
	print(min_max_lexicographic(s, k))


import sys, os.path
import math
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = input()
	l = [i for i in s]
	l.sort()
	s = ''.join(l)
	if s[0] != s[k - 1]:
		print(s[k - 1])
	else:
		ans = s[0]
		if k < n:
			if s[k] != s[n - 1]:
				for i in range(k, n):
					ans += s[i]
				print(ans)
			else:
				for i in range((n - k + k - 1) // k):
					ans += s[n - 1]
				print(ans)
		else:
			print(ans)


t = int(input())

def sol():
	(n, k) = map(int, input().split())
	sr = input().strip()
	s = sorted([c for c in sr])
	if k == 1:
		return ''.join(s)
	if s[k - 1] != s[0] or k == n:
		return s[k - 1]
	if s[k] == s[n - 1]:
		return s[k - 1] + s[k] * ((n - 1) // k)
	return ''.join(s[k - 1:])
for _ in range(t):
	print(sol())


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort()
	c = s[0]
	if s[k - 1] != c:
		print(s[k - 1])
	else:
		x = set(s[k:])
		if len(x) == 0 or len(x) == 1:
			ans = [''] * k
			j = 0
			for i in range(n):
				ans[j] = ans[j] + s[i]
				j = (j + 1) % k
			ans.sort()
			m = ans[-1]
		else:
			m = ''
			for i in range(k - 1, n):
				m = m + s[i]
		print(m)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = input()
	s = sorted(s)
	if k == n:
		print(''.join(map(str, s[-1])))
	elif s[0] == s[k - 1]:
		ans = [s[k - 1]]
		if s[k] == s[n - 1]:
			times = (n - 1 - k + 1) // k
			if (n - 1 - k + 1) % k is not 0:
				times += 1
			for i in range(times):
				ans.append(s[k])
			print(''.join(map(str, ans)))
		else:
			for i in range(k, n):
				ans.append(s[i])
			print(''.join(map(str, ans)))
	else:
		print(s[k - 1])


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	(n, k) = value()
	a = sorted(input())
	freq = Counter(a)
	ans = defaultdict(list)
	i = 0
	ind = 0
	while i < k:
		freq[a[i]] -= 1
		ans[ind].append(a[i])
		i += 1
		ind = (ind + 1) % k
	if ans[0] != ans[k - 1]:
		print(*ans[k - 1])
		continue
	try:
		flag = False
		if freq[a[i]] < n - k:
			flag = True
	except:
		pass
	while i < n:
		ans[ind].append(a[i])
		last = a[i]
		i += 1
		if not flag:
			while i < n and a[i] != last:
				ans[ind].append(a[i])
				i += 1
			ind = (ind + 1) % k
	print(*max(ans.values(), key=lambda x: ''.join(x)), sep='')


def distribute(string, k):
	sorted_string = ''.join(sorted(string))
	if sorted_string[0] != sorted_string[k - 1]:
		return sorted_string[k - 1]
	first_letter = sorted_string[0]
	if len(sorted_string) == k:
		return first_letter
	if sorted_string[k] == sorted_string[-1]:
		second_letter = sorted_string[k]
		size = len(sorted_string)
		equal_split = second_letter * ((size - k) // k)
		non_equal_split = second_letter if size % k != 0 else ''
		return first_letter + equal_split + non_equal_split
	return sorted_string[k - 1:]
number_of_tests = int(input())
for _ in range(number_of_tests):
	(_, k) = map(int, input().split())
	string = input()
	result = distribute(string, k)
	print(result)


from collections import deque

def solve():
	(n, k) = [int(x) for x in input().split()]
	string = input()
	li = deque()
	for ele in string:
		li.append(ele)
	li = list(li)
	li.sort()
	s = ''
	for ele in li:
		s += ele
	if n == k:
		print(s[n - 1])
		return
	if s[0] != s[k - 1]:
		print(s[k - 1])
		return
	elif s[k] != s[n - 1]:
		print(s[0] + s[k:])
		return
	else:
		rest = n - k
		if rest % k == 0:
			add = rest // k
			print(s[0] + s[k] * add)
		else:
			add = rest // k + 1
			print(s[0] + s[k] * add)
	return
t = int(input())
for i in range(t):
	solve()


import math
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = input()
	s1 = [i for i in s]
	s1.sort()
	s = ''.join(s1)
	if m == 1:
		print(s)
		continue
	if m == n:
		print(s[n - 1])
		continue
	l = [[s[i]] for i in range(m)]
	p = -1
	for i in range(m - 1):
		if l[i] == l[m - 1]:
			p = i
			break
	if p == -1:
		print(*l[m - 1])
		continue
	if p == 0:
		if s[m] == s[n - 1]:
			print(s[0] + s[m] * math.ceil((n - m) / m))
		else:
			print(s[0] + s[m:])
	else:
		print(*l[m - 1])


def main():
	ileT = int(input())
	for i in range(ileT):
		(ileL, ileS) = tuple(map(int, input().split()))
		sIn = list(input())
		sIn.sort()
		sOut = [[] for _ in range(ileS)]
		if sIn[ileS - 1] == sIn[0]:
			for j in range(ileS):
				sOut[j].append(sIn[0])
		else:
			print(*sIn[ileS - 1])
			continue
		akt = ileS
		while akt < ileL:
			if akt + ileS - 1 >= ileL:
				if sIn[akt] == sIn[-1]:
					print(*sOut[0], *sIn[akt], sep='')
					break
				else:
					print(*sOut[0], *sIn[akt:], sep='')
					break
			elif sIn[akt + ileS - 1] == sIn[akt]:
				if sIn[-1] == sIn[akt]:
					for j in range(ileS):
						sOut[j].append(sIn[akt])
					akt += ileS
				else:
					print(*sOut[0], *sIn[akt:], sep='')
					break
			else:
				print(*sOut[0], *sIn[akt:], sep='')
				break
		if akt == ileL:
			print(*sOut[0], sep='')
main()


import math
t = int(input())
for t1 in range(t):
	(n, k) = map(int, input().split())
	s = input()
	s = sorted(s)
	if k == 1:
		print(*s, sep='')
		continue
	if s[0] != s[k - 1]:
		print(*s[k - 1], sep='')
		continue
	l1 = []
	for i in range(k):
		l1.append(s[i])
	if k == n:
		print(s[0])
		continue
	if s[k] != s[n - 1]:
		print(s[k - 1], end='')
		print(*(s[i] for i in range(k, n)), sep='')
		continue
	print(s[k - 1] + s[k] * math.ceil((n - k) / k))


import sys
from collections import deque
input = lambda : sys.stdin.readline().strip()
ipnut = input
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort()
	if k == 1:
		print(''.join(s))
		continue
	ans = []
	suff = [0] * n
	su = set()
	f = True
	for i in range(n):
		su.add(s[-1 - i])
		suff[-1 - i] = len(su)
	for i in range(0, n, k):
		if len(set(s[i:min(i + k, n)])) == 1:
			if i == 0:
				ans.append(s[i])
			elif suff[i] == 1:
				ans.append(s[i])
			else:
				ans += s[i:]
				break
		else:
			if i:
				ans += s[i:]
			else:
				ans.append(s[min(i + k - 1, n - 1)])
			break
	print(''.join(ans))


import io
import os
from collections import Counter

def solve(N, K, S):
	if K == 1:
		return ''.join(sorted(S))
	counts = Counter(S)
	firstLetter = [None for i in range(K)]
	key = 'a'
	for i in range(K):
		while key not in counts:
			assert key != 'z'
			key = chr(ord(key) + 1)
		counts[key] -= 1
		if counts[key] == 0:
			del counts[key]
		firstLetter[i] = key
	if len(set(firstLetter)) > 1:
		return ''.join(firstLetter[-1])
	elif len(counts) == 1:
		(key, count) = next(iter(counts.items()))
		if count % K == 0:
			count //= K
		else:
			count = count // K + 1
		return firstLetter[-1] + key * count
	else:
		return firstLetter[-1] + ''.join((k * count for (k, count) in sorted(counts.items())))
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(N, K) = [int(x) for x in input().split()]
	S = input().decode().rstrip()
	ans = solve(N, K, S)
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = input()
	ss = ''.join(sorted(s))
	ch = ss[0]
	fk = True
	for i in range(1, k):
		if ss[i] != ch:
			fk = False
			break
	if fk == False:
		print(ss[k - 1])
	elif k == n or ss[k] != ss[n - 1]:
		ans = ss[0]
		tr = k
		while tr < n:
			ans += ss[tr]
			tr += 1
		print(ans)
	else:
		ans = ss[0]
		tr = k
		while tr < n:
			ans += ss[tr]
			tr += k
		print(ans)


q = int(input())
for _ in range(q):
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort()
	slowo = [[] for i in range(k)]
	if s[0] != s[k - 1]:
		print(s[k - 1])
	elif k == n:
		print(s[n - 1])
	else:
		dl = (n - 1) // k
		if s[k] == s[-1]:
			odp = [s[0]] + [s[k]] * dl
		else:
			odp = [s[0]] + s[k:]
		print(''.join(odp))


import io
import os
from sys import stdout, stdin
from math import ceil
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = list(input().strip())
	s.sort()
	ans = ''
	if k != n:
		if s[0] != s[k - 1]:
			ans = s[k - 1]
		else:
			ans = s[0]
			if s[k] != s[n - 1]:
				for i in range(k, n):
					ans += s[i]
			else:
				for i in range(k, n, k):
					ans += s[i]
	else:
		ans = s[-1]
	stdout.write(ans + '\n')


import math, sys
import heapq
from fractions import Fraction
from collections import Counter, defaultdict

def li():
	return list(map(int, sys.stdin.readline().split()))

def ls():
	return list(map(int, list(input())))

def la():
	return list(input())

def ii():
	return int(input())

def dic(x):
	return defaultdict(lambda : x)

def isPrime(n):
	i = 2
	if n == 1:
		return False
	while i <= int(math.sqrt(n)):
		if n % i == 0:
			return False
		i = i + 1
	return True

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def LCM(a, b):
	return a * b / gcd(a, b)
t = ii()
for _ in range(t):
	(n, k) = li()
	s = la()
	s.sort()
	c = Counter(s)
	u = set(s)
	if k == 1:
		print(''.join(s))
	elif c[s[0]] < k:
		print(s[k - 1])
	elif len(u) == 1:
		x = n // k
		if n % k != 0:
			x = x + 1
		print(x * s[0])
	elif len(u) == 2 and c[s[0]] == k:
		x = c[s[k]] // k
		if c[s[k]] % k != 0:
			x = x + 1
		y = s[0] + s[k] * x
		print(''.join(y))
	else:
		x = [s[0]] + s[k:n]
		print(''.join(x))


t = int(input())
from collections import Counter
import sys
import math
for _ in range(t):
	(n, k) = map(int, input().split())
	s = input()
	se = set()
	st = []
	for i in range(n):
		st.append(s[i])
		se.add(s[i])
	st.sort()
	ans = [[] for i in range(k)]
	for i in range(k):
		ans[i].append(st[i])
	fl = 1
	for i in range(k - 1):
		if st[i] != st[i + 1]:
			fl = 0
	if fl == 0:
		ans[0] += st[k:]
	else:
		b = Counter(st[k:])
		cou = 0
		if len(b) == 1:
			for i in range(n - k):
				ans[cou % k].append(st[i + k])
				cou += 1
		else:
			ans[0] += st[k:]
	tans = []
	for i in ans:
		p = ''.join(i)
		tans.append(p)
	tans.sort()
	print(tans[k - 1])


t = int(input())
while t:
	t -= 1
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	s = input()
	s = ''.join(sorted(s))
	arr = ['' for i in range(k)]
	found = False
	for j in range(k):
		arr[j] += s[j]
	if arr[0] != arr[-1]:
		print(arr[-1])
	else:
		for i in range(k, n - 1):
			if s[i] != s[i + 1]:
				found = True
				break
		if found:
			for i in range(k, n):
				arr[0] += s[i]
			print(arr[0])
		else:
			for i in range(k, n):
				arr[i % k] += s[i]
			print(arr[0])


n = int(input())
while n > 0:
	n = n - 1
	l = []
	(m, k) = map(int, input().split())
	a = input()
	s = sorted(a)
	if s[0] != s[k - 1]:
		print(s[k - 1])
		continue
	l.append(s[0])
	if m != k:
		if s[k] != s[m - 1]:
			for i in range(k, m):
				l.append(s[i])
		else:
			for i in range((m - k + k - 1) // k):
				l.append(s[m - 1])
	print(''.join(l))


t = int(input())
for _ in range(t):
	s = input().split()
	n = int(s[0])
	k = int(s[1])
	string = input()
	a = [[] for i in range(k)]
	letters = [0] * 26
	for i in range(len(string)):
		letters[ord(string[i]) - 97] += 1
	index = 0
	index_for_a = 0
	first_time = True
	first_letter = ''
	last_letter = ''
	while index < len(letters):
		while letters[index] != 0:
			if first_time:
				first_time = False
				first_letter = chr(index + 97)
			last_letter = chr(index + 97)
			a[index_for_a].append(chr(index + 97))
			index_for_a += 1
			letters[index] -= 1
			if index_for_a == len(a):
				break
		if index_for_a == len(a):
			break
		index += 1
	if first_letter != last_letter:
		print(last_letter)
	else:
		types_of_letters = 0
		the_letter = ''
		for i in range(len(letters)):
			if letters[i] != 0:
				types_of_letters += 1
				the_letter = chr(i + 97)
		if types_of_letters != 1:
			print(a[0][0], end='')
			for i in range(len(letters)):
				print(chr(i + 97) * letters[i], end='')
			print()
		else:
			print(a[0][0], end='')
			print(the_letter * (letters[ord(the_letter) - 97] // k), end='')
			if letters[ord(the_letter) - 97] % k != 0:
				print(the_letter, end='')
			print()


from sys import stdin
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	(n, k) = [int(x) for x in inp().split()]
	s = list(inp())
	s.sort()
	countAlpha = [0] * 26
	ans1 = [[], []]
	ans1[0] = list(s[k - 1])
	ans1[1].append(s[0])
	ans1[1].extend(s[k:])
	ans2 = [[] for x in range(k)]
	counter = 0
	for i in s:
		ans2[counter % k].append(i)
		counter += 1
	ans2 = max(ans2)
	ans1 = max(ans1)
	ans = min(ans1, ans2)
	print(''.join(ans))


from collections import *
t = int(input())
for y in range(t):
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort()
	ans = ['' for i in range(k)]
	(j, f) = (0, 1)
	for i in range(n):
		ans[j] += s[i]
		if j != 0 and s[i] != s[i - 1]:
			f = 0
		if i != n - 1:
			j = (j + 1) % k
		if i == n - 1:
			x = ''.join(s[k - 1:])
			ans[j] = min(ans[j], x)
		if j == 0 and f == 0:
			j = k - 1
			if i >= k:
				x = ''.join(s[k - 1:])
				ans[j] = min(ans[j], x)
			break
	print(ans[j])


import math

def ls(l):
	x = ''
	for i in l:
		x += i
	return x
t = int(input())
for you in range(t):
	l = input().split()
	n = int(l[0])
	k = int(l[1])
	s = input()
	arr = [0 for i in range(26)]
	for i in s:
		arr[ord(i) - 97] += 1
	for i in range(26):
		if arr[i] >= 1:
			first = i
			break
	for i in range(25, -1, -1):
		if arr[i] >= 1:
			last = i
			break
	lfi = []
	done = 0
	while done != 1:
		if arr[first] < k:
			sumi = 0
			for i in range(26):
				sumi += arr[i]
				if sumi >= k:
					lfi.append(chr(97 + i))
					done = 1
					break
		elif arr[first] == k:
			lfi.append(chr(first + 97))
			if first == last:
				done = 1
			else:
				for j in range(first + 1, 26):
					if arr[j] >= 1:
						first = j
						break
				if first == last:
					for i in range(math.ceil(arr[first] / k)):
						lfi.append(chr(97 + first))
				else:
					for j in range(first, 26):
						for k in range(arr[j]):
							lfi.append(chr(97 + j))
				done = 1
		elif first == last:
			for i in range(math.ceil(arr[first] / k)):
				lfi.append(chr(97 + first))
			done = 1
		else:
			for i in range(arr[first] - k + 1):
				lfi.append(chr(97 + first))
			for j in range(first + 1, 26):
				for k in range(arr[j]):
					lfi.append(chr(97 + j))
			done = 1
	for i in lfi:
		print(i, end='')
	print()


t = int(input())
for q in range(0, t):
	(n, k) = map(int, input().split())
	s = input()
	arr = []
	for i in range(0, n):
		arr.append(s[i])
	arr.sort()
	if k == 1:
		s = ''
		for i in range(0, n):
			s += arr[i]
		print(s)
	elif arr[k - 1] != arr[k - 2]:
		print(arr[k - 1])
	elif k == n:
		print(arr[k - 1])
	elif arr[0] != arr[k - 1]:
		print(arr[k - 1])
	else:
		before = 0
		for i in range(k - 1, -1, -1):
			if arr[i] != arr[k - 1]:
				break
			else:
				before += 1
		if arr[k] == arr[n - 1]:
			after = n - k
			if after < before or after % before != 0:
				print(arr[k - 1], arr[k] * (after // before + 1), sep='')
			else:
				print(arr[k - 1], arr[k] * (after // before), sep='')
		else:
			after = 0
			new = 0
			for i in range(k, n):
				if arr[i] == arr[k]:
					after += 1
				else:
					new = i
					break
			news = ''
			for i in range(new, n):
				news += arr[i]
			print(arr[k - 1], arr[k] * after, news, sep='')


import sys

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output2.txt', 'w')
t = int(input())
while t > 0:
	t -= 1
	(n, k) = map(int, input().split())
	s = list(input().rstrip())
	s.sort()
	d = {}
	a = ['' for i in range(k)]
	for i in range(k):
		a[i % k] += s[i]
	j = 0
	i = k
	if len(set(s[k:])) == 1:
		for i in range(k, len(s)):
			a[j % k] += s[i]
			j += 1
			if j == k or a[j][0] > a[0][0]:
				j = 0
	else:
		for i in range(k, len(s)):
			a[j % k] += s[i]
	print(max(a))


import math
import os
import sys
from io import BytesIO, IOBase

def main():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		L = input()
		alpha = [0] * 26
		for char in L:
			alpha[ord(char) - ord('a')] += 1
		for i in range(26):
			if alpha[i] > 0:
				minChar = i
				break
		if alpha[minChar] > k:
			count = 0
			for i in range(26):
				if alpha[i] > 0:
					count += 1
			if count == 1:
				ans = math.ceil(n / k) * chr(ord('a') + minChar)
			else:
				ans = ''
				ans += (alpha[minChar] - k + 1) * chr(ord('a') + minChar)
				for i in range(minChar + 1, 26):
					ans += alpha[i] * chr(ord('a') + i)
		elif alpha[minChar] < k:
			preSum = [0] * 26
			preSum[0] = alpha[0]
			for i in range(1, 26):
				preSum[i] = preSum[i - 1] + alpha[i]
			for i in range(26):
				if preSum[i] >= k:
					ans = chr(ord('a') + i)
					break
		else:
			ans = ''
			ans += chr(ord('a') + minChar)
			count = 0
			for i in range(26):
				if alpha[i] > 0:
					count += 1
					second = i
			if count == 2:
				ans += math.ceil(alpha[second] / k) * chr(ord('a') + second)
			else:
				for i in range(minChar + 1, 26):
					ans += alpha[i] * chr(ord('a') + i)
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = lambda s: self.buffer.write(s.encode()) if self.writable else None

	def read(self):
		if self.buffer.tell():
			return self.buffer.read().decode('ascii')
		return os.read(self._fd, os.fstat(self._fd).st_size).decode('ascii')

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline().decode('ascii')

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

def print(*args, sep=' ', end='\n', file=sys.stdout, flush=False):
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(end)
	if flush:
		file.flush()
(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.setrecursionlimit(10000)
main()


MOD = 10 ** 9 + 7

def main():
	for _ in inputt():
		(n, k) = inputi()
		S = sorted(input())
		if S[0] == S[k - 1]:
			if k != n and S[k] == S[-1]:
				print(''.join(S[0] + S[k] * (ceil(n / k) - 1)))
			else:
				print(''.join(S[k - 1:]))
		else:
			print(S[k - 1])
from math import *
from heapq import *
from itertools import *
from functools import reduce, lru_cache, partial
from collections import Counter, defaultdict
import re, copy, operator, cmath
import sys, io, os, builtins
sys.setrecursionlimit(1000)
BUFSIZE = 8192

class FastIO(io.IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = io.BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(io.IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	if args:
		sys.stdout.write(str(args[0]))
		split = kwargs.pop('split', ' ')
		for arg in args[1:]:
			sys.stdout.write(split)
			sys.stdout.write(str(arg))
	sys.stdout.write(kwargs.pop('end', '\n'))

def debug(*args, **kwargs):
	print('debug', *args, **kwargs)
	sys.stdout.flush()
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip()
inputt = lambda t=0: range(t) if t else range(int(input()))
inputs = lambda : input().split()
inputi = lambda k=int: map(k, inputs())
inputl = lambda t=0, k=lambda : list(inputi()): [k() for _ in range(t)] if t else list(k())

def len(a):
	if isinstance(a, range):
		return -((a.start - a.stop) // a.step)
	return builtins.len(a)

def bisect_left(a, x, key=None, lo=0, hi=None):
	if lo < 0:
		lo = 0
	if hi == None:
		hi = len(a)
	if key == None:
		key = do_nothing
	while lo < hi:
		mid = (lo + hi) // 2
		if key(a[mid]) < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def bisect_right(a, x, key=None, lo=0, hi=None):
	if lo < 0:
		lo = 0
	if hi == None:
		hi = len(a)
	if key == None:
		key = do_nothing
	while lo < hi:
		mid = (lo + hi) // 2
		if x < key(a[mid]):
			hi = mid
		else:
			lo = mid + 1
	return lo

def insort_left(a, x, key=None, lo=0, hi=None):
	lo = bisect_left(a, x, key, lo, hi)
	a.insert(lo, x)

def insort_right(a, x, key=None, lo=0, hi=None):
	lo = bisect_right(a, x, key, lo, hi)
	a.insert(lo, x)
do_nothing = lambda x: x
bisect = bisect_right
insort = insort_right

def index(a, x, default=None, key=None, lo=0, hi=None):
	if lo < 0:
		lo = 0
	if hi == None:
		hi = len(a)
	if key == None:
		key = do_nothing
	i = bisect_left(a, x, key, lo, hi)
	if lo <= i < hi and key(a[i]) == x:
		return a[i]
	if default != None:
		return default
	raise ValueError

def find_lt(a, x, default=None, key=None, lo=0, hi=None):
	if lo < 0:
		lo = 0
	if hi == None:
		hi = len(a)
	i = bisect_left(a, x, key, lo, hi)
	if lo < i <= hi:
		return a[i - 1]
	if default != None:
		return default
	raise ValueError

def find_le(a, x, default=None, key=None, lo=0, hi=None):
	if lo < 0:
		lo = 0
	if hi == None:
		hi = len(a)
	i = bisect_right(a, x, key, lo, hi)
	if lo < i <= hi:
		return a[i - 1]
	if default != None:
		return default
	raise ValueError

def find_gt(a, x, default=None, key=None, lo=0, hi=None):
	if lo < 0:
		lo = 0
	if hi == None:
		hi = len(a)
	i = bisect_right(a, x, key, lo, hi)
	if lo <= i < hi:
		return a[i]
	if default != None:
		return default
	raise ValueError

def find_ge(a, x, default=None, key=None, lo=0, hi=None):
	if lo < 0:
		lo = 0
	if hi == None:
		hi = len(a)
	i = bisect_left(a, x, key, lo, hi)
	if lo <= i < hi:
		return a[i]
	if default != None:
		return default
	raise ValueError

class Tree:

	def __init__(n):
		self._n = n
		self._conn = [[] for _ in range(n)]
		self._list = [0] * n

	def connect(a, b):
		pass

class Sieve:

	def __init__(self):
		self._n = 6
		self._list = [2, 3, 5, 7, 11, 13]

	def extend(self, n):
		if n <= self._list[-1]:
			return
		maxbase = int(n ** 0.5) + 1
		self.extend(maxbase)
		begin = self._list[-1] + 1
		newsieve = [i for i in range(begin, n + 1)]
		for p in self.primerange(2, maxbase):
			for i in range(-begin % p, len(newsieve), p):
				newsieve[i] = 0
		self._list.extend([x for x in newsieve if x])

	def extend_to_no(self, i):
		while len(self._list) < i:
			self.extend(int(self._list[-1] * 1.5))

	def primerange(self, a, b):
		a = max(2, a)
		if a >= b:
			return
		self.extend(b)
		i = self.search(a)[1]
		maxi = len(self._list) + 1
		while i < maxi:
			p = self._list[i - 1]
			if p < b:
				yield p
				i += 1
			else:
				return

	def search(self, n):
		if n < 2:
			raise ValueError
		if n > self._list[-1]:
			self.extend(n)
		b = bisect(self._list, n)
		if self._list[b - 1] == n:
			return (b, b)
		else:
			return (b, b + 1)

	def __contains__(self, n):
		if n < 2:
			raise ValueError
		if not n % 2:
			return n == 2
		(a, b) = self.search(n)
		return a == b

	def __getitem__(self, n):
		if isinstance(n, slice):
			self.extend_to_no(n.stop + 1)
			return self._list[n.start:n.stop:n.step]
		else:
			self.extend_to_no(n + 1)
			return self._list[n]
sieve = Sieve()

def isprime(n):
	if n <= sieve._list[-1]:
		return n in sieve
	for i in sieve:
		if not n % i:
			return False
		if n < i * i:
			return True
prime = sieve.__getitem__
primerange = lambda a, b=0: sieve.primerange(a, b) if b else sieve.primerange(2, a)

def factorint(n):
	factors = []
	for i in sieve:
		if n < i * i:
			break
		while not n % i:
			factors.append(i)
			n //= i
	if n != 1:
		factors.append(n)
	return factors
factordict = lambda n: Counter(factorint(n))
main()


from collections import defaultdict
t = int(input())
for tc in range(t):
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort()
	first = s[:k]
	last = s[k:]
	if len(set(first)) > 1:
		print(s[k - 1])
	else:
		sol = [first[0]]
		if len(set(last)) == 1:
			for i in range((n - k) // k + bool((n - k) % k)):
				sol.append(last[0])
		else:
			sol += last
		print(''.join(sol))


from math import ceil
T = int(input())
for t in range(T):
	(N, K) = list(map(int, input().split()))
	s = input()
	s = ''.join(sorted(s))
	if K == 1:
		print(s)
		continue
	firstSame = True
	for i in range(1, K):
		if s[i] != s[i - 1]:
			firstSame = False
			break
	if not firstSame or K == N:
		print(s[K - 1])
		continue
	lastSame = True
	count = 1
	for i in range(K + 1, N):
		if s[i] != s[i - 1]:
			lastSame = False
			break
		count += 1
	if not lastSame:
		print(s[K - 1:])
	else:
		print(s[K - 1] + s[K] * ceil(count / K))


for _ in range(int(input())):
	cnt = [0] * 26
	(n, k) = map(int, input().split())
	s = input()
	for i in s:
		cnt[ord(i) - 97] += 1
	ss = sorted(s)
	s = ''
	cnt = [(chr(i + 97), cnt[i]) for i in range(26) if cnt[i]]
	if cnt[0][1] < k:
		s = ss[k - 1]
	elif cnt[0][1] > k:
		if len(cnt) == 1:
			s = cnt[0][0] * ((cnt[0][1] + k - 1) // k)
		else:
			s = cnt[0][0] * (cnt[0][1] - k + 1)
			for i in range(1, len(cnt)):
				s += cnt[i][0] * cnt[i][1]
	else:
		s = cnt[0][0]
		if len(cnt) == 2:
			s += cnt[1][0] * ((cnt[1][1] + k - 1) // k)
		elif len(cnt) > 2:
			for i in range(1, len(cnt)):
				s += cnt[i][0] * cnt[i][1]
	print(s)


import sys, random
from bisect import bisect_left, bisect_right
input = sys.stdin.readline

def main():
	inf = 10 ** 20
	t = int(input())
	for _ in range(1, t + 1):
		(n, k) = map(int, input().split())
		s = sorted(list(input().strip()))
		diff = 0
		for x in s[:k]:
			if x != s[0]:
				diff = 1
		if diff or k == n:
			print(s[k - 1])
		else:
			last = 1
			for x in s[k:]:
				if x != s[k]:
					last = 0
			if last:
				mul = (n - k) // k
				if (n - k) % k:
					mul += 1
				print(s[0] + s[k] * mul)
			else:
				print(s[0] + ''.join(s[k:]))
main()


import sys
input = sys.stdin.readline
from collections import Counter
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = list(input().rstrip())
	s.sort()
	first_letter = s[0]
	last_letter = s[-1]
	cnt = Counter(s)
	if len(cnt) == 1:
		print(first_letter * ((n + k - 1) // k))
		continue
	if cnt[first_letter] < k:
		print(''.join(s[k - 1]))
		continue
	if cnt[first_letter] > k:
		print(''.join(s[k - 1:]))
		continue
	if len(cnt) == 2:
		ret = first_letter + last_letter * ((cnt[last_letter] + k - 1) // k)
		print(''.join(ret))
	else:
		print(''.join(s[k - 1:]))


import random
import math
LI = lambda : list(map(int, input().split()))
MI = lambda : map(int, input().split())
yes = lambda : print('Yes')
no = lambda : print('No')
I = lambda : list(input())
J = lambda x: ''.join(x)
II = lambda : int(input())
SI = lambda : input()
t = II()
for q in range(t):
	(n, k) = MI()
	s = sorted(list(SI()))
	l = [0] * 26
	boo = True
	for i in s:
		l[ord(i) - 97] += 1
	for i in l:
		if i % k != 0:
			boo = False
	if k == 1:
		print(''.join(s))
	elif len(set(s)) == 1:
		print((n // k + 1) * s[0] if n % k != 0 else n // k * s[0])
	else:
		count = 0
		for i in s:
			if i == s[0]:
				count += 1
		if count >= k:
			ans = [s[0]] + s[k:]
			if ans[1] == ans[-1] and len(ans) != 2:
				ttt = l[ord(ans[1]) - 97]
				if ttt % k != 0:
					ttt = ttt // k + 1
				else:
					ttt = ttt // k
				ans = ans[0] + ttt * ans[1]
			print(''.join(ans))
		else:
			print(s[k - 1])


t = int(input())
import math
for _ in range(t):
	(n, k) = map(int, input().split())
	j = k
	s = input()
	arr = [0] * 26
	for i in s:
		arr[ord(i) - 97] += 1
	ans = ''
	i = 0
	strs = []
	while k > 0:
		if arr[i] > 0:
			arr[i] -= 1
			strs.append(i)
		else:
			while arr[i] == 0:
				i += 1
			arr[i] -= 1
			strs.append(i)
		k -= 1
	suffix = []
	s = 0
	for i in arr[::-1]:
		s += i
		suffix.append(s)
	suffix.reverse()
	last = -1
	second_last = -1
	for i in range(26):
		if arr[i] != 0:
			second_last = last
			last = i
	if strs[0] != strs[-1]:
		print(chr(97 + strs[-1]))
	else:
		x = 0
		for i in range(26):
			if arr[i] > 0:
				x += 1
		if x == 1:
			ans = str(chr(97 + strs[-1]))
			for i in range(26):
				if arr[i] > 0:
					ans += str(chr(97 + i)) * math.ceil(arr[i] / j)
			print(ans)
		else:
			ans = str(chr(97 + strs[-1]))
			for i in range(26):
				if arr[i] > 0:
					ans += str(chr(97 + i)) * arr[i]
			print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = list(input())
	l.sort()
	ans = [''] * k
	for i in range(k):
		ans[i] += l[i]
	if ans[-1] > ans[0]:
		print(ans[-1])
		continue
	if k < n and l[k] == l[-1]:
		for i in range(n - k):
			ans[i % k] += l[k + i]
	else:
		ans[0] += ''.join(l[k:])
	print(max(ans))


import sys
input = lambda : sys.stdin.readline().strip()
t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort()
	if s[0] != s[k - 1]:
		print(s[k - 1])
		continue
	print(s[0], end='')
	if k < n and s[k] != s[n - 1]:
		for i in range(k, n):
			print(s[i], end='')
	else:
		for i in range((n - k + k - 1) // k):
			print(s[n - 1], end='')
	print()


from math import ceil
import sys
input = sys.stdin.readline
from collections import defaultdict as dd, deque as dq
import bisect
t = int(input())
while t:
	(n, k) = map(int, input().split())
	kk = k
	s = input()
	d = dd(int)
	for i in s:
		d[i] += 1
	l = []
	for i in range(26):
		x = chr(ord('a') + i)
		if d[x] != 0:
			l.append(x)
	for i in range(len(l)):
		a = d[l[i]]
		if a >= kk:
			ans = l[i]
			break
		else:
			kk -= a
	if k == d[l[0]]:
		if len(l) == 2:
			ans += l[1] * ceil(d[l[1]] / k)
		else:
			for i in range(1, len(l)):
				ans += l[i] * d[l[i]]
	elif k < d[l[0]]:
		if len(l) == 1:
			ans += l[0] * ceil((d[l[0]] - k) / k)
		else:
			ans += l[0] * (d[l[0]] - k)
			for i in range(1, len(l)):
				ans += l[i] * d[l[i]]
	print(ans)
	t -= 1


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort()
	list1 = s[:k]
	list2 = s[k:]
	i = len(list2) - 1
	while i > 0 and list2[i] == list2[i - 1]:
		i -= 1
	if i == 0:
		list2 = list2[:math.ceil(len(list2) / k)]
	if k == 1:
		print(''.join(s))
	elif list1[0] == list1[-1]:
		print(list1[0] + ''.join(list2))
	else:
		print(list1[-1])


def minimize(n, k, string):
	slist = sorted(list(string))
	if slist[0] == slist[-1]:
		return slist[0] * -(-n // k)
	if slist[0] != slist[k - 1]:
		return slist[k - 1]
	if slist[k] != slist[0] and slist[k] == slist[-1]:
		return slist[0] + slist[k] * (-(-n // k) - 1)
	return slist[0] + ''.join(slist[k:])
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	string = input()
	print(minimize(n, k, string))


from math import ceil
t = int(input())
for test in range(t):
	(n, k) = map(int, input().split())
	s = sorted(input())
	if s[0] == s[-1]:
		print(''.join(s[:ceil(n / k)]))
	elif s[0] == s[k - 1]:
		c = 0
		for i in range(k, n):
			if s[i] != s[0]:
				break
			c += 1
		if s[k] == s[-1]:
			print(s[0] * ceil((k + c) / k) + s[k] * ceil((n - k - c) / k))
		else:
			print(s[0] + ''.join(s[k:]))
	else:
		print(s[k - 1])


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')

def main():
	for _ in range(N()):
		(n, k) = RL()
		s = list(input())
		s.sort()
		res = [[] for _ in range(k)]
		now = 0
		for i in range(len(s)):
			if i < k:
				res[i].append(s[i])
			elif s[i] != s[-1]:
				res[i % k].extend(s[i:])
				break
			else:
				res[now].append(s[i])
				if now + 1 == k or res[now][0] != res[now + 1][0]:
					now = 0
				else:
					now += 1
		print(''.join(max(res)))
main()


t = int(input())

def solve(l, k):
	res = []
	if l[0] != l[k - 1] or len(l) == k:
		return l[k - 1]
	if l[k] != l[-1]:
		return [l[0]] + l[k:]
	return [l[0]] + [l[k]] * ((len(l) - 1) // k)
for i in range(1, t + 1):
	(n, k) = list(map(int, input().split()))
	s = sorted(list(input()))
	print(''.join(solve(s, k)))


import math
t = int(input())

def als(A):
	if len(list(set(list(A)))) == 1:
		return True
	return False
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	s = input()
	ss = s
	ss = list(ss)
	ss.sort()
	ss = ''.join(ss)
	bb = list(set(list(ss)))
	bb = ''.join(bb)
	a = [0] * 26
	for x in s:
		a[ord(x) - 97] += 1
	tt = []
	idx = []
	for i in range(26):
		if a[i] != 0:
			tt.append(a[i])
			idx.append(i)
	if tt[0] < k:
		print(ss[k - 1])
	elif als(ss[k:]):
		res = ss[0]
		val = math.ceil(len(ss[k:]) / k) * ss[k]
		print(res + val)
	else:
		print(ss[0] + ss[k:])


import bisect
import math
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	ans = [[] for _ in range(k)]
	s = [i for i in input()]
	s.sort()
	i = 0
	while i != k:
		ans[i % k].append(s[i])
		i += 1
	if ans[0] != ans[-1]:
		print(''.join(ans[-1]))
	elif len(set(s[k:])) == 1:
		i = k
		while i != n:
			ans[i % k].append(s[i])
			i += 1
		print(''.join(max(ans)))
	else:
		for i in range(k, n):
			ans[-1].append(s[i])
		print(''.join(ans[-1]))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = str(input())
	s = sorted(s)
	if s[0] != s[k - 1]:
		print(s[k - 1])
		continue
	print(s[0], end='')
	if k <= n - 1 and s[k] != s[n - 1]:
		for i in range(k, n):
			print(s[i], end='')
	else:
		for i in range(0, (n - 1) // k):
			print(s[n - 1], end='')
	print()


import math
t = int(input())
for q in range(t):
	(n, k) = map(int, input().split())
	s = [x for x in input()]
	s.sort()
	l = []
	if k == 1:
		for x in s:
			print(x, end='')
		print()
		continue
	for x in range(k):
		l.append(s[x])
	s = s[k:]
	setl = list(set(l))
	sets = list(set(s))
	ll = len(setl)
	ls = len(sets)
	if ls < ll:
		print(l[-1])
		continue
	else:
		i = 0
		l.sort()
		if ll == 1 and ls > 1:
			for x in range(len(s)):
				l[-1] += s[x]
		elif ll == 1:
			l[0] += s[0] * max(1, math.ceil(len(s) / k))
		else:
			print(l[-1])
			continue
	l.sort()
	print(l[-1])


import math
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(input())
	l.sort()
	k = list(set(l))
	s = set()
	for i in range(m):
		s.add(l[i])
	if m == 1:
		print(''.join(l))
	elif len(s) == 1:
		k = set()
		for i in range(m, n):
			k.add(l[i])
		k = list(k)
		if len(k) == 1:
			print(l[0] + k[0] * math.ceil((len(l) - m) / m))
		else:
			print(l[0] + ''.join(l[m:]))
	else:
		print(l[m - 1])


from collections import deque, defaultdict
from math import ceil

def fun(arr):
	print(''.join(arr))
tc = int(input())
for zzz in range(tc):
	dic = defaultdict(int)
	(n, k) = map(int, input().split())
	strn = input()
	for ele in strn:
		dic[ele] += 1
	brr = [str(i) for i in dic.keys()]
	w = deque()
	brr.sort()
	arr = [[] for i in range(k)]
	for ele in brr:
		p = dic[ele]
		for i in range(p):
			w.append(ele)
	for i in range(k):
		arr[i].append(w.popleft())
	if dic[brr[0]] < k:
		fun(arr[k - 1])
	elif len(set(w)) > 1:
		while w:
			arr[k - 1].append(w.popleft())
		fun(arr[k - 1])
	else:
		r = 0
		while w:
			arr[r % k].append(w.popleft())
			r += 1
		fun(max(arr))


from sys import stdin
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = sorted([i for i in stdin.readline().strip()])
	if k == 1:
		print(*s, sep='')
		continue
	if s[0] != s[k - 1]:
		print(s[k - 1])
	else:
		cnt = 0
		st = set()
		for i in range(k, len(s)):
			cnt += 1
			st.add(s[i])
		print(s[0], end='')
		if len(st) == 1:
			print(s[k] * ((cnt + (k - 1)) // k))
		else:
			print(*s[k:], sep='')


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = sorted(list(input()))
	b = []
	s = set()
	if k == 1:
		print(''.join(a))
		continue
	elif k == n:
		print(max(a))
		continue
	for i in range(k):
		b.append([a[i]])
		s.add(a[i])
	if len(s) != 1:
		print(max(s))
	elif a[k] == a[-1]:
		for i in range(k, n):
			b[i % k].append(a[i])
		for i in range(k):
			b[i] = ''.join(b[i])
		print(max(b))
	else:
		print(b[0][0] + ''.join(a[k:]))


import sys
readline = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, readline().split())
	s = sorted(readline().rstrip())
	if n > k and s[0] == s[k - 1]:
		if s[k] != s[-1]:
			print(*s[k - 1:], sep='')
		else:
			print(*s[k - 1] + s[k] * ((n - k + k - 1) // k), sep='')
	else:
		print(s[k - 1])


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def get_str():
	return input().decode().strip()

def rint():
	return map(int, input().split())

def oint():
	return int(input())
t = oint()
for _ in range(t):
	(n, k) = rint()
	s = get_str()
	s = sorted(list(s))
	if s[0] != s[k - 1]:
		print(s[k - 1])
		continue
	ans = []
	ans += s[0]
	if len(set(s[k:])) == 1:
		ans += s[k] * ((n - k) // k)
		if (n - k) % k:
			ans += s[k]
		print(''.join(ans))
		continue
	ans += s[k:]
	print(''.join(ans))


import sys
input = sys.stdin.readline
Q = int(input())
Query = []
for _ in range(Q):
	(N, K) = map(int, input().split())
	S = list(input().rstrip())
	Query.append((N, K, S))
for (N, K, S) in Query:
	S.sort()
	ind = 0
	if S[0] != S[K - 1]:
		print(S[K - 1])
	else:
		ans = S[K - 1]
		if K == N:
			print(ans)
		elif S[K] == S[N - 1]:
			ans += S[K] * ((N - K + K - 1) // K)
			print(ans)
		else:
			ans += ''.join(S[K:])
			print(ans)


TestCase = int(input())
for TestCaseIteration in range(TestCase):
	(no_of_elements, no_of_sets) = map(int, input().split())
	String = input()
	Sorted_string = ''.join(sorted(String))
	if no_of_sets == no_of_elements or Sorted_string[0] != Sorted_string[no_of_sets - 1]:
		print(Sorted_string[no_of_sets - 1])
		continue
	if Sorted_string[no_of_sets] != Sorted_string[-1]:
		Answer = Sorted_string[0]
		Answer = Answer + Sorted_string[no_of_sets:]
		print(Answer)
		continue
	else:
		Answer = Sorted_string[0]
		c = (no_of_elements - 1) // no_of_sets
		Answer = Answer + Sorted_string[no_of_sets] * c
		print(Answer)


from collections import Counter

def mult_input():
	return map(int, input().split())

def list_input():
	return list(map(int, input().split()))
for nt in range(int(input())):
	(n, k) = mult_input()
	s = list(input())
	c = Counter(s)
	ans = [[] for i in range(k)]
	s.sort()
	if c[s[0]] < k:
		print(s[k - 1])
		continue
	elif c[s[0]] == k:
		j = 0
		for i in range(k):
			ans[i].append(s[j])
			j += 1
		if j == len(s):
			print(''.join(map(str, ans[0])))
			continue
		if s[j] != s[-1]:
			for i in range(j, n):
				ans[0].append(s[i])
			print(''.join(map(str, ans[0])))
		else:
			count = 0
			for i in range(j, n):
				ans[count % k].append(s[i])
				count += 1
			print(''.join(map(str, ans[0])))
	else:
		j = 0
		for i in range(k):
			ans[i % k].append(s[j])
			j += 1
		if j == len(s):
			print(''.join(map(str, ans[0])))
			continue
		if s[j] == s[-1]:
			count = 0
			for i in range(j, n):
				ans[count % k].append(s[i])
				count += 1
		else:
			for i in range(j, n):
				ans[0].append(s[i])
		print(''.join(map(str, ans[0])))


from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

def input():
	return sys.stdin.readline()

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
for _ in range(int(input())):
	(n, k) = mapi()
	a = list(input().strip())
	b = [[] for i in range(k)]
	c = [[] for i in range(k)]
	a.sort()
	if k == 1 or k == n:
		print(''.join(a[k - 1:]))
	else:
		for i in range(k):
			b[i].append(a[i])
			c[i].append(a[i])
		for i in range(k, n):
			b[0].append(a[i])
			c[i % k].append(a[i])
		b.sort()
		c.sort()
		one = ''.join(b[k - 1])
		two = ''.join(c[k - 1])
		print(min(one, two))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(input())
	l.sort()
	s = ''.join(l)
	competitors = k
	ind = 0
	ans = ''
	if k == 1:
		print(s)
		continue
	cnt = 0
	curr = ''
	for i in range(k):
		if s[i] != curr:
			curr = s[i]
			cnt = 1
		else:
			cnt += 1
	if cnt == k:
		ans = s[k - 1]
		s = s[k:]
		if len(s) == 0:
			print(ans)
			continue
		if s[0] == s[-1]:
			ans += s[0] * (len(s) // cnt)
			if len(s) % cnt != 0:
				ans += s[0]
		else:
			ans += s
		print(ans)
		continue
	print(s[k - 1])
	continue


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = list(input().rstrip())
	s.sort()
	if len(set(s[:k])) > 1:
		print(max(s[:k]))
		continue
	ss = s[k:]
	if len(set(ss)) == 1:
		print(s[0], *[ss[0]] * ((len(ss) - 1) // k + 1), sep='')
	else:
		print(s[0], *s[k:], sep='')


from sys import stdin, stdout
from math import *
for __ in range(int(input())):
	(n, m) = map(int, input().split())
	ar = list(input())
	ar.sort()
	ans = max(ar[:m])
	if ans != ar[0] or n == m:
		print(ans)
	else:
		if ar[-1] == ar[m]:
			ans += ar[m] * ceil((n - m) / m)
		else:
			ans += ''.join(ar[m:])
		print(ans)


import math
for case in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	s = input()
	series = [c for c in s]
	series.sort()
	i = 0
	temp = set()
	while i < k:
		temp.add(series[i])
		i += 1
	rem = set()
	while i < n:
		rem.add(series[i])
		i += 1
	if len(temp) > 1:
		temp = list(temp)
		temp.sort()
		print(temp[-1])
	else:
		temp = list(temp)
		temp.sort()
		if len(rem) > 1 or len(rem) == 0:
			print(temp[0] + ''.join(series[k:]))
		else:
			rem = list(rem)[0]
			l = math.ceil((n - k) / k)
			print(temp[0] + rem * l)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort()
	if len(set(s[:k])) > 1:
		print(s[k - 1])
	elif len(set(s[k:])) > 1:
		print(s[0] + ''.join(s[k:]))
	else:
		print(s[0] + s[-1] * ((n - 1) // k))


import math
t = int(input())
for i1 in range(t):
	(n, k) = list(map(int, input().split(' ')))
	s = input()
	s.strip()
	s = sorted(s)
	s = ''.join(s)
	temp = s[:k]
	if temp[-1] == temp[0]:
		temp1 = s[k:]
		if len(temp1) > 0:
			if temp1[-1] != temp1[0]:
				print(temp[0] + temp1)
			else:
				z1 = len(temp1)
				z = z1 // k
				if z1 % k != 0:
					z += 1
				z = temp1[0] * z
				print(temp[0] + z)
		else:
			print(temp[-1])
	else:
		print(temp[-1])


import math

def solve(k, left, forced=False):
	if len(left) == 0:
		return ''
	if forced:
		x = left[:k]
		if len(set(x)) == 1:
			return x[0] + solve(k, left[k:])
		else:
			return x[-1]
	else:
		if len(set(left)) == 1:
			return left[0] * math.ceil(len(left) / k)
		return ''.join(left)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort()
	print(solve(k, s, True))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = input()
	lis = list(s)
	lis.sort()
	s = ''.join(lis)
	sub = s[:k]
	if k == 1:
		print(s)
	elif len(s) == k:
		print(sub[-1])
	elif sub[0] == sub[-1]:
		s = s[k:]
		if s[0] == s[-1]:
			if len(s) % k == 0:
				print(sub[0] + s[0] * (len(s) // k))
			else:
				print(sub[0] + s[0] * (len(s) // k + 1))
		else:
			print(sub[0] + s)
	else:
		print(sub[-1])


import math
import collections
from sys import stdin, stdout
T = int(stdin.readline())
for _ in range(T):
	(n, k) = list(map(int, stdin.readline().split()))
	s = stdin.readline().strip('\n')
	d = {}
	for i in range(n):
		if s[i] not in d:
			d[s[i]] = 0
		d[s[i]] += 1
	s = ''.join(sorted(s))
	if k == 1:
		print(s)
		continue
	if len(d) == 1:
		rep = n // k + (1 if n % k != 0 else 0)
		print(s[0] * rep)
		continue
	ch = list(d.keys())
	ch.sort()
	if k > d[ch[0]]:
		print(s[k - 1])
		continue
	if d[ch[0]] == k:
		del d[ch[0]]
	else:
		d[ch[0]] = d[ch[0]] - k
	if len(d) > 1:
		print(ch[0] + s[k:])
	else:
		c = list(d.keys())[0]
		rep = d[c] // k + (1 if d[c] % k != 0 else 0)
		print(ch[0] + c * rep)


import sys

def readStr():
	return sys.stdin.readline().rstrip()

def readInts():
	return list(map(int, readStr().split(' ')))

def main(n, k, a):
	s = ''.join(sorted(a))
	if k == 1:
		return s
	if s[k - 1] != s[0]:
		return s[k - 1]
	if k == n:
		return s[n - 1]
	if s[k] != s[n - 1]:
		return s[k - 1:]
	return s[::k]
(t,) = readInts()
for _ in range(t):
	(n, k) = readInts()
	a = readStr()
	m = main(n, k, a)
	print(m)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	if k == 1:
		print(*sorted(input()), sep='')
		continue
	cnt = [0] * 26
	for el in input():
		cnt[ord(el) - ord('a')] += 1
	done = False
	for i in range(26):
		if cnt[i] >= k:
			cnt[i] -= k
			ans = chr(i + ord('a'))
			pp = 0
			for el in cnt:
				if el:
					pp += 1
			if pp == 1:
				for i in range(26):
					if cnt[i]:
						ans += chr(i + ord('a')) * (cnt[i] // k + (cnt[i] % k != 0))
						print(ans)
						done = True
						break
			else:
				for i in range(26):
					ans += chr(i + ord('a')) * cnt[i]
				print(ans)
				done = True
			break
		elif cnt[i] > 0:
			k -= cnt[i]
			cnt[i] = 0
			break
	if not done:
		for i in range(26):
			if cnt[i] >= k:
				print(chr(i + ord('a')))
				break
			else:
				k -= cnt[i]


from math import *
t = int(input())
while t > 0:
	(n, k) = [int(x) for x in input().split()]
	s1 = input()
	s = sorted(s1)
	flag = 0
	if k == 1:
		flag = -1
	for i in range(1, k):
		if s[i] != s[i - 1]:
			flag = 1
			break
	ans = ''
	if flag == -1:
		for i in s:
			ans += i
	elif flag == 1:
		ans = s[k - 1]
	else:
		ans = s[k - 1]
		s = s[k:]
		if len(s) > 0:
			for i in range(1, len(s)):
				if s[i] != s[i - 1]:
					flag = 1
					break
			if flag == 1:
				for i in s:
					ans += i
			else:
				for i in range(0, len(s), k):
					ans += s[i]
		else:
			for i in s:
				ans += i
	print(ans)
	t -= 1


import os
import sys
from io import BytesIO, IOBase

def solution(s, n, k):
	s = ''.join(sorted(s))
	if s[0] != s[k - 1]:
		write(s[k - 1])
		return
	if s[0] == s[k - 1]:
		if k < n and s[k] == s[n - 1]:
			res = s[0]
			for _ in range((n - k) // k):
				res += s[k]
			if (n - k) % k:
				res += s[k]
			write(res)
		else:
			write(s[0] + s[k:])

def main():
	for _ in range(r_int()):
		(n, k) = r_array()
		s = input()
		solution(s, n, k)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def write(*args, end='\n'):
	for x in args[:-1]:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(str(args[-1]))
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())
main()


import math
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	s = input()
	temp = sorted(s)
	a = ''
	for i in temp:
		a += i
	x = a[0]
	flag = 0
	flag1 = 0
	for i in range(0, k):
		if a[i] != x:
			flag = 1
			break
	if flag == 1:
		print(a[k - 1])
	else:
		s1 = ''
		s1 = a[0]
		if n == k:
			p = ''
		else:
			p = a[k]
		for i in range(k, n):
			if a[i] != p:
				flag1 = 1
				break
		if flag1 == 1:
			for i in range(k, n):
				s1 = s1 + a[i]
			print(s1)
		else:
			r = math.ceil((n - k) / k)
			for i in range(r):
				s1 = s1 + a[k]
			print(s1)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = sorted(input().strip())
	x = n % k == 0
	y = all((s[0] == i for i in s[:k]))
	z = all((s[k] == i for i in s[k:]))
	if y and z:
		print(''.join(s[::k]))
	else:
		print(max(''.join(s[0:1] + s[k:]), s[k - 1]))


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(input())
	a.sort()
	if a[k - 1] != a[0] or k == n:
		print(a[k - 1])
	else:
		b = a[k:]
		if b.count(b[0]) == n - k:
			c = n // k
			if n % k == 0:
				c -= 1
			print(a[0] + b[0] * c)
		else:
			print(a[0] + ''.join(b))


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def solve():
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort(reverse=True)
	ans = []
	c = s[-1]
	d = c
	for i in range(k):
		d = s.pop()
	if c != d or len(s) == 0:
		print(d)
		return
	ans.append(c)
	if s[0] == s[-1]:
		ans.extend([s[0]] * -(-len(s) // k))
	else:
		ans.extend(list(reversed(s)))
	print(''.join(ans))
t = int(input())
for i in range(t):
	solve()


numcases = int(input())
for i in range(numcases):
	(n, k) = map(int, input().split())
	s = sorted(input())
	unique1 = []
	unique2 = []
	ans = 0
	for i in range(k):
		if s[i] not in unique1:
			unique1.append(s[i])
	for i in range(k, n):
		if s[i] not in unique2:
			unique2.append(s[i])
	if len(unique1) > 1 or len(unique2) == 0:
		print(s[k - 1])
	elif len(unique2) > 1:
		ans = s[0]
		for i in range(k, n):
			ans = ans + s[i]
		print(ans)
	else:
		remainder = n - k
		if remainder % k == 0:
			ans = s[0] + s[k] * (remainder // k)
		else:
			ans = s[0] + s[k] * (remainder // k + 1)
		print(ans)


import collections
t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	s = input()
	ctr = collections.Counter(list(s))
	chars = list(ctr.keys())
	chars.sort()
	last_idx = len(chars)
	for i in range(len(chars)):
		if ctr[chars[i]] % k != 0:
			last_idx = i
			break
	if ctr[chars[0]] < k:
		cnt = 0
		for char in chars:
			if cnt + ctr[char] >= k:
				ans = char
				break
			else:
				cnt += ctr[char]
	elif ctr[chars[0]] > k:
		if len(chars) == 1:
			ans = chars[0] * ((ctr[chars[0]] + k - 1) // k)
		else:
			ans = chars[0] * (ctr[chars[0]] - k + 1)
			for char in chars[1:]:
				ans += char * ctr[char]
	elif len(chars) == 1:
		ans = chars[0]
	elif len(chars) == 2:
		ans = chars[0] + chars[1] * ((ctr[chars[1]] + k - 1) // k)
	else:
		ans = chars[0]
		for char in chars[1:]:
			ans += char * ctr[char]
	print(ans)
	t -= 1


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = input()
	p = list(s)
	p.sort()
	ans = ''
	if p[0] != p[k - 1]:
		print(p[k - 1])
	elif n == k:
		print(p[n - 1])
	else:
		if p[k] == p[n - 1]:
			ans += p[0]
			for i in range((n - k) // k):
				ans += p[k]
			if (n - k) % k != 0:
				ans += p[k]
		else:
			ans += p[0]
			for i in range(k, n):
				ans += p[i]
		print(ans)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
from math import log, sqrt, factorial
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey, reverse=True)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def ceil(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	for _ in range(ii()):
		(n, k) = mi()
		s = si()
		f = [0] * 26
		ans = ''
		for i in range(n):
			f[abd[s[i]]] += 1
		pos = -1
		cnt = 0
		c = 0
		for i in range(26):
			if f[i] != 0:
				if cnt + f[i] <= k:
					pos = i
					c += 1
					cnt += f[i]
					f[i] = 0
				else:
					if k - cnt != 0:
						c += 1
						pos = i
						f[i] -= k - cnt
					break
		if c != 1:
			print(abc[pos])
			continue
		else:
			ans += abc[pos]
			flag = 0
			for i in range(26):
				if f[i]:
					for j in range(i + 1, 26):
						if f[j]:
							flag = 1
							break
					if flag == 1:
						ans += abc[i] * f[i]
					else:
						ans += abc[i] * (f[i] // k)
						if f[i] % k:
							ans += abc[i]
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from math import ceil
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(input())
	a.sort()
	minCharacter = a[0]
	minCount = 0
	for i in range(n):
		if a[i] == minCharacter:
			minCount += 1
		else:
			break
	if minCount < k:
		print(a[k - 1])
	elif minCount == n:
		print(''.join(a[0:ceil(n / k)]))
	else:
		nextMinCharacter = a[k]
		isAllSame = True
		for i in range(minCount, n):
			if a[i] != nextMinCharacter:
				isAllSame = False
				break
		if isAllSame:
			print(''.join(a[0] + nextMinCharacter * ceil((n - k) / k)))
		else:
			print(''.join([a[0]] + a[k:]))


import sys
from collections import defaultdict, deque
import math
import heapq
t = int(sys.stdin.readline())
for _ in range(t):
	(n, k) = map(int, sys.stdin.readline().split())
	s = list(sys.stdin.readline()[:-1])
	arr = [0] * 26
	s.sort()
	ans = []
	tar = s[0]
	lim = 0
	for i in range(k):
		if s[i] == tar:
			lim = i
		ans.append([s[i]])
	for i in range(k, n):
		arr[ord(s[i]) - 97] += 1
	count = 0
	tar = 0
	for i in range(26):
		if arr[i] != 0:
			tar = i
			count += 1
	if count == 1:
		i = 0
		while arr[tar] > 0:
			ans[i].append(chr(tar + 97))
			arr[tar] -= 1
			i += 1
			i %= lim + 1
	else:
		for i in range(26):
			if arr[i] != 0:
				while arr[i] != 0:
					ans[0].append(chr(i + 97))
					arr[i] -= 1
	if lim + 1 == k:
		print(''.join((x for x in ans[0])))
	else:
		print(''.join((x for x in ans[-1])))


from math import ceil

def solve(chars, k):
	if chars[0] != chars[k - 1]:
		return chars[k - 1]
	if chars[0] == chars[-1]:
		return chars[0] * ceil(len(chars) / k)
	solutions = chars[:k]
	if chars[k] == chars[-1]:
		return solutions[0] + chars[k] * ceil((len(chars) - k) / k)
	else:
		return solutions[0] + ''.join(chars[k:])
test_cases = int(input())
for _ in range(test_cases):
	((n, k), chars) = (map(int, input().split()), input())
	print(solve(sorted(chars), k))


t = int(input())
while t:
	t -= 1
	(n, k) = [int(i) for i in input().split()]
	a = [i for i in input()]
	a.sort()
	ans = []
	for i in range(k):
		ans.append(a[i])
	if len(set(ans)) == 1:
		for i in range(k):
			ans[i] = list(ans[i])
		if len(set(a[k:])) == 1:
			for i in range(k, n):
				ans[i % k].append(a[i])
		else:
			ans[0].extend(a[k:])
		print(''.join(max(ans)))
	else:
		print(''.join(max(ans)))


import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
from itertools import islice, cycle

def go():
	(n, k) = map(int, input().split())
	s = input()
	ss = sorted(s)
	if ss[0] != ss[k - 1] or k == n:
		return ss[k - 1]
	r = n - k
	if ss[k] == ss[n - 1]:
		return ss[0] + ss[k] * ((r + k - 1) // k)
	else:
		return ss[0] + ''.join(ss[k:])
t = int(input())
ans = []
for _ in range(t):
	ans.append(str(go()))
print('\n'.join(ans))


t = int(input())
ans = []
for _ in range(t):
	(n, k) = map(int, input().split())
	s = input()
	s = sorted(s)
	if k == 1:
		ans.append(''.join(s))
		continue
	if n == k:
		ans.append(s[k - 1])
		continue
	if s[k - 1] != s[0]:
		ans.append(s[k - 1])
		continue
	elif len(set(s[k:])) > 1:
		ans.append(s[0] + ''.join(s[k:]))
		continue
	else:
		r = n - k
		r = (n - k) // k + (1 if (n - k) % k else 0)
		ans.append(s[0] + r * s[k])
for aa in ans:
	print(aa)


from sys import stdin, stdout
from collections import Counter
t = int(stdin.readline().strip())
for _ in range(t):
	(n, k) = stdin.readline().strip().split(' ')
	(n, k) = (int(n), int(k))
	s = sorted(stdin.readline().strip())
	s = ''.join(s)
	ans = ''
	if s[0] == s[-1]:
		ans += s[0] * (len(s) // k)
		if len(s) % k != 0:
			ans += s[0]
	elif s[0] != s[k - 1]:
		ans = s[k - 1]
	elif s[0] == s[k - 1]:
		ans += s[0]
		s = s[k:]
		if s[0] == s[-1]:
			ans += s[0] * (len(s) // k)
			if len(s) % k != 0:
				ans += s[0]
		else:
			ans += s
	stdout.write(ans + '\n')


from fractions import Fraction
import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
for _ in range(iinput()):
	(n, k) = rinput()
	s = ''.join(sorted(input()))
	if s[0] != s[k - 1]:
		print(s[k - 1])
		continue
	ans = s[0]
	if k != n and s[k] != s[n - 1]:
		ans += s[k:]
	else:
		ans += s[n - 1] * ((n - 1) // k)
	print(ans)


import sys
import math
from collections import defaultdict, deque
import operator
input = sys.stdin.readline

def inar():
	return [int(el) for el in input().split()]

def main():
	t = int(input())
	for _ in range(t):
		(n, k) = inar()
		st = list(input().strip())
		st.sort()
		ans = [''] * k
		for i in range(k):
			ans[i] += st[i]
		dic = defaultdict(int)
		for i in range(k, n):
			dic[st[i]] += 1
		dic = dict(sorted(dic.items(), key=operator.itemgetter(0)))
		ke = list(dic.keys())
		if ans[0] == ans[-1]:
			if len(ke) == 1:
				all = dic[ke[0]] // k
				for i in range(k):
					ans[i] += ke[0] * all
				rem = dic[ke[0]] % k
				i = 0
				while rem:
					ans[i] += ke[0]
					rem -= 1
					i += 1
			else:
				for i in range(len(ke)):
					ans[0] += ke[i] * dic[ke[i]]
		else:
			for i in range(len(ke)):
				ans[0] += ke[i] * dic[ke[i]]
		print(max(ans))
main()


import sys, math
from sys import stdin, stdout

def R():
	return map(int, stdin.readline().strip().split())
ans = []
for h in range(int(stdin.readline().strip())):
	(n, k) = R()
	s = list(stdin.readline().strip())
	s.sort()
	s = ''.join(s)
	if k == 1:
		ans.append(s)
		continue
	p = ''
	temp = str(s)
	dp = []
	c = 1
	for i in range(len(s) - 1):
		if s[i] != s[i + 1]:
			dp.append((c, s[i]))
			c = 1
		else:
			c += 1
	dp.append((c, s[-1]))
	indi = 0
	if dp[0][0] == k:
		p += dp[0][1]
		indi += k
	s = s[indi:]
	if len(s) == 0:
		ans.append(p)
		continue
	dp = []
	c = 1
	for i in range(len(s) - 1):
		if s[i] != s[i + 1]:
			dp.append((c, s[i]))
			c = 1
		else:
			c += 1
	dp.append((c, s[-1]))
	if len(dp) == 1:
		ans.append(p + s[0] * math.ceil(dp[0][0] / k))
	else:
		ans.append(max(temp[0] + temp[1 + k - 1:], max(list(temp[1:1 + k - 1]))))
stdout.write('\n'.join(ans))


from collections import defaultdict, deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10 ** 5)
input = sys.stdin.readline
sqrt = math.sqrt

def LI():
	return list(map(int, input().split()))

def LF():
	return list(map(float, input().split()))

def LI_():
	return list(map(lambda x: int(x) - 1, input().split()))

def II():
	return int(input())

def IF():
	return float(input())

def S():
	return input().rstrip()

def LS():
	return S().split()

def IR(n):
	return [II() for _ in range(n)]

def LIR(n):
	return [LI() for _ in range(n)]

def FR(n):
	return [IF() for _ in range(n)]

def LFR(n):
	return [LI() for _ in range(n)]

def LIR_(n):
	return [LI_() for _ in range(n)]

def SR(n):
	return [S() for _ in range(n)]

def LSR(n):
	return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

def solve():
	for _ in range(II()):
		(n, k) = LI()
		s = list(S())
		s.sort()
		if len(set(s[:k])) == 1 and len(set(s[k:])) == 1:
			print(s[0] + s[k] * ((n - k - 1) // k + 1))
			continue
		ans = [[s[i]] for i in range(k)]
		for i in range(k, n):
			ans[0].append(s[i])
		ans.sort()
		print(''.join(ans[-1]))
	return
solve()


from collections import Counter
from math import ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort()
	dct = Counter(s)
	x1 = dct[s[0]]
	if k > x1:
		print(s[k - 1])
	elif k < x1:
		if x1 != n:
			print(s[0] + ''.join(s[k:]))
		else:
			print(s[0] * ceil(x1 / k))
	else:
		ls = len(dct.most_common())
		if ls == 1:
			print(s[0] * ceil(x1 / k))
		elif ls == 2:
			print(s[0] + s[x1] * ceil(dct[s[x1]] / k))
		else:
			print(s[0] + ''.join(s[x1:]))


import sys
input = sys.stdin.readline
import heapq
t = int(input())
for tests in range(t):
	(n, k) = map(int, input().split())
	S = sorted(input().strip())
	ANS = [[S[i]] for i in range(k)]
	ANS[0] += S[k:]
	if len(ANS) == 0:
		print(''.join(ANS[0]))
	elif max(ANS) != ANS[0]:
		print(''.join(max(ANS)))
	else:
		H = ANS[1:]
		heapq.heapify(H)
		A = ANS[0]
		while H:
			x = heapq.heappop(H)
			y = A.pop()
			x.append(y)
			if A >= x:
				heapq.heappush(H, x)
			else:
				A.append(y)
				break
		print(''.join(A))


from sys import stdin, stdout
T = int(stdin.readline())
for i in range(T):
	[N, K] = [int(x) for x in stdin.readline().split()]
	S = [x for x in stdin.readline().strip()]
	S.sort()
	if K == N:
		res = S[-1]
	elif S[0] == S[-1]:
		res = S[0] * (N // K + (0 if N % K == 0 else 1))
	elif S[0] != S[K - 1]:
		res = S[K - 1]
	elif S[K] == S[-1]:
		res = S[0] + S[K] * ((N - K) // K + (0 if N % K == 0 else 1))
	else:
		res = S[K - 1:]
	stdout.write(''.join(res) + '\n')


from collections import deque
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = list(input()[:-1])
	ans = []
	q = deque(sorted(s))
	set_ = set()
	for _ in range(k):
		v = q.popleft()
		set_.add(v)
		last = v
	ans.append(last)
	if len(set_) >= 2:
		print(''.join(ans))
	else:
		li = list(q)
		if len(set(li)) != 1:
			print(''.join(ans + li))
		else:
			print(''.join(ans) + -(-len(li) // k) * li[0])


from collections import defaultdict as dc
from heapq import *
import math
import bisect
import sys
from collections import deque as dq
from heapq import heapify, heappush, heappop
mod = 10 ** 9 + 7

def inp():
	p = int(input())
	return p

def line():
	p = list(map(int, input().split()))
	return p

def read_mat():
	n = inp()
	a = []
	for i in range(n):
		a.append(line())
	return a

def digit(n):
	s = str(n)
	p = 0
	for i in s:
		p += int(i) ** 2
	return p

def solve(s, n, k):
	p = ['' for i in range(k)]
	s = sorted(s)
	q = ''.join(s)
	z = len(set(s))
	q = ''.join(s)
	z = 0
	for i in range(k):
		p[i] = s[z]
		z += 1
	ans = max(p)
	if z == n:
		return ans
	if s[0] != s[z - 1]:
		return ans
	l = min(p)
	ans = l + q[z:]
	while z < n:
		for i in range(k):
			p[i] += q[z]
			z += 1
			if z == n:
				break
	return min(ans, max(p))
for test in range(inp()):
	(n, k) = line()
	s = str(input())
	l = solve(s, n, k)
	print(l)


from math import sqrt
from collections import defaultdict
from string import ascii_lowercase
it = lambda : list(map(int, input().strip().split()))
INF = float('inf')

def solve():
	(_, k) = it()
	S = input().strip()
	if k == 1:
		return ''.join(sorted(S))
	C = defaultdict(int)
	for ch in S:
		C[ch] += 1
	i = 0
	while i <= 25 and C[chr(ord('a') + i)] == 0:
		i += 1
	if C[chr(ord('a') + i)] < k:
		t = 0
		while t < k:
			t += C[chr(ord('a') + i)]
			i += 1
		return chr(ord('a') + i - 1)
	A = defaultdict(int)
	A[chr(ord('a') + i)] += 1
	C[chr(ord('a') + i)] -= k
	c = 0
	for j in range(i, 26):
		if C[chr(ord('a') + j)] > 0:
			c += 1
	if c <= 1:
		while i <= 25:
			if C[chr(ord('a') + i)] > 0:
				A[chr(ord('a') + i)] += (C[chr(ord('a') + i)] - 1) // k + 1
			i += 1
	else:
		while i <= 25:
			A[chr(ord('a') + i)] += C[chr(ord('a') + i)]
			i += 1
	return ''.join((ch * A[ch] for ch in ascii_lowercase))
T = int(input())
for _ in range(T):
	print(solve())


import os
import sys
from io import BytesIO, IOBase

def iin():
	return int(input())

def lin():
	return list(map(int, input().split()))

def main():
	T = iin()
	while T:
		T -= 1
		(n, k) = lin()
		k1 = k
		s = input()
		a1 = [0] * 26
		for i in s:
			a1[ord(i) - 97] += 1
		ans = []
		rn = n
		d1 = 0
		for i in range(26):
			if a1[i]:
				if ans:
					if rn == a1[i] and d1 == 0:
						ans.append(chr(i + 97) * ((a1[i] + k1 - 1) // k1))
					else:
						ans.append(chr(i + 97) * a1[i])
						d1 = 1
				elif a1[i] >= k:
					if rn < n:
						ans.append(chr(i + 97))
						break
					if rn == a1[i]:
						ans.append(chr(i + 97) * ((a1[i] + k - 1) // k))
					else:
						ans.append(chr(i + 97) * (a1[i] - k + 1))
						if a1[i] - k + 1 > 1:
							d1 = 1
					k = 0
				else:
					k -= a1[i]
			rn -= a1[i]
		print(''.join(ans))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


T = int(input())
for t in range(T):
	(N, K) = map(int, input().split())
	A = input()
	A = list(A)
	A.sort()
	mp = {}
	lis = []
	for a in A:
		if a in mp:
			mp[a] += 1
		else:
			mp[a] = 1
			lis.append(a)
	if mp[A[0]] < K:
		print(A[K - 1])
	elif len(lis) == 1:
		ans = ''
		for i in range(0, N, K):
			ans += A[i]
		print(ans)
	elif len(lis) == 2 and K == mp[A[0]]:
		ans = A[0]
		for i in range(K, N, K):
			ans += A[i]
		print(ans)
	else:
		ans = A[0]
		for i in range(K, N):
			ans += A[i]
		print(ans)


T = int(input())
for _ in range(T):
	(N, K) = map(int, input().split())
	S = input()
	ss = sorted(S)
	if K == 1:
		print(''.join(ss))
		continue
	if ss[0] != ss[K - 1]:
		print(ss[K - 1])
		continue
	if N > K and ss[K] == ss[-1]:
		l = 0 - -(N - K) // K
		print(ss[0] + ss[K] * l)
		continue
	print(''.join(ss[K - 1:]))


T = int(input())
for _ in range(0, T):
	(n, k) = map(int, input().split())
	s = input()
	L = []
	for i in range(0, len(s)):
		L.append(s[i])
	L.sort()
	ct = []
	c = 1
	for i in range(1, len(L)):
		if L[i] == L[i - 1]:
			c += 1
		else:
			ct.append((L[i - 1], c))
			c = 1
	ct.append((L[-1], c))
	if len(set(L)) > 2:
		if ct[0][1] < k:
			print(L[k - 1])
		elif ct[0][1] == k:
			ans = ct[0][0]
			for i in range(1, len(ct)):
				ans = ans + ct[i][0] * ct[i][1]
			print(ans)
		else:
			ans = ct[0][0] * (ct[0][1] - k + 1)
			for i in range(1, len(ct)):
				ans = ans + ct[i][0] * ct[i][1]
			print(ans)
	elif len(set(L)) == 2:
		if ct[0][1] < k:
			print(L[k - 1])
		elif ct[0][1] == k:
			ans = ct[0][0]
			if ct[1][1] < k:
				ans += ct[1][0]
				print(ans)
			else:
				tt = ct[1][1] // k
				tt2 = ct[1][1] % k
				ans = ans + ct[1][0] * tt
				if ct[1][1] % k != 0:
					ans = ans + ct[1][0]
				print(ans)
		else:
			ans = ct[0][0] * (ct[0][1] - k + 1)
			for i in range(1, len(ct)):
				ans = ans + ct[i][0] * ct[i][1]
			print(ans)
	else:
		ans = ''
		tt = ct[0][1] // k
		tt2 = ct[0][1] % k
		ans = ans + ct[0][0] * tt
		if ct[0][1] % k != 0:
			ans = ans + ct[0][0]
		print(ans)


def solve():
	(n, k) = map(int, input().split(' '))
	s = input()
	sor = sorted(s)
	if n == k:
		print(sor[-1])
		return
	if sor[k - 1] != sor[0]:
		print(sor[k - 1])
		return
	if sor[k] != sor[n - 1]:
		print(sor[0] + ''.join(sor[k:n]))
	else:
		result = sor[0]
		for i in range(0, (n - k + k - 1) // k):
			result += sor[n - 1]
		print(result)
t = int(input())
for i in range(t):
	solve()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = list(str(input()))
	s.sort()
	if k == 1:
		print(''.join(s))
		continue
	if k == n:
		print(s[-1])
		continue
	if s[0] != s[k - 1]:
		print(s[k - 1])
		continue
	d = {}
	for i in range(k, n):
		if s[i] not in d:
			d[s[i]] = 1
		else:
			d[s[i]] += 1
	if len(d) == 1:
		v = list(d.values())
		(q, r) = divmod(v[0], k)
		if r == 0:
			ans = s[0] + s[-1] * q
		else:
			ans = s[0] + s[-1] * (q + 1)
		print(ans)
	else:
		ans = [s[0]]
		for (k, v) in d.items():
			ans += [k] * v
		print(''.join(ans))


import sys
import math
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort()
	if len(set(s)) == 1:
		print(math.ceil(s.count(s[0]) / k) * s[0])
		continue
	if s.count(s[0]) > k:
		print(''.join(s[k - 1:]))
	elif s.count(s[0]) == k:
		t = list(s[0]) + s[k:]
		if len(set(s)) == 2:
			t = s[0] + math.ceil(s.count(s[-1]) / k) * s[-1]
		print(''.join(t))
	else:
		print(''.join(s[k - 1]))


t = int(input())
from collections import Counter
for i in range(t):
	(n, k) = map(int, input().split())
	s = input()
	l = list(s)
	l.sort()
	c = Counter(l)
	l1 = [''] * k
	l2 = [1] * k
	for j in range(k):
		l1[j] += l[j]
		c[l[j]] -= 1
	j += 1
	l1.sort()
	if l1[0] != l1[-1]:
		print(l1[-1])
	else:
		p = 0
		l3 = []
		for j in c:
			if c[j] != 0:
				l3.append(j)
		l3.sort()
		j = 0
		if len(l3) != 0:
			while 1:
				if j == len(l3) - 1:
					break
				x = l3[j]
				while c[x] != 0:
					l1[0] += x
					c[x] -= 1
				j += 1
			if len(l1[0]) == 1:
				p = 0
				z = 1
				while c[l3[-1]] > 0:
					l1[p] += l3[-1]
					c[l3[-1]] -= 1
					if p < len(l1) - 1:
						if len(l1[p + 1]) == z:
							p += 1
						else:
							z += 1
							p = 0
					else:
						z += 1
						p = 0
			else:
				x = l3[-1]
				while c[x] != 0:
					l1[0] += x
					c[x] -= 1
		print(l1[0])


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
for _ in range(INT()):
	(N, K) = MAP()
	S = list(input())
	if K == 1:
		S.sort()
		ans = ''.join(S)
		print(ans)
		continue
	S.sort(reverse=1)
	mx = S[0]
	A = [[] for i in range(K)]
	for i in range(K):
		A[i].append(S.pop())
	if A[0] < A[-1]:
		ans = ''.join(A[-1])
	elif S and S[-1] == mx:
		i = 0
		while S:
			A[i].append(S.pop())
			i = (i + 1) % K
		ans = ''.join(A[0])
	else:
		A[-1] += sorted(S)
		ans = ''.join(A[-1])
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(input())
	a.sort()
	s = set(a)
	if len(s) == 1:
		print(a[0] * ((n + k - 1) // k))
	else:
		ans = ''
		si = 0
		while si + k <= n and len(set(a[si:si + k])) == 1:
			ans += a[si]
			si += k
		if si < n:
			ans += a[min(n - 1, si + k - 1)]
		ans2 = a[k - 1]
		ans3 = a[0] + ''.join(a[k:])
		print(min(ans, max(ans2, ans3)))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = list(input())
	s = sorted(s)
	if k == 1:
		print(''.join(map(str, s)))
	elif len(set(s)) == 1:
		print(s[0] * ((n + k - 1) // k))
	elif len(set(s[:k])) != 1:
		print(s[k - 1])
	else:
		tmp = s[0]
		s = s[k:]
		if len(set(s)) != 1:
			print(tmp + ''.join(map(str, s)))
		else:
			print(tmp + s[0] * ((n - k + k - 1) // k))


from collections import Counter
import math
mod = 10 ** 9 + 7
for i in range(int(input())):
	(n, k) = map(int, input().split())
	s = input()
	s = sorted(s)
	s.append(' ')
	if len(s) == 1:
		print(s[0])
	elif s[0] != s[k - 1]:
		print(s[k - 1])
	elif s[k] == s[n - 1]:
		ans = s[0]
		d = (n - k) // k
		for i in range(d):
			ans += s[k]
		if (n - k) % k != 0:
			ans += s[k]
		print(ans)
	else:
		ans = s[0]
		for i in range(k, n):
			ans += s[i]
		print(ans)


T = int(input())
for t in range(T):
	(N, K) = map(int, input().split())
	s = sorted(input())
	if len(set(s[:K])) > 1:
		print(s[K - 1])
	else:
		if len(set(s[K:])) > 1:
			for c in s[K:]:
				s[0] += c
		else:
			for i in range(K, N):
				s[i % K] += s[i]
		print(max(s[:K]))


import sys
from collections import defaultdict, Counter
import math
input = sys.stdin.readline

def print_result(l):
	return print(' '.join(map(str, l)))

def timer(function):
	import time

	def wrapper(*args, **kwargs):
		t1 = time.time()
		val = function()
		t2 = time.time()
		print('Executed \\{}\\ in {:.2f} seconds.'.format(function.__name__, t2 - t1))
		return val
	return wrapper

def solve():
	(n, k) = map(int, input().split())
	s = input()
	if k == 1:
		print(''.join(sorted(s[:-1])))
	else:
		s = s[:-1]
		l = sorted(s)
		freq = Counter(s)
		characters = sorted(list(set(s)))
		if len(freq.keys()) >= 3:
			if freq[characters[0]] < k:
				print(l[k - 1])
			else:
				prefix = characters[0] * (freq[characters[0]] - k + 1)
				suffix = ''.join([characters[i] * freq[characters[i]] for i in range(1, len(characters))])
				print(prefix + suffix)
		elif len(freq.keys()) == 2:
			if freq[characters[0]] < k:
				print(l[k - 1])
			else:
				if freq[characters[0]] == k:
					m1 = int(math.ceil(freq[characters[0]] / k))
					m2 = int(math.ceil(freq[characters[1]] / k))
					result = characters[0] * m1 + characters[1] * m2
				else:
					m1 = characters[0] * (freq[characters[0]] - k + 1)
					m2 = characters[1] * freq[characters[1]]
					result = m1 + m2
				print(result)
		else:
			m1 = int(math.ceil(freq[characters[0]] / k))
			print(characters[0] * m1)
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	(n, k) = [int(c) for c in input().split()]
	s = [i for i in input()]
	s.sort()
	s += ['0'] * 10
	if s[0] != s[k - 1]:
		print(s[k - 1])
	else:
		print(s[k - 1], end='')
		if s[k] != s[n - 1]:
			print(*s[k:n], sep='')
		else:
			ans = s[n - 1] * ((n - 1) // k)
			print(ans, sep='')


import math
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().rstrip().split(' ')))
	s = input().rstrip()
	s = ''.join(sorted(s))
	if s[0] == s[k - 1]:
		if n == k:
			ans = s[0]
		elif s[k] == s[-1]:
			ans = s[0] + s[k] * math.ceil((n - k) / k)
		else:
			ans = s[0] + s[k:]
	else:
		ans = s[k - 1]
	print(ans)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input().strip()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())

def from_file(f):
	return f.readline

def count_from_index(s, start):
	if start >= len(s):
		return 0
	first = s[start]
	index = start
	first_count = 0
	while index < len(s) and s[index] == first:
		first_count += 1
		index += 1
	return first_count

def solve(n, k, s):
	s.sort()
	first = s[0]
	first_count = count_from_index(s, 0)
	has_others = first_count < len(s)
	if first_count < k:
		return s[k - 1]
	if first_count > k and has_others:
		res = [first]
		for i in range(k, len(s)):
			res.append(s[i])
		return ''.join(res)
	if first_count > k:
		c = len(s) // k
		if len(s) % k != 0:
			c += 1
		res = [first] * c
		return ''.join(res)
	if first_count == k:
		if len(s) == k:
			return first
		second = s[k]
		second_count = count_from_index(s, k)
		has_others = first_count + second_count < len(s)
		if has_others:
			res = [first] + s[k:]
			return ''.join(res)
		else:
			c = second_count // k
			if second_count % k != 0:
				c += 1
			res = [first] + [second] * c
			return ''.join(res)
t = inp()
for _ in range(t):
	(n, k) = invr()
	s = insr()
	res = solve(n, k, s)
	print(res)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = input()
	s = list(s)
	s.sort()
	small = s[0]
	ans = ''
	rest = []
	if s[0] == s[-1]:
		l = len(s)
		ans += math.ceil(l / k) * s[0]
	else:
		t = s.count(small) // k
		rest = s[k:]
		if t > 0:
			ans += small
			if rest[0] == rest[-1]:
				l = len(rest)
				ans += math.ceil(l / k) * rest[0]
			else:
				ans += ''.join(rest)
		else:
			ans = s[k - 1]
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = ''.join(sorted(input()))
	if a[0] == a[m - 1]:
		if m < n and a[m] == a[-1]:
			print(a[0] + a[m] * ((n - 1) // m))
		else:
			print(a[m - 1:])
	else:
		print(a[m - 1])


t = int(input())
i = 0
while i < t:
	(n, m) = map(int, input().split())
	rama = []
	string = input()
	for j in string:
		rama.append(ord(j))
	rama.sort()
	m = m - 1
	lax = []
	if rama[m] == rama[0]:
		if m + 1 != n and rama[m + 1] == rama[-1]:
			lax.append(chr(rama[0]))
			c = (len(rama) - 1 - m) // (m + 1)
			d = (len(rama) - 1 - m) % (m + 1)
			lax.append(chr(rama[m + 1]) * (c if d == 0 else c + 1))
		else:
			lax.append(chr(rama[0]))
			k = m + 1
			l = 0
			while l < len(rama) - 1 - m:
				lax.append(chr(rama[k]))
				l += 1
				k += 1
	else:
		lax.append(chr(rama[m]))
	for s in lax:
		print(s, end='')
	print()
	i += 1


import sys
from math import log2, floor, ceil, sqrt
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
for _ in range(int(ri())):
	(n, k) = Ri()
	st = ri()
	st = [i for i in st]
	alpha = [chr(ord('a') + i) for i in range(26)]
	dic = {}
	for i in range(26):
		ch = alpha[i]
		dic[ch] = 0
	for i in st:
		dic[i] += 1
	start = -1
	pre = [0] * 26
	for i in range(24, -1, -1):
		ch = alpha[i]
		nch = alpha[i + 1]
		if dic[nch] > 0:
			pre[i] = pre[i + 1] + 1
		else:
			pre[i] = pre[i + 1]
	for i in range(26):
		ch = alpha[i]
		if dic[ch] > 0:
			start = i
			break
	if dic[alpha[start]] < k:
		left = k - dic[alpha[start]]
		ite = start + 1
		while dic[alpha[ite]] < left:
			left -= dic[alpha[ite]]
			ite += 1
		print(alpha[ite])
	else:
		dic[alpha[start]] -= k
		ite = 0
		r = k - 1
		ans = alpha[start]
		for i in range(start, 26):
			if dic[alpha[i]] > 0:
				if pre[i] == 0:
					ch = alpha[i]
					no = dic[ch]
					div = no // (r + 1)
					rem = no % (r + 1)
					ans += ch * div
					if rem != 0:
						ans += ch
					break
				else:
					for j in range(i, 26):
						ch = alpha[j]
						no = dic[ch]
						for k in range(no):
							ans += ch
					break
		print(ans)


from collections import Counter

def read_int():
	return int(input())

def read_ints():
	return map(int, input().split(' '))
t = read_int()
for case_num in range(t):
	(n, k) = read_ints()
	s = input()
	s = [c for c in s]
	s.sort()
	cnt = Counter(s)
	l = list(cnt)
	l.sort()
	if cnt[l[0]] < k:
		print(s[k - 1])
	elif len(l) == 1:
		add = 0 if cnt[l[0]] % k == 0 else 1
		ans = l[0] * (n // k + add)
		print(ans)
	elif cnt[l[0]] == k and len(l) == 2:
		add = 0 if cnt[l[1]] % k == 0 else 1
		ans = l[0] + l[1] * (n // k + add - 1)
		print(ans)
	else:
		print(l[0] + ''.join(s[k:]))


t = int(input())
while t > 0:
	t -= 1
	(n, k) = [int(x) for x in input().split()]
	string = input()
	a = []
	for i in string:
		a.append(i)
	a.sort()
	cnt = []
	for i in range(0, 26):
		cnt.append(0)
	for i in a:
		cnt[ord(i) - ord('a')] += 1
	if ord(a[k - 1]) > ord(a[0]):
		print(a[k - 1])
	else:
		s = 0
		b = []
		for i in range(0, 26):
			if cnt[i] > 0:
				b.append(i)
		if len(b) > 2 or (len(b) == 2 and cnt[b[0]] > k):
			x = cnt[ord(a[0]) - ord('a')]
			for i in range(0, x - k + 1):
				print(a[0], end='')
			for i in range(x, n):
				print(a[i], end='')
			print()
		elif len(b) == 1:
			for i in range(0, int(n / k) + int(n % k > 0)):
				print(a[0], end='')
			print()
		else:
			print(a[0], end='')
			for i in range(0, int((n - k) / k) + int(n % k > 0)):
				print(a[n - 1], end='')
			print()


from sys import stdin
import math
a = int(stdin.readline())
for b in range(0, a):
	A = stdin.readline().split()
	n = int(A[0])
	K = int(A[1])
	S = set()
	D = dict()
	B = stdin.readline()
	for k in range(0, n):
		u = len(S)
		S.add(B[k])
		if len(S) == u:
			D[B[k]] += 1
		else:
			D[B[k]] = 1
	S = list(S)
	S.sort()
	mark = 0
	if len(S) == 1:
		for y in range(0, int(math.ceil(D[S[0]] / K))):
			if y == int(math.ceil(D[S[0]] / K)) - 1:
				print(S[0])
			else:
				print(S[0], end='')
		continue
	if D[S[0]] < K:
		K -= D[S[0]]
		count = 0
		l = 1
		while count < K:
			count += D[S[l]]
			if count < K:
				l += 1
		print(S[l])
		continue
	else:
		if D[S[0]] == K:
			mark = 1
		print(S[0], end='')
		for j in range(0, D[S[0]] - K):
			print(S[0], end='')
	if len(S) == 2:
		if mark == 1:
			for y in range(0, int(math.ceil(D[S[1]] / K))):
				if y == int(math.ceil(D[S[1]] / K)) - 1:
					print(S[1])
				else:
					print(S[1], end='')
		else:
			for y in range(0, D[S[1]]):
				if y == D[S[1]] - 1:
					print(S[1])
				else:
					print(S[1], end='')
		continue
	for i in range(1, len(S)):
		for y in range(0, D[S[i]]):
			if i == len(S) - 1 and y == D[S[i]] - 1:
				print(S[i])
			else:
				print(S[i], end='')


import math

def solve(n, k, s):
	s = ''.join(sorted(s))
	if k == 1:
		print(s)
		return None
	if s[0] != s[k - 1]:
		print(s[k - 1])
		return None
	answers = []
	for i in range(k):
		answers.append(s[i])
	if len(set(s[k:])) == 1:
		print(answers[0] + s[k] * math.ceil((n - k) / k))
	else:
		print(answers[0] + ''.join(s[k:]))
no = int(input())
for i in range(no):
	(n, k) = tuple(map(int, input().strip().split()))
	s = input()
	solve(n, k, s)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def gift():
	for _ in range(t):
		(n, k) = list(map(int, input().split()))
		word = list(input())
		word.sort()
		if k == 1:
			yield ''.join((str(x) for x in word))
		elif n == k:
			yield word[n - 1]
		else:
			cur = word[k - 1]
			if cur != word[0]:
				yield cur
			else:
				nextele = word[k]
				nexrep = True
				for i in range(k + 1, n):
					if word[i] != nextele:
						nexrep = False
						break
				if (n - k) % k == 0:
					end = k + (n - k) // k
				else:
					end = k + (n - k) // k + 1
				if nexrep:
					yield ''.join((str(x) for x in word[k - 1:end]))
				else:
					yield ''.join((str(x) for x in word[k - 1:]))
t = int(input())
ans = gift()
print(*ans, sep='\n')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = input()
	l = []
	for i in s:
		l.append(i)
	l.sort()
	if n == k:
		print(l[k - 1])
	elif l[k - 1] != l[0]:
		print(l[k - 1])
	elif l[-1] != l[k]:
		for i in range(k - 1, n):
			print(l[i], end='')
		print()
	elif n % k == 0:
		print(l[k - 1], end='')
		print(l[k] * ((n - k) // k))
	else:
		print(l[k - 1], end='')
		print(l[k] * ((n - k) // k + 1))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	s = input()
	l = list(s)
	l.sort()
	if k == 1:
		d = ''
		d = d.join(l)
		print(d)
		continue
	s = l[k - 1]
	ind = 2 * k - 1
	if l[0] < l[k - 1]:
		print(s)
		continue
	if k == n:
		print(s)
		continue
	while True:
		if ind >= n:
			if l[n - 1] == l[ind - k + 1]:
				s += l[n - 1]
			else:
				l1 = l[ind - k + 1:]
				s2 = ''
				s2 = s2.join(l1)
				s += s2
			print(s)
			break
		elif l[ind - k + 1] < l[ind]:
			l1 = l[ind - k + 1:]
			s2 = ''
			s2 = s2.join(l1)
			s += s2
			print(s)
			break
		else:
			if ind == n - 1:
				s += l[ind]
			else:
				b = 0
				for j in range(ind + 1, n):
					if l[j] != l[ind]:
						b = 1
						break
				if b == 0:
					s += (n - 1 - (ind - k + 1) + 1) // k * l[ind]
					if (n - 1 - (ind - k + 1) + 1) % k > 0:
						s += l[ind]
				else:
					l1 = l[ind - k + 1:]
					s2 = ''
					s2 = s2.join(l1)
					s += s2
			print(s)
			break
		if ind == n - 1:
			print(s)
			break
		ind += k


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort()
	if k == 1:
		print(*s, sep='')
		continue
	ans = ''
	low = s[0]
	begin = s[k - 1]
	if begin > low:
		print(begin)
		continue
	if s[n - 1] == low:
		m = n // k
		r = n % k
		for i in range(m):
			ans = ans + low
		if r != 0:
			ans += low
		print(ans)
		continue
	i = 0
	count = 0
	while s[i] == low:
		i = i + 1
		count = count + 1
	if count > k:
		ans = ans + low
		l = ''
		l = l.join(s[k:])
		ans = ans + l
		print(ans)
		continue
	idx = i
	f = s[i]
	count = 0
	while i < n and s[i] == f:
		i = i + 1
		count = count + 1
	if i != n:
		ans = ans + low
		l = ''
		l = l.join(s[idx:])
		ans = ans + l
		print(ans)
		continue
	times = count // k
	ans = ans + low
	for i in range(times):
		ans = ans + f
	times = count % k
	if times != 0:
		ans = ans + f
	print(ans)


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip()
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
test = int(input())
for _ in range(test):
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort()
	i = 0
	if s[0] == s[k - 1]:
		if k < n and s[-1] == s[k]:
			c = s[k]
			cnt = (n + k - 1) // k - 1
			print(''.join([s[k - 1]] + [c] * cnt))
		else:
			print(''.join(s[k - 1:]))
	else:
		print(s[k - 1])


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = input()
	ar = list(s)
	ar.sort()
	alpha = [0] * 26
	U = list(set(ar))
	U.sort()
	for i in ar:
		alpha[ord(i) - 97] += 1
	ct = 0
	for i in alpha:
		if i > 0:
			ct += 1
	if alpha[ord(ar[0]) - 97] < k:
		print(ar[k - 1])
	elif ct == 1:
		st = ''
		for i in range(n):
			if i % k == 0:
				st += ar[i]
		print(st)
	elif ct == 2:
		if alpha[ord(ar[0]) - 97] == k:
			st = ''
			for i in range(n):
				if i % k == 0:
					st += ar[i]
			print(st)
		else:
			st = ar[0]
			for i in range(k, n):
				st += ar[i]
			print(st)
	else:
		st = ar[0]
		for i in range(k, n):
			st += ar[i]
		print(st)


from collections import defaultdict as dd
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = input()
	l = [str(s[i]) for i in range(n)]
	a = [''] * k
	r = [''] * k
	l = sorted(l)
	s = ''.join([str(i) for i in l])
	if k == 1:
		print(s)
	elif k == n:
		print(s[n - 1])
	else:
		for i in range(k):
			a[i] += s[i]
			r[i] += s[i]
		for i in range(k, n):
			a[0] += s[i]
			r[i % k] += s[i]
		a = sorted(a)
		r = sorted(r)
		print(min(a[k - 1], r[k - 1]))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k == 1:
		print(''.join(sorted(input())))
		continue
	s = list(input())
	s.sort()
	freq = {}
	for c in s:
		freq[c] = freq.get(c, 0) + 1
	types = len(freq)
	if types == 1:
		print(s[0] * ((len(s) + k - 1) // k))
		continue
	if s[0] != s[k - 1]:
		print(s[k - 1])
		continue
	if types == 2:
		if freq[s[0]] == k:
			f2 = freq[s[-1]]
			res = [s[0]] + [s[-1]] * ((f2 + k - 1) // k)
			print(''.join(res))
			continue
	print(''.join(s[k - 1:]))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = input()
	re = set(list(s))
	p = [0] * 26
	for i in s:
		p[ord(i) - 97] += 1
	ans = [''] * k
	l = 0
	t = []
	u = False
	res = ''
	for i in range(k):
		for j in range(26):
			if p[j] != 0:
				if j not in t:
					t.append(j)
				ans[i] += chr(j + 97)
				p[j] = p[j] - 1
				break
	if len(t) >= 2:
		if k == 1:
			print(s)
		else:
			print(ans[k - 1])
	elif len(re) > 2:
		for i in range(26):
			ans[0] += p[i] * chr(i + 97)
		print(ans[0])
	elif len(re) == 1:
		re = list(re)
		ans[0] += p[ord(re[0]) - 97] // k * re[0]
		if p[ord(re[0]) - 97] % k != 0:
			print(ans[0] + re[0])
		else:
			print(ans[0])
	else:
		e = list(re)
		e.sort()
		if p[ord(e[0]) - 97] == 0:
			ans[0] += p[ord(e[1]) - 97] // k * e[1]
			if p[ord(e[1]) - 97] % k != 0:
				print(ans[0] + e[1])
			else:
				print(ans[0])
		else:
			for i in range(26):
				ans[0] += p[i] * chr(i + 97)
			print(ans[0])


t = int(input())
answers = []
for _ in range(t):
	(n, k) = [int(i) for i in input().split()]
	s = input()
	assert len(s) == n
	vals = [ord(i) - ord('a') for i in s]
	freq = [0 for i in range(26)]
	for v in vals:
		freq[v] += 1
	num_unique = len(set(vals))
	if num_unique == 1:
		answers.append(s[:int((n - 1) / k) + 1])
		continue
	elif num_unique == 2 and freq[min(set(vals))] == k:
		c1 = chr(min(set(vals)) + ord('a'))
		c2 = chr(max(set(vals)) + ord('a'))
		f_c2 = int((freq[max(set(vals))] - 1) / k) + 1
		answers.append(c1 + c2 * f_c2)
		continue
	worst = ''
	empty = k
	first_letter_assigned = False
	for (char, f) in enumerate(freq):
		char += ord('a')
		if f == 0:
			continue
		if empty == 0:
			worst += chr(char) * f
		elif empty <= f and first_letter_assigned:
			worst = chr(char)
			break
		elif empty == f and (not first_letter_assigned):
			worst = chr(char)
			empty = 0
		elif empty > f:
			empty -= f
		elif empty < f:
			worst = chr(char) * (f - empty + 1)
			empty = 0
		first_letter_assigned = True
	answers.append(worst)
print(*answers, sep='\n')


for t in range(int(input())):
	(n, k) = map(int, input().split())
	ss = sorted(input().strip())
	diff = -1
	for i in range(k - 1):
		if ss[i] != ss[i + 1]:
			diff = i
			break
	if diff != -1 or n == k:
		print(ss[k - 1])
	elif ss[k] == ss[-1]:
		print(ss[k - 1] + ss[k] * ((n - k - 1) // k + 1))
	else:
		print(''.join(ss[k - 1:]))


import math
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	s = input()
	sa = s
	s = list(s)
	s.sort()
	minech = s[0]
	if s[0] != s[k - 1] or k == len(s):
		print(s[k - 1])
	else:
		a = ''
		a += s[0]
		com = s[k]
		if s[k] != s[n - 1]:
			a += ''.join(s[k:])
			print(a)
		else:
			a += com * math.ceil((len(s) - k) / k)
			print(a)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = input()
	lol = {}
	for c in s:
		lol[c] = lol.get(c, 0) + 1
	for c in lol.keys():
		if lol[c] % k != 0:
			break
	a = sorted(set(s))
	b = sorted(s)
	if len(a) == 1:
		print(a[0] * (n // k + int(n % k > 0)))
		continue
	if lol[a[0]] < k:
		print(b[k - 1])
		continue
	if lol[a[0]] == k and len(a) == 2:
		print(a[0] + a[1] * (lol[a[1]] // k + int(lol[a[1]] % k > 0)))
		continue
	else:
		ans = a[0] * (lol[a[0]] + 1 - k)
		for i in range(1, len(a)):
			ans += a[i] * lol[a[i]]
		print(ans)


def Solve(nCase):
	(n, k) = [int(x) for x in input().split()]
	s = input()
	l = list(s)
	l.sort()
	if len(set(l[:k])) > 1:
		print(max(l[:k]))
		return
	m = l[k:]
	ans = [l[0]]
	if len(set(m)) == 1:
		for _ in range(len(m) // k):
			ans.append(m[0])
		if len(m) % k:
			ans.append(m[0])
	else:
		ans.extend(m)
	print(''.join(ans))
T = int(input())
for i in range(1, T + 1):
	Solve(i)


T = int(input())
for t in range(T):
	(n, k) = map(int, input().split())
	a = sorted(list(input()))
	if k == n or a[k - 1] > a[0]:
		print(a[k - 1])
	elif a[k] < max(a):
		print(a[0] + ''.join(a[k:]))
	else:
		print(a[0] + a[k] + a[k] * ((n - k - 1) // k))


import math
t = int(input())
for a in range(t):
	(n, k) = map(int, input().split())
	string = sorted(input())
	strings = ['' for i in range(k)]
	firstSame = True
	for b in range(k):
		if string[b] != string[0]:
			firstSame = False
		strings[b] += string[b]
	if n > k:
		value = string[k]
		same = True
		for b in range(k, n):
			if string[b] != value:
				same = False
		if same and firstSame:
			for b in range(k, n):
				strings[b % k] += string[b]
		else:
			for b in range(k, n):
				strings[0] += string[b]
	print(max(strings))


t = int(input())
for test in range(t):
	(n, k) = list(map(int, input().split()))
	s = list(input())
	s.sort()
	arr = []
	if s[k - 1] != s[0]:
		arr.append(s[k - 1])
	else:
		arr.append(s[0])
		if n > k:
			if len(set(s[k:])) == 1:
				for i in range((n - 1) // k):
					arr.append(s[k])
			else:
				arr.extend(s[k:])
	print(*arr, sep='')


import sys
from collections import Counter

def solve(n, k, s):
	c = Counter(s)
	if k == 1:
		return ''.join(sorted(s))
	if len(c) == 1:
		if n % k == 0:
			return s[0] * (n // k)
		else:
			return s[0] * (n // k + 1)
	keys = list(sorted(c.keys()))
	minimum_key = keys[0]
	if c[minimum_key] == k and len(keys) == 2:
		return minimum_key + keys[1] * ((c[keys[1]] + k - 1) // k)
	elif c[minimum_key] >= k:
		return minimum_key * (c[minimum_key] - (k - 1)) + ''.join((key * c[key] for key in keys[1:]))
	else:
		current_sum = 0
		for e in keys:
			current_sum += c[e]
			if current_sum >= k:
				return e
r = []
for _ in range(int(sys.stdin.readline())):
	(n, k) = map(int, sys.stdin.readline().strip().split())
	s = sys.stdin.readline().strip()
	cur = solve(n, k, s)
	r.append(cur)
sys.stdout.write('\n'.join(r))


import sys
import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort()
	lola = s[0:k]
	if len(set(s)) == 1:
		abc = math.ceil(n / k)
		print(s[0] * abc)
		continue
	if min(lola) != max(lola):
		print(max(lola))
	elif s[k] == max(lola) or len(set(s)) > 2:
		print(max(lola), end='')
		for i in range(k, n):
			print(s[i], end='')
		print()
		continue
	else:
		print(max(lola), end='')
		abc = math.ceil(n / k) - 1
		print(s[-1] * abc)
		continue


from math import ceil

def a(c, k):
	if c[0] != c[k - 1]:
		return c[k - 1]
	if c[0] == c[-1]:
		return c[0] * ceil(len(c) / k)
	s = c[:k]
	if c[k] == c[-1]:
		return s[0] + c[k] * ceil((len(c) - k) / k)
	else:
		return s[0] + ''.join(c[k:])
for _ in ' ' * int(input()):
	((n, k), c) = (map(int, input().split()), input())
	print(a(sorted(c), k))


t = int(input())
for _ in range(t):
	(n, k) = [int(i) for i in input().split()]
	s = sorted(input())
	m1 = max(s)
	s1 = s[k - 1]
	if s[0] != s[k - 1]:
		print(s1)
	else:
		flag = 0
		if k < n:
			if s[k] != m1:
				s1 += ''.join(s[k:])
			else:
				dist = n - k
				each = dist // k
				rem = dist % k
				s1 += m1 * (each + min(rem, 1))
		print(s1)


lis = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = sorted(input())
	has = [0] * 26
	for i in s:
		has[ord(i) - ord('a')] += 1
	ss = sorted(set(s))
	if len(ss) == 2 and has[ord(ss[0]) - ord('a')] == k:
		aa = has[ord(ss[1]) - ord('a')]
		ans = s[0] + ss[1] * math.ceil(aa / k)
		print(*ans, sep='')
	elif len(ss) == 1:
		aa = has[ord(s[0]) - ord('a')]
		ans = s[0] * math.ceil(aa / k)
		print(*ans, sep='')
	else:
		ans = ''
		if has[ord(ss[0]) - ord('a')] < k:
			ans = s[k - 1]
		else:
			ans = s[k - 1:]
		print(*ans, sep='')


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = input()
	s = sorted(s)
	l = [0 for i in range(26)]
	for i in s:
		l[ord(i) - ord('a')] += 1
	i = 0
	while i < 26 and l[i] == 0:
		i += 1
	if l[i] < k:
		print(s[k - 1])
	elif k == 1:
		print(''.join(s))
	else:
		while i < 26:
			if l[i] == 0:
				i += 1
			else:
				break
		if sum(l) == l[i]:
			ans = chr(i + ord('a')) * math.ceil(l[i] / k)
			print(ans)
		else:
			ans = chr(i + ord('a')) * (l[i] - (k - 1))
			for j in range(i + 1, 26):
				if l[j] == n - l[i] and l[i] == k:
					ans += chr(j + ord('a')) * math.ceil(l[j] / k)
				else:
					ans += chr(j + ord('a')) * l[j]
			print(ans)


class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = input()
	x = sorted([k for k in s])
	if n == k:
		print(max(x))
		continue
	if n == 1:
		print(''.join(x))
		continue
	count = [0] * 26
	for each in x:
		count[ord(each) - 97] += 1
	groups = ['' for __ in range(k)]
	equal = 0
	start = x[0]
	for i in range(k):
		groups[i % k] += x[i]
		if x[i] == start:
			equal += 1
		count[ord(x[i]) - 97] -= 1
	jj = [k for k in count if k]
	if len(jj) > 1:
		p = 0
		for i in range(k, n):
			if p < 2:
				groups[p] += x[i]
			else:
				groups[0] += x[i]
	else:
		ch = x[k]
		p = 0
		for i in range(k, n):
			groups[p % equal] += ch
			p += 1
	print(max(groups))


from collections import defaultdict, Counter
from functools import lru_cache
from heapq import heappush, heappop
from math import gcd, floor, ceil
from sys import stdin, stdout

def ilist():
	return [int(x) for x in stdin.readline().strip().split(' ')]

def iint():
	return int(stdin.readline().strip())

def istr():
	return stdin.readline().strip()

def solve(s, k):
	n = len(s)
	s = list(s)
	s.sort()
	if s[0] != s[k - 1]:
		return s[k - 1]
	res = s[0]
	if k < n:
		if s[k] != s[n - 1]:
			for i in range(k, n):
				res += s[i]
		elif (n - k) % k == 0:
			res += s[k] * ((n - k) // k)
		else:
			res += s[k] * ((n - k) // k + 1)
	return res
t = iint()
for _ in range(t):
	(n, k) = ilist()
	s = istr()
	print(solve(s, k))


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = input()
	a = list(s)
	a.sort()
	b = list(set(a))
	b.sort()
	ans = a[k - 1]
	if ans != b[0]:
		print(ans)
	else:
		try:
			c = a[k]
			if c != b[-1]:
				print(ans + ''.join(a[k:]))
			else:
				print(ans + c * math.ceil((n - k) / k))
		except:
			print(ans)


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = input()
	ss = ''.join(sorted(s))
	if k == 1:
		print(ss)
	elif len(set(s)) == 1:
		print(s[0] * int(math.ceil(len(s) / k)))
	else:
		dic = {}
		for i in ss:
			if i in dic:
				dic[i] = dic[i] + 1
			else:
				dic[i] = 1
		if ss.count(ss[0]) < k:
			for i in dic:
				if dic[i] >= k:
					print(i)
					break
				else:
					k = k - dic[i]
		elif ss.count(ss[0]) > k:
			print(ss[k - 1:n])
		elif ss.count(ss[0]) == k:
			if len(set(ss[k - 1:n])) == 2:
				print(ss[k - 1] + ss[-1] * int(math.ceil(dic[ss[-1]] / k)))
			else:
				print(ss[k - 1:n])


def roundUp(a, b):
	ans = a // b
	if a % b == 0:
		return ans
	else:
		return ans + 1
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = input()
	chars = sorted(list(s))
	if chars.count(chars[0]) < k:
		print(chars[k - 1])
		continue
	tail = chars[k:]
	if len(set(tail)) == 1:
		print(chars[k - 1], end='')
		print(''.join(tail[0] * roundUp(len(tail), k)))
		continue
	print(''.join(chars[k - 1:]))


import math
t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	s = list(input())
	s.sort()
	p = s[0:k]
	if len(list(set(p))) > 1:
		print(s[k - 1])
		continue
	elif len(list(set(s))) == 1:
		if n % k == 0:
			for i in range(n // k):
				print(s[0], end='')
			print()
		else:
			for i in range(n // k + 1):
				print(s[0], end='')
			print()
	else:
		p = s[k:]
		if len(list(set(p))) > 1:
			print(s[0], end='')
			for i in range(len(p)):
				print(p[i], end='')
			print()
		else:
			print(s[0], end='')
			n = len(p)
			if n % k == 0:
				for i in range(n // k):
					print(p[i], end='')
				print()
			else:
				for i in range(n // k + 1):
					print(p[i], end='')
				print()


from sys import stdin, stdout
Pi = lambda x: stdout.write(str(x) + '\n')
Ps = lambda x: stdout.write(str(x))
S = lambda x: x * (x + 1) // 2
I = lambda x: 1 + 2 * x
R = lambda : stdin.readline()
Ri = lambda x: map(int, x.split())
Rs = lambda x: map(str, x.split())
Rf = lambda x: map(float, x.split())
MaxN = int(1000.0) + 5

def f(dp, n):
	mn = 1
	while 1:
		k = 1
		good = 1
		while n - 2 * k >= 0 and good:
			if mn == 2 * dp[n - k] - dp[n - 2 * k]:
				good = 0
			k += 1
		if good:
			return mn
		mn += 1

def main():
	t = int(R())
	for test in range(t):
		(n, k) = Ri(R())
		s = R().strip('\n')
		B = sorted(list(s))
		A = [''] * k
		B = ''.join(B)
		for z in range(k):
			A[z] += B[z]
		ans = max(A)
		if ans == A[0]:
			ans2 = A[0] + B[k:]
			pos = 0
			for i in range(k, len(B)):
				if pos == 0:
					A[pos] += B[i]
					pos += 1
					if pos == k:
						pos = 0
					continue
				if A[0] == A[pos] + B[i]:
					A[pos] += B[i]
					pos += 1
				else:
					A[0] += B[i:]
					break
				if pos == k:
					pos = 0
			ans = max(A)
			ans = min(ans, ans2)
		Pi(ans)
main()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort()
	if s[0] != s[k - 1]:
		print(s[k - 1], end='')
	elif n != k:
		if s[k] == s[n - 1]:
			for i in range(0, n, k):
				print(s[i], end='')
		else:
			for i in range(k - 1, n):
				print(s[i], end='')
	else:
		print(s[0], end='')
	print()


from collections import Counter

def rn():
	a = int(input())
	return a

def rl():
	a = list(map(int, input().split()))
	return a
for _ in range(int(input())):
	[n, k] = rl()
	s = input()
	sl = [i for i in s]
	sl.sort()
	mc = 1
	ch = sl[0]
	for i in range(1, n):
		if sl[i] == ch:
			mc += 1
	if mc < k:
		print(sl[k - 1])
		continue
	c = len(Counter(sl).keys())
	ans = ch
	if c == 1:
		for i in range((mc + k - 1) // k - 1):
			ans = ch + ans
	elif c == 2 and mc == k:
		for i in range((n - mc + k - 1) // k):
			ans = ans + sl[mc]
	else:
		for i in range(k, n):
			ans = ans + sl[i]
	print(ans)


import sys

def I():
	return sys.stdin.readline().rstrip()
for _ in range(int(I())):
	(n, k) = map(int, I().split())
	s = [c for c in I()]
	s.sort()
	p = []
	i = 0
	if s[i] != s[i + k - 1]:
		print(s[i + k - 1])
	else:
		p.append(s[i])
		i += k
		d = {}
		for c in s[i:]:
			if c not in d:
				d[c] = 0
			d[c] += 1
		if len(d) > 1:
			print(''.join(p + s[i:]))
		else:
			i = n - i
			i = i // k + (i % k > 0)
			p += [s[-1] * i]
			print(''.join(p))


T = int(input())

def check_all_same(S):
	for i in range(len(S)):
		if S[i] != S[0]:
			return False
	return True

def solve():
	[N, K] = list(map(int, input().split()))
	S = sorted(input())
	prefix = []
	for i in range(K):
		prefix.append(S[i])
	ptr = 0
	for i in range(K, N):
		if S[i] != S[K - 1]:
			break
		ptr += 1
		if ptr == K:
			break
	prefix = sorted(prefix)
	rest = sorted(S[K:])
	if check_all_same(prefix) and check_all_same(rest):
		for (i, v) in enumerate(rest):
			prefix[i % len(prefix)] = prefix[i % len(prefix)] + v
		print(max(prefix))
	else:
		prefix[0] = prefix[0] + ''.join(rest)
		print(max(prefix))
for _ in range(T):
	solve()


import sys
for tt in range(int(input())):
	(n, k) = map(int, input().split())
	s = input()
	s = sorted(s)
	temp = [[] for i in range(k)]
	for i in range(k):
		temp[i].append(s[i])
	if len(set(s[k:])) <= 1:
		new = {temp[0][0]: [[temp[0][0]]]}
		cnt = 1
		for i in range(1, len(temp)):
			if temp[i][0] in new:
				cnt += 1
		final = [[temp[0][0]] for i in range(cnt)]
		j = 0
		size = len(final)
		for i in range(k, n):
			final[j % size].append(s[i])
			j += 1
		print(''.join(sorted(final + temp[size:], key=lambda x: ''.join(x))[-1]))
	else:
		for i in range(k, n):
			temp[0].append(s[i])
		print(''.join(sorted(temp, key=lambda x: ''.join(x))[-1]))


from collections import Counter
import math
for _ in range(int(input())):
	(n, k) = map(int, input().split(' '))
	s = list(input())
	s.sort()
	if s[0] != s[k - 1]:
		print(s[k - 1])
	else:
		temp = Counter(s)
		a = list(sorted(temp.items(), key=lambda x: x[0]))
		if len(a) == 1:
			print(a[0][0] * math.ceil(a[0][1] / k))
		elif len(a) == 2:
			if a[0][1] == k:
				print(a[0][0] + a[1][0] * math.ceil(a[1][1] / k))
			else:
				print(a[0][0] * (a[0][1] - k + 1) + a[1][0] * a[1][1])
		else:
			ans = a[0][0] * math.ceil(a[0][1] - k + 1)
			a.pop(0)
			for x in a:
				ans += x[0] * x[1]
			print(ans)


t = int(input())
while t > 0:
	t -= 1
	nk = input().split()
	n = int(nk[0])
	k = int(nk[1])
	s = input()
	list1 = []
	list2 = []
	for i in range(0, k):
		list1.append('')
		list2.append('')
	s = sorted(s)
	if k == 1:
		for i in range(len(s)):
			print(s[i], end='')
		print('', end='\n')
	elif k == n:
		print(s[n - 1])
	else:
		for i in range(0, k):
			list1[i] += s[i]
			list2[i] += s[i]
		for i in range(k, n):
			list1[0] += s[i]
			list2[i % k] += s[i]
		list1 = sorted(list1)
		list2 = sorted(list2)
		print(min(list1[k - 1], list2[k - 1]))


ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda : int(input())
ip = lambda : [int(w) for w in input().split()]
mp = lambda : map(int, input().split())
from math import ceil
for _ in range(int(input())):
	(n, k) = mp()
	s = input()
	st = list(s)
	st.sort()
	if k == 1:
		print(''.join(st))
		continue
	ans = []
	for i in range(k):
		ans.append([st[i]])
	st = st[k:]
	if ans[0][0] != ans[-1][0]:
		print(ans[-1][0])
		continue
	if len(set(st)) > 1:
		t = ans[-1] + st
	else:
		nl = int(ceil(len(st) / k))
		t = ans[-1] + st[:nl]
	print(''.join(t))


n = int(input())
for x in range(n):
	(t, q) = list(map(int, input().split()))
	k = ''.join(sorted(input()))
	l = []
	for xy in range(q):
		l.append(k[xy])
	if l[0] != l[-1] or t == q:
		print(l[-1])
	elif k[q] == k[-1]:
		counter = q
		ab = 0
		while True:
			l[ab] += k[counter]
			counter += 1
			ab += 1
			if ab == q:
				ab = 0
			if counter > t - 1:
				break
		print(max(l))
	else:
		print(l[0] + k[q:])


import sys
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	s = str(input())
	s = ''.join(sorted(s))
	if k == n:
		print(s[n - 1])
		continue
	if s[0] != s[k - 1]:
		print(s[k - 1])
		continue
	print(s[0], end='')
	if s[k] == s[n - 1]:
		for _ in range(int((n - k) / k)):
			print(s[k], end='')
		if (n - k) % k:
			print(s[k], end='')
		print()
	else:
		print(s[k:])


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = input()
	s = ''.join(sorted(list(s)))
	if s[0] != s[k - 1]:
		print(s[k - 1])
	else:
		sset = set(s)
		if k < n and s[k - 1] == s[k] and (len(sset) == 2):
			print(s[k - 1:])
		elif len(sset) > 2:
			print(s[k - 1:])
		elif k < n:
			print(s[k - 1] + s[k] * math.ceil((n - k) / k))
		else:
			print(s[k - 1])


import getopt
import sys
import math
onlyCase = -1
verbose = False
try:
	(opts, args) = getopt.getopt(sys.argv[1:], 'vc:', ['case='])
except getopt.GetoptError as err:
	print(str(err))
	sys.exit(2)
for (o, a) in opts:
	if o in ('-c', '--case'):
		onlyCase = int(a)
	elif o == '-v':
		verbose = True
	else:
		sys.exit()
ncases = int(input())
for c in range(1, ncases + 1):
	(_, k) = [int(x) for x in input().split()]
	a = list(input())
	if onlyCase != -1 and onlyCase != c:
		continue
	a.sort()
	f = [[] for x in range(k)]
	toFirst = False
	for (i, e) in enumerate(a):
		if i < k:
			f[i].append(e)
		else:
			if f[0][0] != f[-1][0] or e != a[-1]:
				toFirst = True
			if toFirst:
				f[0].append(e)
			else:
				f[i % k].append(e)
	f.sort()
	print(''.join(f[-1]))


T = int(input())
for t in range(T):
	(n, k) = map(int, input().split())
	x = list(input())
	x.sort()
	if x[k - 1] == x[0] and n != k:
		if x[-1] != x[k]:
			print(''.join(x[k - 1:]))
		else:
			num = n - k
			d = num // k
			if num % k != 0:
				d += 1
			print(x[0] + x[-1] * d)
	else:
		print(str(x[k - 1]))


T = int(input())
while T > 0:
	(n, k) = map(int, input().split())
	arr = input()
	count = [0] * 26
	low = 27
	for i in range(n):
		key = ord(arr[i]) - ord('a')
		count[key] += 1
		low = min(low, key)
	temp = k
	for i in range(26):
		temp -= count[i]
		if temp <= 0:
			start = i
			break
	res = chr(start + ord('a'))
	if start == low:
		temp = ''
		repeat = 0
		for i in range(26):
			if i == low:
				count[i] -= k
			if count[i] > 0:
				repeat += 1
			temp += chr(i + ord('a')) * count[i]
		if repeat > 1:
			res += temp
		else:
			le = len(temp)
			if le > 0:
				res += temp[0] * (le // k)
				if le % k != 0:
					res += temp[0]
	print(res)
	T -= 1


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = list(input())
	arr1 = ['' for i in range(k)]
	arr2 = ['' for i in range(k)]
	s.sort()
	for i in range(k):
		arr1[i] += s[i]
		arr2[i] += s[i]
	for i in range(k, n):
		arr1[0] += s[i]
		arr2[i % k] += s[i]
	a = arr1[0]
	b = arr2[0]
	for i in range(1, k):
		a = max(arr1[i], a)
		b = max(arr2[i], b)
	print(min(a, b))


t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	a = list(input())
	a.sort()
	if k == 1:
		print(''.join(a))
		continue
	if k == n:
		print(a[-1])
		continue
	firstKTheSame = True
	for i in range(k - 1):
		if a[i + 1] != a[i]:
			firstKTheSame = False
			break
	if firstKTheSame == False:
		ans = a[k - 1]
	else:
		beyondFirstKTheSame = True
		for j in range(k, n - 1):
			if a[j + 1] != a[j]:
				beyondFirstKTheSame = False
				break
		if beyondFirstKTheSame == False:
			ans = str(a[k - 1]) + ''.join(a[k:])
		else:
			remainingL = n - k
			ans = a[k - 1] + remainingL // k * a[k]
			if remainingL % k != 0:
				ans = ans + a[k]
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort()
	is_dif = False
	for i in range(1, k):
		if s[i] != s[i - 1]:
			is_dif = True
			break
	if is_dif:
		print(s[k - 1])
	else:
		for i in range(k + 1, n):
			if s[i] != s[i - 1]:
				is_dif = True
		if is_dif:
			print(s[0], end='')
			print(*s[k:], sep='')
		else:
			for i in range(0, n, k):
				print(s[i], end='')
			print('')


t = int(input())
for ds in range(t):
	(n, k) = [int(x) for x in input().split()]
	a = input()
	a = list(a)
	a.sort()
	res1 = [''] * k
	res2 = [''] * k
	for i in range(k):
		res1[i] += a[i]
	for i in range(k, n):
		res1[0] += a[i]
	for i in range(n):
		res2[i % k] += a[i]
	print(min(max(res1), max(res2)))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = input()
	l = []
	for i in s:
		l.append(i)
	l.sort()
	temp = ''
	temp += l[k - 1]
	if l[0] == l[k - 1] and k < n and (l[k] == l[n - 1]):
		for j in range((n - 1) // k):
			temp += l[k]
	elif l[0] == l[k - 1]:
		for j in range(k, n):
			temp += l[j]
	print(temp)


def chk(arr):
	for i in arr:
		if i != k:
			return False
	return True
for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	arr = [i for i in input()]
	arr.sort()
	na = list(set(arr))
	na.sort()
	d = {}
	for i in arr:
		d[i] = d.get(i, 0) + 1
	if d[na[0]] < k:
		print(arr[k - 1])
	else:
		ans = na[0]
		d[na[0]] -= k
		v = [d[i] for i in na]
		if v[0] == 0:
			v.pop(0)
			na.pop(0)
		if len(v) == 1:
			ans += d[na[0]] // k * na[0] + min(1, d[na[0]] % k) * na[0]
		else:
			for i in na:
				ans += d[i] * i
		print(ans)


import sys
from array import array
import typing as Tp

def input():
	return sys.stdin.buffer.readline().decode('utf-8')

def output(*args):
	sys.stdout.buffer.write(('\n'.join(map(str, args)) + '\n').encode('utf-8'))

def main():
	t = int(input())
	ans_a = [''] * t
	for ti in range(t):
		(n, k) = map(int, input().split())
		s = sorted(input().rstrip())
		if s[0] == s[-1]:
			ans_a[ti] = s[0] * ((n + k - 1) // k)
		elif s[0] != s[k - 1]:
			ans_a[ti] = s[k - 1]
		elif n > k and s[k - 1] != s[k] and (s[k] == s[-1]):
			ans_a[ti] = s[0] + s[k] * ((n - k + k - 1) // k)
		else:
			ans_a[ti] = ''.join(s[k - 1:])
	output(*ans_a)
main()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	data = input()
	my_dict = dict()
	temp_dict = [0] * 26
	small_one = 1000
	for i in data:
		temp_dict[ord(i) - 97] += 1
		small_one = min(small_one, ord(i))
		if i not in my_dict:
			my_dict[i] = 1
		else:
			my_dict[i] += 1
	go = [[] for _ in range(k)]
	temp = ''
	for i in range(26):
		temp += chr(i + 97) * temp_dict[i]
	my_count = temp.count(chr(small_one))
	for i in range(k):
		go[i].append(temp[i])
	if len(my_dict) == 1:
		if len(temp) // k == len(temp) / k:
			print(chr(small_one) * (len(temp) // k))
		else:
			print(chr(small_one) * (len(temp) // k + 1))
	elif len(my_dict) == 2 and my_count == k:
		temp_set = set()
		zz = 'a'
		for x in temp[k:]:
			temp_set.add(x)
			zz = x
		if len(temp_set) == 1:
			if len(temp[k:]) // k == len(temp[k:]) / k:
				print(chr(small_one) + zz * (len(temp[k:]) // k))
			else:
				print(chr(small_one) + zz * (len(temp[k:]) // k + 1))
	elif my_count >= k:
		print(go[0][0], end='')
		print(temp[k:])
	else:
		print(temp[k - 1])


import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())
for _ in range(int(input())):
	(n, k) = num_input()
	s = list(input())
	s.sort()
	if k == 1:
		print(''.join(s))
	else:
		max1 = str(s[0]) + ''.join(s[k:])
		for i in range(k):
			if max1 < s[i]:
				max1 = s[i]
		arr = []
		indx = 0
		for i in range(k):
			arr.append(s[i])
		for i in range(k, n):
			arr[indx] = arr[indx] + s[i]
			indx += 1
			if indx == k:
				indx = 0
		arr.sort()
		print(min(max1, arr[-1]))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = sorted(list(input()))
	if k == 1:
		print(*s, sep='')
		continue
	elif n == k:
		print(s[-1])
	elif s[0] != s[k - 1]:
		print(s[k - 1])
	elif s[k] != s[-1]:
		print(s[0], *s[k:], sep='')
	else:
		print(s[0] + s[k] * ((len(s) - k) // k) + (s[k] if len(s) % k else ''))


t = int(input())
for i in range(t):
	(n, k) = [int(v) for v in input().split()]
	s = list(input())
	s.sort(reverse=True)
	s = ''.join(s)
	if k == n:
		print(s[0])
	elif len(set(s[-k:])) >= 2:
		print(s[-k])
	else:
		res = s[-1]
		if len(set(s[:-k])) == 1:
			r = n - k
			res += (r // k + int(bool(r % k))) * s[0]
		else:
			res += s[:-k][::-1]
		print(res)


import sys
import math as mt
t = int(input())
for __ in range(t):
	(n, k) = map(int, input().split())
	s = input()
	l = [0] * 27
	for i in range(n):
		l[ord(s[i]) - 97] += 1
	maxi = 0
	ans = ''
	eq = 0
	for i in range(27):
		if l[i] > 0:
			last = i
	for i in range(27):
		if l[i] > 0:
			if last == i:
				for j in range(l[i] // k):
					ans += chr(i + 97)
				if l[i] % k != 0:
					ans += chr(i + 97)
			elif l[i] < k:
				maxi = 1
			else:
				if l[i] == k:
					eq = 1
				ans += chr(i + 97)
				for j in range(l[i] - k):
					ans += chr(i + 97)
			total = l[i]
			l[i] = 0
			break
	if maxi == 1:
		for i in range(27):
			if l[i] > 0:
				total += l[i]
				if total >= k:
					ans += chr(i + 97)
					break
			if total >= k:
				break
	else:
		ch = 0
		for i in range(27):
			if l[i] > 0:
				if last != i or ch == 1 or eq == 0:
					for j in range(l[i]):
						ans += chr(i + 97)
					ch = 1
				else:
					for j in range(l[i] // k):
						ans += chr(i + 97)
					if l[i] % k != 0:
						ans += chr(i + 97)
	print(ans)


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = sorted(list(input()))
	if n == k:
		print(s[-1])
	elif s[0] != s[k - 1]:
		print(s[k - 1])
	elif s[-1] == s[k]:
		print(s[0] + s[k] * ((n - 1) // k))
	else:
		print(*s[k - 1:], sep='')


from sys import stdin, stdout
test = int(stdin.readline())
for _ in range(test):
	(N, K) = map(int, stdin.readline().split())
	s = list(input())
	if K == 1:
		print(''.join(sorted(s)))
		continue
	if K == N:
		print(max(s))
		continue
	s.sort()
	dis = list(set(s))
	dis.sort()
	if len(set(s[:K])) == 1:
		if len(set(s[K:])) == 1:
			first = s[K - 1]
			sec = s[K]
			if not (N - K) % K:
				ans = dis[0] + sec * ((N - K) // K)
			else:
				ans = dis[0] + sec * ((N - K) // K + 1)
			print(ans)
		else:
			sets = [s[i] for i in range(K)]
			sets[0] = s[0] + ''.join(s[K:])
			print(''.join(max(sets)))
		continue
	sets = [s[i] for i in range(K)]
	sets[0] = s[0] + ''.join(s[K:])
	print(''.join(max(sets)))


from math import log as lol
t = int(input())
for u in range(t):
	(n, k) = map(int, input().split())
	s = input()
	l = []
	for i in range(len(s)):
		l.append(s[i])
	l.sort()
	q = k
	a = [''] * k
	tek = 0
	if k == 1:
		for i in range(len(l)):
			a[0] += l[i]
	else:
		for i in range(k):
			a[i] += l[i]
		for i in range(k, len(l)):
			if a[0] + l[i] < a[-1] + l[-1]:
				a[0] += l[i]
			else:
				a[tek] += l[i]
				tek += 1
				tek %= k
	print(max(a))


import collections
import math
t = int(input())
for test_case in range(t):
	(n, k) = [int(x) for x in input().split()]
	cnt = collections.Counter(input())
	start = min(cnt.keys())
	if len(cnt.keys()) == 1:
		ans = [start] * math.ceil(cnt[start] / k)
		print(*ans, sep='')
	elif cnt[start] == k and len(cnt.keys()) == 2:
		second = max(cnt.keys())
		print(''.join([start] + [second] * math.ceil(cnt[second] / k)))
	elif cnt[start] < k:
		for key in sorted(cnt.keys()):
			k -= cnt[key]
			if k <= 0:
				print(key)
				break
	else:
		ans = []
		for key in sorted(cnt.keys()):
			if key == start:
				ans += [key] * (cnt[key] - k + 1)
			else:
				ans += [key] * cnt[key]
		print(*ans, sep='')


(t,) = map(int, input().split())
for _ in range(t):
	(N, K) = map(int, input().split())
	s = input().strip()
	s = sorted(s)
	if K == 1:
		print(''.join(s))
		continue
	dc = dict()
	cs = []
	for c in s:
		if c not in dc:
			cs.append(c)
			dc[c] = 0
		dc[c] += 1
	if dc[cs[0]] < K:
		print(s[K - 1])
		continue
	if len(cs) == 1:
		rs = []
		for _ in range(-(-dc[cs[0]] // K)):
			rs.append(cs[0])
		print(''.join(rs))
		continue
	if len(cs) == 2 and dc[cs[0]] == K:
		rs = [cs[0]]
		for _ in range(-(-dc[cs[1]] // K)):
			rs.append(cs[1])
		print(''.join(rs))
		continue
	print(''.join(s[K - 1:]))


import sys, math
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	(N, K) = map(int, input().split())
	S = list(input())
	S.sort()
	D = 1
	flag = 0
	v1 = 1
	C = [S[1]]
	for i in range(2, N + 1):
		if S[i] != S[i - 1]:
			D = D + 1
			C.append(S[i])
	B = [0 for i in range(D)]
	j = 0
	for i in range(1, N + 1):
		if S[i] == C[j]:
			B[j] = B[j] + 1
		else:
			j = j + 1
			B[j] = B[j] + 1
	if B[0] < K:
		K1 = K
		for i in range(D):
			if K1 - B[i] <= 0:
				print(C[i])
				break
			K1 = K1 - B[i]
	elif D == 1:
		print(C[0] * math.ceil(B[0] / K))
	elif D == 2 and B[0] == K:
		print(C[0] + C[1] * math.ceil(B[1] / K))
	else:
		s = C[0] * (B[0] - K + 1)
		for i in range(1, D):
			s = s + C[i] * B[i]
		print(s)


def solve(s, n, k):
	s = sorted(s)
	s = ''.join(s)
	if n == k:
		print(s[n - 1])
		return
	if s[0] != s[k - 1]:
		print(s[k - 1])
		return
	print(s[0], end='')
	if s[k] != s[n - 1]:
		print(s[k:])
	else:
		r = (n - 1) // k
		print(s[n - 1] * r)
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = input()
	solve(s, n, k)


from math import *
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = input()
	l = list(s)
	l.sort()
	y = set(l)
	y = list(y)
	y.sort()
	z = len(y)
	if z == 1:
		if n % k == 0:
			for i in range(n // k):
				print(l[i], end='')
			print()
		else:
			for i in range(n // k + 1):
				print(l[i], end='')
			print()
	else:
		d = l.count(l[0])
		if k > d:
			print(l[k - 1])
		elif z == 2 and k != 1 and (k == d):
			ct = l.count(y[1])
			if d >= ct:
				print(y[0], end='')
				print(y[1], end='')
				print()
			else:
				print(y[0], end='')
				if ct % d == 0:
					for i in range(ct // d):
						print(y[1], end='')
					print()
				else:
					for i in range(ct // d + 1):
						print(y[1], end='')
					print()
		else:
			for i in range(k - 1, n):
				print(l[i], end='')
			print()


import math
t = int(input())
for z in range(t):
	(n, k) = [int(i) for i in input().split()]
	s = input()
	l = []
	for i in range(n):
		l.append(s[i])
	l.sort()
	m = int(math.ceil(n / k)) - 1
	a = 0
	b = k - 1
	result = []
	if l[a] != l[b]:
		result.append(l[b])
	else:
		result.append(l[a])
		a = b + 1
		b = b + k
		if a < n:
			if l[a] != l[n - 1]:
				result.extend(l[a:])
			else:
				result.extend(l[a:a + int(math.ceil((n - k) / k))])
	for i in result:
		print(i, end='')
	print()


import sys
import math
from collections import Counter
t = int(input())
for _ in range(t):
	(n, k) = [int(c) for c in input().split()]
	s = sorted(input())
	if s[0] != s[k - 1]:
		print(s[k - 1])
		continue
	s_set = sorted(set(s))
	diff_chars = len(s_set)
	if diff_chars == 1:
		print(s[0] * math.ceil(n / k))
		continue
	count = Counter(s)
	if diff_chars == 2:
		if s[k - 1] != s[k]:
			c = math.ceil(count[s[k]] / k)
			print(s[0] + s[k] * c)
			continue
		else:
			print(''.join(s[k - 1:]))
			continue
	res = s[k - 1:]
	print(''.join(res))


import sys
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = sorted(input())
	if k == 1:
		print(''.join(s))
		continue
	if s[k - 1] != s[0]:
		print(s[k - 1])
	else:
		a = list(s[k - 1:])
		q = 1
		j = 0
		while q + 1 < len(a) and a[-1] == a[q]:
			a.pop()
			j += 1
			if j == k - 1:
				j = 0
				q += 1
		print(''.join(a))


import sys
import math
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		(N, K) = [int(x) for x in input().split()]
		S = input().strip()
		S = sorted(S)
		if K == 1:
			print(''.join(S))
			continue
		ans = [[] for _ in range(K)]
		for i in range(K):
			ans[i].append(S[i])
		if ans[0] != ans[-1]:
			print(''.join(ans[-1]))
			continue
		if len(set(S[K:])) == 1:
			ans[0] += S[K] * math.ceil((N - K) / K)
			print(''.join(ans[0]))
		else:
			ans[0] += S[K:]
			print(''.join(ans[0]))
main()


for lo in range(int(input())):
	(n, k) = map(int, input().split())
	st = input()
	ls = [0 for i in range(26)]
	c = 0
	mn = 30
	for i in st:
		x = ord(i) - 97
		if ls[x] == 0:
			c += 1
		ls[x] += 1
		mn = min(x, mn)
	if c == 1:
		z = 0
		if ls[mn] % k != 0:
			z += 1
		z += ls[mn] // k
		ans = ''
		for i in range(z):
			ans += chr(97 + mn)
		print(ans)
		continue
	if ls[mn] < k:
		z = 0
		for i in range(26):
			z += ls[i]
			if mn != i and z >= k:
				ans = chr(97 + i)
				break
		print(ans)
		continue
	if ls[mn] == k and c == 2:
		x = 0
		mn2 = 0
		for i in range(26):
			if mn != i and ls[i] > 0:
				mn2 = i
				x = ls[i]
				break
		z = 0
		if ls[mn2] % k != 0:
			z += 1
		z += ls[mn2] // k
		ans = chr(97 + mn)
		for i in range(z):
			ans += chr(97 + mn2)
		print(ans)
		continue
	z = 0
	ans = ''
	for i in range(26):
		if mn == i:
			for j in range(ls[mn] - k + 1):
				ans += chr(mn + 97)
		else:
			for j in range(ls[i]):
				ans += chr(i + 97)
	print(ans)


import sys
for _ in range(int(sys.stdin.readline().lstrip().rstrip())):
	(n, m) = list(map(int, sys.stdin.readline().lstrip().rstrip().split()))
	word = sys.stdin.readline().lstrip().rstrip()
	arr = list(map(str, word))
	arr.sort()
	x = ''.join((str(x) for x in arr))
	if m == 1:
		print(x)
	else:
		brr = ['' for i in range(m)]
		temp = brr[:]
		for i in range(m):
			y = i % m
			brr[y] += arr[i]
			temp[y] += arr[i]
		for i in range(m, n):
			brr[0] += arr[i]
			temp[i % m] += arr[i]
		a = brr[0]
		b = temp[0]
		for i in range(1, m):
			a = max(brr[i], a)
			b = max(temp[i], b)
		sys.stdout.write(str(min(a, b)) + '\n')


t = int(input())
for x in range(t):
	(n, k) = map(int, input().split())
	s = input()
	s = ''.join(sorted(s))
	l = []
	for i in range(k):
		l.append(s[i])
	s = s[k:]
	if l[0] < l[k - 1] or len(s) == 0:
		print(l[k - 1])
	else:
		if s[0] < s[-1]:
			l[k - 1] = l[k - 1] + s
		else:
			count = 0
			if len(s) % k:
				count += 1
			count += len(s) // k
			for i in range(count):
				l[k - 1] += s[0]
		print(l[k - 1])


import io, os
import sys
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort()
	if s[k - 1] != s[0] or n == k:
		sys.stdout.write(''.join(s[k - 1]) + '\n')
	elif s[k] == s[n - 1]:
		if n % k == 0:
			print(s[0] + s[k] * (n // k - 1))
		else:
			print(s[0] + s[k] * (n // k))
	else:
		print(''.join(s[k - 1:]))


t = int(input())
for test in range(t):
	(n, k) = map(int, input().split())
	s = input()
	sarr = []
	carr = [0 for i in range(26)]
	alph = [chr(97 + i) for i in range(26)]
	for i in range(n):
		sarr.append(s[i])
		carr[ord(s[i]) - 97] += 1
	sarr.sort()
	res = ''
	if sarr[0] != sarr[k - 1]:
		res += sarr[k - 1]
		print(res)
		continue
	res = sarr[0]
	if k == n:
		print(res)
		continue
	if sarr[k] != sarr[n - 1]:
		for i in range(k, n):
			res += sarr[i]
		print(res)
		continue
	resa = ['' for i in range(k)]
	for i in range(k, n):
		resa[i % k] += sarr[i]
	resa.sort()
	print(res + resa[k - 1])


for t in range(int(input())):
	(n, k) = map(int, input().split())
	s = sorted(input())
	answer = ''
	temp = s[:k]
	if len(set(temp)) > 1:
		answer = s[k - 1]
	else:
		answer += s[0]
		rest = s[k:]
		if len(set(rest)) > 1:
			answer += ''.join(rest)
		elif len(rest) > 0:
			answer += rest[0] * (len(rest) // k)
			if len(rest) % k != 0:
				answer += rest[0]
	print(answer)


import sys, math
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
import collections as col
import math

def solve():
	(N, K) = getInts()
	S = listStr()
	S.sort()
	if K == 1:
		return ''.join(S)
	if N == K or S[K - 1] != S[0]:
		return S[K - 1]
	if S[K] != S[-1]:
		return ''.join(S[K - 1:])
	ans = S[K - 1]
	letter = S[K]
	letter_count = S[K:].count(letter)
	required_num = math.ceil(letter_count / K)
	ans += letter * required_num
	return ans
for t in range(getInt()):
	print(solve())


import math
t = int(input())
for i in range(t):
	l1 = list(map(int, input().split()))
	n = l1[0]
	k = l1[1]
	s1 = input()
	l = list(s1)
	l.sort()
	s = ''
	for i in l:
		s += i
	if k == n or s[0] != s[k - 1]:
		print(s[k - 1])
	elif s[k] == s[-1]:
		print(s[0] + s[k] * ((n - 1) // k))
	else:
		print(s[k - 1:])


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort()
	l = [''] * k
	flag = True
	for i in range(n):
		if i < k:
			l[i] += s[i]
		elif l[0] < l[-1]:
			print(l[-1])
			flag = False
			break
		elif s[i] == s[-1]:
			min_val = min(l)
			min_val_count = l.count(min_val)
			l[0] += s[i] * math.ceil((n - i) / min_val_count)
			flag = False
			print(l[0])
			break
		else:
			for j in range(i, n):
				l[0] += s[j]
			print(l[0])
			flag = False
			break
	if flag:
		print(max(l))


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	stri = list(input())
	stri.sort()
	if len(set(stri[:k])) > 1:
		print(stri[k - 1])
		continue
	if len(set(stri[k:])) == 1:
		s = ''
		s = stri[0]
		u = int(math.ceil(len(stri[k:]) / k))
		s += stri[-1] * u
		print(s)
		continue
	else:
		s = [stri[0]] + stri[k:]
		si = ''.join(s)
		print(si)