#### Answer to <https://codeforces.com/problemset/problem/251/A>
# import math

# count, bounds = [int(x) for x in input().split(" ")]
# total = 0

# left_index = 0
# right_index = 2
# current = 0

# lst = [int(x) for x in input().split(" ")]
# if lst[0] < 0:
#     delta = 1 - lst[0]
#     lst = [x + delta for x in lst]

# while right_index < len(lst):
#     if lst[right_index] - lst[left_index] <= bounds:
#         right_index += 1
#         continue
#     elements = right_index - left_index - 1
#     total += elements * (elements - 1) / 2
#     left_index += 1

# while left_index < len(lst) - 2:
#     if lst[count-1] - lst[left_index] <= bounds:
#         elements = count - left_index - 2
#         total += elements * (elements + 1) / 2
#         left_index += 1
# print(int(total))

# ### Answer to <https://codeforces.com/contest/38/problem/C>
# count, bounds = [int(x) for x in input().split(" ")]
# lst = [int(x) for x in input().split(" ")]
# lst.sort()

# right_index = count - 1
# left_index = 0
# highest = 0
# current_num = -1

# # Find left most index where number is greater than or equal to bounds
# for index, i in enumerate(lst):
#     if i < bounds:
#         left_index += 1
#         continue
#     break

# while right_index >= left_index:
#     # Same number as before, no need to check
#     if lst[left_index] == current_num:
#         left_index += 1
#         continue

#     # Different Number
#     current_num = lst[left_index]

#     for j in range(current_num, bounds-1, -1):
#         current = 0
#         for i in range(left_index, right_index + 1):
#             # Add maximum possible
#             current += (lst[i] // j) * j
#         # print("L:", left_index, "| R:", right_index, "current:", current)
#         if current > highest:
#             highest = current
#     left_index += 1

# print(highest)

#### <https://codeforces.com/problemset/problem/617/B>
# def solve():
#     numbers = int(input())
#     lst = [int(x) for x in input().split(" ")]
#     add = sum
#     if add(lst) <= 1:
#         print(add(lst))
#         return
#     elif add(lst) == len(lst):
#         print(1)
#         return

#     left_index = lst.index(1) # First occurence of a nut
#     right_index = left_index

#     for i in range(left_index, len(lst)):
#         if lst[i] == 1:
#             right_index = i
#             break

#     total = 1
#     while right_index < len(lst):
#         if lst[right_index] == 1:
#             delta = right_index - left_index
#             total *= max(1, delta)
#             left_index = right_index
#         right_index += 1
#     print(total)
# solve()

#### <https://codeforces.com/contest/617/problem/C> UNSOLVED
# def solve():
#     total = 0
#     n, r_x, r_y, s_x, s_y = list(map(int, input().split(" ")))
#     flowers = []
#     for i in range(n):
#         flowers.append(list(map(int, input().split(" "))))

#     r_list = []
#     s_list = []
#     flowers_list = []
#     for index, i in enumerate(flowers):
#         distance_r = (r_x - i[0])**2 + (r_y - i[1])**2
#         distance_s = (s_x - i[0])**2 + (s_y - i[1])**2
#         # r_list.append((index, distance_r))
#         # s_list.append((index, distance_s))

#         flowers_list.append((index, distance_r, "R"))
#         flowers_list.append((index, distance_s, "S"))

#     flowers_list.sort(key=lambda x:x[1])

#     # r_list.sort(key=lambda x:x[1])
#     # s_list.sort(key=lambda x:x[1])

#     # lowest = int(s_list[-1][1]) + 1
#     # for index, j in enumerate(s_list):
#     #     current = 0

#     #     # Show all the flowers that are being given to r
#     #     r_tmp = []
#     #     for i in range(index, len(s_list)):
#     #         r_tmp.append(s_list[i][0])

#     # print(r_list)
#     # print(s_list)
#     print(flowers_list)
#     flower_freq = {}
#     for i in range(n):
#         flower_freq[i] = 0

#     val1 = flowers_list[-1][0]
#     val2 = 0
#     if flowers_list[-1][-1] == 'S':
#         highest = 'R'
#     else:
#         highest = 'S'

#     for i in range(n):
#         flowers_freq[flowers_list[i][0]] += 1
#         if flowers_list[i][2] != highest:
#             val2 = flowers_list[i][0]
#     # total = r1 + r2
#     # print(total)
# solve()

#### Solution <https://codeforces.com/problemset/problem/615/A>
# def solve():
#     groups, lights = list(map(int, input().split(" ")))
#     lst = []

#     for i in range(groups):
#         group = list(map(int, input().split(" ")))
#         num = group.pop(0)
#         lst = lst + group
#     lst = list(set(lst))
#     if len(lst) == lights:
#         print("YES")
#     else:
#         print("NO")

# solve()

#### Solution <https://codeforces.com/problemset/problem/614/A>
# def solve():
#     l, r, k = list(map(int, input().split(" ")))
#     lst = []
#     count = 0
#     while k ** count <= r:
#         if k ** count >= l:
#             lst.append(k ** count)
#         count += 1
#     if len(lst) == 0:
#         print(-1)
#     else:
#         print(" ".join([str(x) for x in lst]))

# solve()

# def solve():
#     n = int(input())
#     words = {}
#     for i in range(n):
#       word = input()
#       while "u" in word:
#           word = word.replace("u", "oo")
#       while "kkh" in word:
#           word = word.replace("kkh", "kh")
#       if "kh" in word:
#           word = word.replace("kh", "h")
#       if word not in words:
#           words[word] = 1
#       else:
#           words[word] += 1
#     print(len(words))
# solve()

# def solve():
#     t = int(input())
#     add = len
#     for i in range(t):
#         n = int(input())
#         if n <= 2:
#             print(n)
#             continue

#         lst = [int(2**i) for i in range(1, n+1)]
#         pile1 = []
#         pile2 = []
#         pile1.append(lst.pop(len(lst) - 1))
#         count1 = pile1[0]
#         count2 = 0

#         while add(lst) > 0:
#             while add(lst) > 0 and count2 < count1 and add(pile2) < (n//2):
#                 pile2.append(lst.pop(add(lst) - 1))
#                 count2 += pile2[-1]

#             if add(pile2) == n//2:
#                 while add(lst) > 0:
#                     pile1.append(lst.pop(add(lst) - 1))
#                     count1 += pile1[-1]
#             else:
#                 pile1.append(lst.pop(add(lst) - 1))
#                 count1 += pile1[-1]
#         print(abs(count2 - count1))

# solve()

def solve():
    t = int(input())
    for i in range(t):
        n, k = list(map(int, input().split(" ")))
        word = sorted(input())
        add = len

        # Case k = 1, i.e. take the whole string
        if k == 1:
            print("".join(word))
            continue

        lst = []
        # Put a list for each substring
        for j in range(k):
            lst.append([])

        # Check if all the first k letters are the same
        if add(set(word[:k])) != 1:
            print(word[k-1])
            continue

        # Put the first k letters into the lists
        for m in range(k):
            lst[m].append(word.pop(0))

        # Check if length of remaining string isn't k or there are 2 or more distinct letters
        if add(word) > k or add(set(word)) != 1:
            print("".join(lst[0] + word))

        elif add(word) <= k:
            lst[0].append(word[0])
            print("".join(lst[0]))
solve()


#### Answer to <https://codeforces.com/problemset/problem/251/A>
# import math

# count, bounds = [int(x) for x in input().split(" ")]
# total = 0

# left_index = 0
# right_index = 2
# current = 0

# lst = [int(x) for x in input().split(" ")]
# if lst[0] < 0:
#     delta = 1 - lst[0]
#     lst = [x + delta for x in lst]

# while right_index < len(lst):
#     if lst[right_index] - lst[left_index] <= bounds:
#         right_index += 1
#         continue
#     elements = right_index - left_index - 1
#     total += elements * (elements - 1) / 2
#     left_index += 1

# while left_index < len(lst) - 2:
#     if lst[count-1] - lst[left_index] <= bounds:
#         elements = count - left_index - 2
#         total += elements * (elements + 1) / 2
#         left_index += 1
# print(int(total))

# ### Answer to <https://codeforces.com/contest/38/problem/C>
# count, bounds = [int(x) for x in input().split(" ")]
# lst = [int(x) for x in input().split(" ")]
# lst.sort()

# right_index = count - 1
# left_index = 0
# highest = 0
# current_num = -1

# # Find left most index where number is greater than or equal to bounds
# for index, i in enumerate(lst):
#     if i < bounds:
#         left_index += 1
#         continue
#     break

# while right_index >= left_index:
#     # Same number as before, no need to check
#     if lst[left_index] == current_num:
#         left_index += 1
#         continue

#     # Different Number
#     current_num = lst[left_index]

#     for j in range(current_num, bounds-1, -1):
#         current = 0
#         for i in range(left_index, right_index + 1):
#             # Add maximum possible
#             current += (lst[i] // j) * j
#         # print("L:", left_index, "| R:", right_index, "current:", current)
#         if current > highest:
#             highest = current
#     left_index += 1

# print(highest)

#### <https://codeforces.com/problemset/problem/617/B>
# def solve():
#     numbers = int(input())
#     lst = [int(x) for x in input().split(" ")]
#     add = sum
#     if add(lst) <= 1:
#         print(add(lst))
#         return
#     elif add(lst) == len(lst):
#         print(1)
#         return

#     left_index = lst.index(1) # First occurence of a nut
#     right_index = left_index

#     for i in range(left_index, len(lst)):
#         if lst[i] == 1:
#             right_index = i
#             break

#     total = 1
#     while right_index < len(lst):
#         if lst[right_index] == 1:
#             delta = right_index - left_index
#             total *= max(1, delta)
#             left_index = right_index
#         right_index += 1
#     print(total)
# solve()

#### <https://codeforces.com/contest/617/problem/C> UNSOLVED
# def solve():
#     total = 0
#     n, r_x, r_y, s_x, s_y = list(map(int, input().split(" ")))
#     flowers = []
#     for i in range(n):
#         flowers.append(list(map(int, input().split(" "))))

#     r_list = []
#     s_list = []
#     flowers_list = []
#     for index, i in enumerate(flowers):
#         distance_r = (r_x - i[0])**2 + (r_y - i[1])**2
#         distance_s = (s_x - i[0])**2 + (s_y - i[1])**2
#         # r_list.append((index, distance_r))
#         # s_list.append((index, distance_s))

#         flowers_list.append((index, distance_r, "R"))
#         flowers_list.append((index, distance_s, "S"))

#     flowers_list.sort(key=lambda x:x[1])

#     # r_list.sort(key=lambda x:x[1])
#     # s_list.sort(key=lambda x:x[1])

#     # lowest = int(s_list[-1][1]) + 1
#     # for index, j in enumerate(s_list):
#     #     current = 0

#     #     # Show all the flowers that are being given to r
#     #     r_tmp = []
#     #     for i in range(index, len(s_list)):
#     #         r_tmp.append(s_list[i][0])

#     # print(r_list)
#     # print(s_list)
#     print(flowers_list)
#     flower_freq = {}
#     for i in range(n):
#         flower_freq[i] = 0

#     val1 = flowers_list[-1][0]
#     val2 = 0
#     if flowers_list[-1][-1] == 'S':
#         highest = 'R'
#     else:
#         highest = 'S'

#     for i in range(n):
#         flowers_freq[flowers_list[i][0]] += 1
#         if flowers_list[i][2] != highest:
#             val2 = flowers_list[i][0]
#     # total = r1 + r2
#     # print(total)
# solve()

#### Solution <https://codeforces.com/problemset/problem/615/A>
# def solve():
#     groups, lights = list(map(int, input().split(" ")))
#     lst = []

#     for i in range(groups):
#         group = list(map(int, input().split(" ")))
#         num = group.pop(0)
#         lst = lst + group
#     lst = list(set(lst))
#     if len(lst) == lights:
#         print("YES")
#     else:
#         print("NO")

# solve()

#### Solution <https://codeforces.com/problemset/problem/614/A>
# def solve():
#     l, r, k = list(map(int, input().split(" ")))
#     lst = []
#     count = 0
#     while k ** count <= r:
#         if k ** count >= l:
#             lst.append(k ** count)
#         count += 1
#     if len(lst) == 0:
#         print(-1)
#     else:
#         print(" ".join([str(x) for x in lst]))

# solve()

# def solve():
#     n = int(input())
#     words = {}
#     for i in range(n):
#       word = input()
#       while "u" in word:
#           word = word.replace("u", "oo")
#       while "kkh" in word:
#           word = word.replace("kkh", "kh")
#       if "kh" in word:
#           word = word.replace("kh", "h")
#       if word not in words:
#           words[word] = 1
#       else:
#           words[word] += 1
#     print(len(words))
# solve()

# def solve():
#     t = int(input())
#     add = len
#     for i in range(t):
#         n = int(input())
#         if n <= 2:
#             print(n)
#             continue

#         lst = [int(2**i) for i in range(1, n+1)]
#         pile1 = []
#         pile2 = []
#         pile1.append(lst.pop(len(lst) - 1))
#         count1 = pile1[0]
#         count2 = 0

#         while add(lst) > 0:
#             while add(lst) > 0 and count2 < count1 and add(pile2) < (n//2):
#                 pile2.append(lst.pop(add(lst) - 1))
#                 count2 += pile2[-1]

#             if add(pile2) == n//2:
#                 while add(lst) > 0:
#                     pile1.append(lst.pop(add(lst) - 1))
#                     count1 += pile1[-1]
#             else:
#                 pile1.append(lst.pop(add(lst) - 1))
#                 count1 += pile1[-1]
#         print(abs(count2 - count1))

# solve()

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([])

        word_len = n // k
        remainder = n % k

        if add(set(word[:k])) != 1:
            print(word[k-1])
            continue

        for m in range(k):
            lst[m].append(word.pop(0))

        if add(word) > k:
            print("".join(lst[0] + word))
            continue

        if add(set(word)) != 1:
            lst[0] = lst[0] + word
            print("".join(lst[0].sort()))
            continue

        list_num = 0
        while add(word) > 0:
            lst[list_num].append(word.pop(add(word) - 1))
            list_num = (list_num + 1) % k
        print("".join(lst[0]))
solve()


#### Answer to <https://codeforces.com/problemset/problem/251/A>
# import math

# count, bounds = [int(x) for x in input().split(" ")]
# total = 0

# left_index = 0
# right_index = 2
# current = 0

# lst = [int(x) for x in input().split(" ")]
# if lst[0] < 0:
#     delta = 1 - lst[0]
#     lst = [x + delta for x in lst]

# while right_index < len(lst):
#     if lst[right_index] - lst[left_index] <= bounds:
#         right_index += 1
#         continue
#     elements = right_index - left_index - 1
#     total += elements * (elements - 1) / 2
#     left_index += 1

# while left_index < len(lst) - 2:
#     if lst[count-1] - lst[left_index] <= bounds:
#         elements = count - left_index - 2
#         total += elements * (elements + 1) / 2
#         left_index += 1
# print(int(total))

# ### Answer to <https://codeforces.com/contest/38/problem/C>
# count, bounds = [int(x) for x in input().split(" ")]
# lst = [int(x) for x in input().split(" ")]
# lst.sort()

# right_index = count - 1
# left_index = 0
# highest = 0
# current_num = -1

# # Find left most index where number is greater than or equal to bounds
# for index, i in enumerate(lst):
#     if i < bounds:
#         left_index += 1
#         continue
#     break

# while right_index >= left_index:
#     # Same number as before, no need to check
#     if lst[left_index] == current_num:
#         left_index += 1
#         continue

#     # Different Number
#     current_num = lst[left_index]

#     for j in range(current_num, bounds-1, -1):
#         current = 0
#         for i in range(left_index, right_index + 1):
#             # Add maximum possible
#             current += (lst[i] // j) * j
#         # print("L:", left_index, "| R:", right_index, "current:", current)
#         if current > highest:
#             highest = current
#     left_index += 1

# print(highest)

#### <https://codeforces.com/problemset/problem/617/B>
# def solve():
#     numbers = int(input())
#     lst = [int(x) for x in input().split(" ")]
#     add = sum
#     if add(lst) <= 1:
#         print(add(lst))
#         return
#     elif add(lst) == len(lst):
#         print(1)
#         return

#     left_index = lst.index(1) # First occurence of a nut
#     right_index = left_index

#     for i in range(left_index, len(lst)):
#         if lst[i] == 1:
#             right_index = i
#             break

#     total = 1
#     while right_index < len(lst):
#         if lst[right_index] == 1:
#             delta = right_index - left_index
#             total *= max(1, delta)
#             left_index = right_index
#         right_index += 1
#     print(total)
# solve()

#### <https://codeforces.com/contest/617/problem/C> UNSOLVED
# def solve():
#     total = 0
#     n, r_x, r_y, s_x, s_y = list(map(int, input().split(" ")))
#     flowers = []
#     for i in range(n):
#         flowers.append(list(map(int, input().split(" "))))

#     r_list = []
#     s_list = []
#     flowers_list = []
#     for index, i in enumerate(flowers):
#         distance_r = (r_x - i[0])**2 + (r_y - i[1])**2
#         distance_s = (s_x - i[0])**2 + (s_y - i[1])**2
#         # r_list.append((index, distance_r))
#         # s_list.append((index, distance_s))

#         flowers_list.append((index, distance_r, "R"))
#         flowers_list.append((index, distance_s, "S"))

#     flowers_list.sort(key=lambda x:x[1])

#     # r_list.sort(key=lambda x:x[1])
#     # s_list.sort(key=lambda x:x[1])

#     # lowest = int(s_list[-1][1]) + 1
#     # for index, j in enumerate(s_list):
#     #     current = 0

#     #     # Show all the flowers that are being given to r
#     #     r_tmp = []
#     #     for i in range(index, len(s_list)):
#     #         r_tmp.append(s_list[i][0])

#     # print(r_list)
#     # print(s_list)
#     print(flowers_list)
#     flower_freq = {}
#     for i in range(n):
#         flower_freq[i] = 0

#     val1 = flowers_list[-1][0]
#     val2 = 0
#     if flowers_list[-1][-1] == 'S':
#         highest = 'R'
#     else:
#         highest = 'S'

#     for i in range(n):
#         flowers_freq[flowers_list[i][0]] += 1
#         if flowers_list[i][2] != highest:
#             val2 = flowers_list[i][0]
#     # total = r1 + r2
#     # print(total)
# solve()

#### Solution <https://codeforces.com/problemset/problem/615/A>
# def solve():
#     groups, lights = list(map(int, input().split(" ")))
#     lst = []

#     for i in range(groups):
#         group = list(map(int, input().split(" ")))
#         num = group.pop(0)
#         lst = lst + group
#     lst = list(set(lst))
#     if len(lst) == lights:
#         print("YES")
#     else:
#         print("NO")

# solve()

#### Solution <https://codeforces.com/problemset/problem/614/A>
# def solve():
#     l, r, k = list(map(int, input().split(" ")))
#     lst = []
#     count = 0
#     while k ** count <= r:
#         if k ** count >= l:
#             lst.append(k ** count)
#         count += 1
#     if len(lst) == 0:
#         print(-1)
#     else:
#         print(" ".join([str(x) for x in lst]))

# solve()

# def solve():
#     n = int(input())
#     words = {}
#     for i in range(n):
#       word = input()
#       while "u" in word:
#           word = word.replace("u", "oo")
#       while "kkh" in word:
#           word = word.replace("kkh", "kh")
#       if "kh" in word:
#           word = word.replace("kh", "h")
#       if word not in words:
#           words[word] = 1
#       else:
#           words[word] += 1
#     print(len(words))
# solve()

# def solve():
#     t = int(input())
#     add = len
#     for i in range(t):
#         n = int(input())
#         if n <= 2:
#             print(n)
#             continue

#         lst = [int(2**i) for i in range(1, n+1)]
#         pile1 = []
#         pile2 = []
#         pile1.append(lst.pop(len(lst) - 1))
#         count1 = pile1[0]
#         count2 = 0

#         while add(lst) > 0:
#             while add(lst) > 0 and count2 < count1 and add(pile2) < (n//2):
#                 pile2.append(lst.pop(add(lst) - 1))
#                 count2 += pile2[-1]

#             if add(pile2) == n//2:
#                 while add(lst) > 0:
#                     pile1.append(lst.pop(add(lst) - 1))
#                     count1 += pile1[-1]
#             else:
#                 pile1.append(lst.pop(add(lst) - 1))
#                 count1 += pile1[-1]
#         print(abs(count2 - count1))

# solve()

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([])

        word_len = n // k
        remainder = n % k

        if add(set(word[:k])) != 1:
            print(word[k-1])
            continue

        reword = ""
        for m in range(k):
            lst[m].append(word.pop(0))
            reword += lst[m][-1]

        if add(word) > k:
            print("".join(lst[0] + word))
            continue

        elif add(word) <= k:
            if add(set(word)) != 1:
                lst[0] = lst[0] + word
                print("".join(lst[0].sort()))
                continue
            list_num = 0
            while add(word) > 0:
                lst[list_num].append(word.pop(add(word) - 1))
                list_num += 1
                list_num %= k
            print("".join(lst[0]))
            continue

        print(lst)
solve()


#### Answer to <https://codeforces.com/problemset/problem/251/A>
# import math

# count, bounds = [int(x) for x in input().split(" ")]
# total = 0

# left_index = 0
# right_index = 2
# current = 0

# lst = [int(x) for x in input().split(" ")]
# if lst[0] < 0:
#     delta = 1 - lst[0]
#     lst = [x + delta for x in lst]

# while right_index < len(lst):
#     if lst[right_index] - lst[left_index] <= bounds:
#         right_index += 1
#         continue
#     elements = right_index - left_index - 1
#     total += elements * (elements - 1) / 2
#     left_index += 1

# while left_index < len(lst) - 2:
#     if lst[count-1] - lst[left_index] <= bounds:
#         elements = count - left_index - 2
#         total += elements * (elements + 1) / 2
#         left_index += 1
# print(int(total))

# ### Answer to <https://codeforces.com/contest/38/problem/C>
# count, bounds = [int(x) for x in input().split(" ")]
# lst = [int(x) for x in input().split(" ")]
# lst.sort()

# right_index = count - 1
# left_index = 0
# highest = 0
# current_num = -1

# # Find left most index where number is greater than or equal to bounds
# for index, i in enumerate(lst):
#     if i < bounds:
#         left_index += 1
#         continue
#     break

# while right_index >= left_index:
#     # Same number as before, no need to check
#     if lst[left_index] == current_num:
#         left_index += 1
#         continue

#     # Different Number
#     current_num = lst[left_index]

#     for j in range(current_num, bounds-1, -1):
#         current = 0
#         for i in range(left_index, right_index + 1):
#             # Add maximum possible
#             current += (lst[i] // j) * j
#         # print("L:", left_index, "| R:", right_index, "current:", current)
#         if current > highest:
#             highest = current
#     left_index += 1

# print(highest)

#### <https://codeforces.com/problemset/problem/617/B>
# def solve():
#     numbers = int(input())
#     lst = [int(x) for x in input().split(" ")]
#     add = sum
#     if add(lst) <= 1:
#         print(add(lst))
#         return
#     elif add(lst) == len(lst):
#         print(1)
#         return

#     left_index = lst.index(1) # First occurence of a nut
#     right_index = left_index

#     for i in range(left_index, len(lst)):
#         if lst[i] == 1:
#             right_index = i
#             break

#     total = 1
#     while right_index < len(lst):
#         if lst[right_index] == 1:
#             delta = right_index - left_index
#             total *= max(1, delta)
#             left_index = right_index
#         right_index += 1
#     print(total)
# solve()

#### <https://codeforces.com/contest/617/problem/C> UNSOLVED
# def solve():
#     total = 0
#     n, r_x, r_y, s_x, s_y = list(map(int, input().split(" ")))
#     flowers = []
#     for i in range(n):
#         flowers.append(list(map(int, input().split(" "))))

#     r_list = []
#     s_list = []
#     flowers_list = []
#     for index, i in enumerate(flowers):
#         distance_r = (r_x - i[0])**2 + (r_y - i[1])**2
#         distance_s = (s_x - i[0])**2 + (s_y - i[1])**2
#         # r_list.append((index, distance_r))
#         # s_list.append((index, distance_s))

#         flowers_list.append((index, distance_r, "R"))
#         flowers_list.append((index, distance_s, "S"))

#     flowers_list.sort(key=lambda x:x[1])

#     # r_list.sort(key=lambda x:x[1])
#     # s_list.sort(key=lambda x:x[1])

#     # lowest = int(s_list[-1][1]) + 1
#     # for index, j in enumerate(s_list):
#     #     current = 0

#     #     # Show all the flowers that are being given to r
#     #     r_tmp = []
#     #     for i in range(index, len(s_list)):
#     #         r_tmp.append(s_list[i][0])

#     # print(r_list)
#     # print(s_list)
#     print(flowers_list)
#     flower_freq = {}
#     for i in range(n):
#         flower_freq[i] = 0

#     val1 = flowers_list[-1][0]
#     val2 = 0
#     if flowers_list[-1][-1] == 'S':
#         highest = 'R'
#     else:
#         highest = 'S'

#     for i in range(n):
#         flowers_freq[flowers_list[i][0]] += 1
#         if flowers_list[i][2] != highest:
#             val2 = flowers_list[i][0]
#     # total = r1 + r2
#     # print(total)
# solve()

#### Solution <https://codeforces.com/problemset/problem/615/A>
# def solve():
#     groups, lights = list(map(int, input().split(" ")))
#     lst = []

#     for i in range(groups):
#         group = list(map(int, input().split(" ")))
#         num = group.pop(0)
#         lst = lst + group
#     lst = list(set(lst))
#     if len(lst) == lights:
#         print("YES")
#     else:
#         print("NO")

# solve()

#### Solution <https://codeforces.com/problemset/problem/614/A>
# def solve():
#     l, r, k = list(map(int, input().split(" ")))
#     lst = []
#     count = 0
#     while k ** count <= r:
#         if k ** count >= l:
#             lst.append(k ** count)
#         count += 1
#     if len(lst) == 0:
#         print(-1)
#     else:
#         print(" ".join([str(x) for x in lst]))

# solve()

# def solve():
#     n = int(input())
#     words = {}
#     for i in range(n):
#       word = input()
#       while "u" in word:
#           word = word.replace("u", "oo")
#       while "kkh" in word:
#           word = word.replace("kkh", "kh")
#       if "kh" in word:
#           word = word.replace("kh", "h")
#       if word not in words:
#           words[word] = 1
#       else:
#           words[word] += 1
#     print(len(words))
# solve()

# def solve():
#     t = int(input())
#     add = len
#     for i in range(t):
#         n = int(input())
#         if n <= 2:
#             print(n)
#             continue

#         lst = [int(2**i) for i in range(1, n+1)]
#         pile1 = []
#         pile2 = []
#         pile1.append(lst.pop(len(lst) - 1))
#         count1 = pile1[0]
#         count2 = 0

#         while add(lst) > 0:
#             while add(lst) > 0 and count2 < count1 and add(pile2) < (n//2):
#                 pile2.append(lst.pop(add(lst) - 1))
#                 count2 += pile2[-1]

#             if add(pile2) == n//2:
#                 while add(lst) > 0:
#                     pile1.append(lst.pop(add(lst) - 1))
#                     count1 += pile1[-1]
#             else:
#                 pile1.append(lst.pop(add(lst) - 1))
#                 count1 += pile1[-1]
#         print(abs(count2 - count1))

# solve()

def solve():
    t = int(input())
    for i in range(t):
        n, k = list(map(int, input().split(" ")))
        word = sorted(input())
        add = len

        # Case k = 1, i.e. take the whole string
        if k == 1:
            print("".join(word))
            continue

        lst = []
        # Put a list for each substring
        for j in range(k):
            lst.append([])

        # Check if all the first k letters are the same
        if add(set(word[:k])) != 1:
            print(word[k-1])
            continue

        # Put the first k letters into the lists
        for m in range(k):
            lst[m].append(word.pop(0))

        # Check for 2 or more distinct letters
        if add(set(word)) != 1:
            print("".join(lst[0] + word))
            continue

        # Less than or k remaining letters
        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()


#x,y = map(int,input().split())
#arr = [int(i) for i in input().split()]
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)
	#print(s)
	if len(s) == 1:
		print(s[0])
	elif s[0] != s[k-1]:
		print(s[k-1])
	else:
		if s[k] != s[n-1]:
			ans = s[0]
			for i in range(k,n):
				ans += s[i]
			print(ans)
		else:
			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)


#x,y = map(int,input().split())
#arr = [int(i) for i in input().split()]
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(' ')
	#print(s)
	if len(s) == 1:
		print(s[0])
	elif s[0] != s[k-1]:
		print(s[k-1])
	else:
		if 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)


#x,y = map(int,input().split())
#arr = [int(i) for i in input().split()]
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)
	#print(s)
	if s[0] != s[k-1]:
		print(s[k-1])
	else:
		if s[k] != s[n-1]:
			ans = s[0]
			for i in range(k,n):
				ans += s[i]
			print(ans)
		else:
			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)


#x,y = map(int,input().split())
#arr = [int(i) for i in input().split()]
from collections import Counter
import math
mod = 10**9+7
for i in range(int(input())):
	n,k = map(int,input().split())
	s = input()
	if s[0] != s[k-1]:
		print(s[k-1])
	else:
		if s[k-1] != s[n-1]:
			ans = s[0]
			for i in range(k,n):
				ans += s[i]
			print(ans)
		else:
			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)


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:
        ans=s[0]
        n-=k
        if n>0:
            ans+=s[k]*(n//k)
        if n%k!=0:
            ans+=s[k]
    else:
        for i in range(k-1,n):
            ans+=s[i]
    print(ans)


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)


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]:
        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:]))


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:]))


_IS_DEBUG_MODE = False

def Problem():
    # use custom test cases when debug mode
    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:
        # input number of test cases
        t = int(input())

        # repeat input test cases
        testcaseList = []
        for testcaseIndex in range(t):
            # input test case
            n, k = list(map(int, input().split()))
            s = list(input())
            testcaseList.append([n, k, s])

    return testcaseList

def Solver(testcaseList):
    # repeat calc answer
    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 __name__ == '__main__':
    # time check when debug mode
    if _IS_DEBUG_MODE == True:
        import time

        startTime = time.time()

    # problem solving
    testcaseList = Problem()
    Solver(testcaseList)

    # time check when debug mode
    if _IS_DEBUG_MODE == True:
        endTime = time.time()

        print('time', endTime - startTime)


_IS_DEBUG_MODE = False

def Problem():
    # use custom test cases when debug mode
    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')])

    else:
        # input number of test cases
        t = int(input())

        # repeat input test cases
        testcaseList = []
        for testcaseIndex in range(t):
            # input test case
            n, k = list(map(int, input().split()))
            s = list(input())
            testcaseList.append([n, k, s])

    return testcaseList

def Solver(testcaseList):
    # repeat calc answer
    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]:
            print(aList[-1])
            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 __name__ == '__main__':
    # time check when debug mode
    if _IS_DEBUG_MODE == True:
        import time

        startTime = time.time()

    # problem solving
    testcaseList = Problem()
    Solver(testcaseList)

    # time check when debug mode
    if _IS_DEBUG_MODE == True:
        endTime = time.time()

        print('time', endTime - startTime)


"""
Code of Ayush Tiwari
Codechef: ayush572000
Codeforces: servermonk

"""
# import sys
# input = sys.stdin.buffer.readline

def solution():

    # This is the main code
    n,k=map(int,input().split())
    s=list(input())
    s.sort()
    ans=''
    if s[0]!=s[k-1]:
        print(s[k-1])
    else:

        if s[k]!=s[n-1]:
            for i in range(k-1,n):
                ans+=s[i]
        if s[k]==s[n-1]:
            ans=s[k-1]
            if (n-k)%k==0:
                x=(n-k)//k
            else:
                x=((n-k)//k)+1
            for i in range(x):
                ans+=s[n-1]
        print(ans)
for _ in range(int(input())):
    solution()


"""
Code of Ayush Tiwari
Codechef: ayush572000
Codeforces: servermonk

"""
# import sys
# input = sys.stdin.buffer.readline

def solution():

    # This is the main code
    n,k=map(int,input().split())
    s=list(input())
    s.sort()
    ans=''
    if s[0]!=s[k-1]:
        ans=s[k-1]
    elif s[k]!=s[n-1]:
        for i in range(k-1,n):
            ans+=s[i]
    else:
        ans=s[0] + s[k] * ((n-1)//k)

    print(ans)
for _ in range(int(input())):
    solution()


"""
Code of Ayush Tiwari
Codechef: ayush572000
Codeforces: servermonk

"""
# import sys
# input = sys.stdin.buffer.readline

def solution():

    # This is the main code
    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[k] == s[-1]:
        print(s[0] + s[k] * ((n-1)//k))
    else:
        print(s[k-1:])
for _ in range(int(input())):
    solution()


"""
Code of Ayush Tiwari
Codechef: ayush572000
Codeforces: servermonk

"""
# import sys
# input = sys.stdin.buffer.readline

def solution():

    # This is the main code
    n,k=map(int,input().split())
    s=list(input())
    s.sort()
    ans=''
    if s[0]!=s[k-1]:
        print(s[k-1])
        continue
    if s[k]!=s[n-1]:
        for i in range(k-1,n):
            ans+=s[i]
    if s[k]==s[n-1]:
        ans=s[k-1]
        if (n-k)%k==0:
            x=(n-k)//k
        else:
            x=((n-k)//k)+1
        for i in range(x):
            ans+=s[n-1]
    print(ans)
for _ in range(int(input())):
    solution()


"""
Code of Ayush Tiwari
Codechef: ayush572000
Codeforces: servermonk

"""
# import sys
# input = sys.stdin.buffer.readline

def solution():

    # This is the main code
    n,k=map(int,input().split())
    s=list(input())
    s.sort()
    ans=''
    for i in range(k-1,n,k):
        ans+=s[i]
    print(ans)
for _ in range(int(input())):
    solution()


"""
Code of Ayush Tiwari
Codechef: ayush572000
Codeforces: servermonk

"""
# import sys
# input = sys.stdin.buffer.readline
from collections import Counter

def solution():

    # This is the main code
    n,k=map(int,input().split())
    s=list(input())
    c=Counter(s)
    s.sort()
    ans=''
    if c[s[0]]<k:
        print(s[k-1])
        return
    if s[k-1]!=s[n-1]:
        for i in range(k-1,n):
            ans+=s[i]
    if s[k-1]==s[n-1]:
        if n%k==0:
            x=n//k
        else:
            x=(n//k)+1
        for i in range(x):
            ans+=s[i]
    print(ans)
for _ in range(int(input())):
    solution()


"""
Code of Ayush Tiwari
Codechef: ayush572000
Codeforces: servermonk

"""
# import sys
# input = sys.stdin.buffer.readline

def solution():

    # This is the main code
    n,k=map(int,input().split())
    s=list(input())
    s.sort()
    ans=''
    if s[0]!=s[k-1]:
        print(s[k-1])
        return
    if s[k]!=s[n-1]:
        for i in range(k-1,n):
            ans+=s[i]
    if s[k]==s[n-1]:
        ans=s[k-1]
        if (n-k)%k==0:
            x=(n-k)//k
        else:
            x=((n-k)//k)+1
        for i in range(x):
            ans+=s[n-1]
    print(ans)
for _ in range(int(input())):
    solution()


"""
Code of Ayush Tiwari
Codechef: ayush572000
Codeforces: servermonk

"""
# import sys
# input = sys.stdin.buffer.readline

def solution():

    # This is the main code
    n,k=map(int,input().split())
    s=list(input())
    s.sort()
    ans=''
    if s[0]!=s[k-1]:
        print(s[k-1])
    else:

        if s[k]!=s[n-1]:
            for i in range(k-1,n):
                ans+=s[i]
        else:
            ans=s[k-1]
            if (n-k)%k==0:
                x=(n-k)//k
            else:
                x=((n-k)//k)+1
            for i in range(x):
                ans+=s[n-1]
        print(ans)
for _ in range(int(input())):
    solution()


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(k-1,n,k):
                ans+=given[i]
        else:
            ans = ''.join(given[k-1:])
    print(ans)


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())
    given = sorted(input())
    ans = ''
    for i in range(k):
        temp = ''
        for j in range(0+i,n,k):
            temp+=given[j]
        ans = max(ans,temp)
    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)
	#print(b,c)
	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


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:
		print(d[:1+len(a)//k])
	elif b[c[0]]==k and len(b)==2:
		print(d[0]+d[k+b[c[1]]//k:])
	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


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


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


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


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


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)
	#print(b,c)
	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


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:
		print(d[:1+len(a)//k])
	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


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:]
    #print(ANS)

    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()]

            #print("!",x,y,A)

            if A>=x+y:
                x+=y
                heapq.heappush(H,x)
            else:
                A+=y
                break
        print("".join(A))


import sys
input = sys.stdin.readline

n,k=map(int,input().split())
RB=[tuple(map(int,input().split())) for i in range(n)]
RED=0
BLUE=0
for r,b in RB:
    RED+=r
    BLUE+=b

ANS=RED//k+BLUE//k
RED%=k
BLUE%=k

if RED==0 or BLUE==0:
    print(ANS)
else:
    flag=0
    for RREST in range(1,RED+1):
        BREST=k-RREST

        if BREST<=BLUE:
            for r,b in RB:
                if r>=RREST and b>=BREST:
                    flag=1
                    break
        if flag:
            break

    if flag:
        print(ANS+1)
    else:
        print(ANS)


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:]
    #print(ANS)

    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)

            #print("!",x,y,A)

            if A>=x:
                heapq.heappush(H,x)
            else:
                A.append(y)
                break
        print("".join(A))


from collections import Counter

T = int(input().strip())
for t in range(T):
    n, k = list(map(int, input().split()))
    rem = sorted(input().strip())
    # print(rem, ' before')
    minc = min(rem[:k])
    maxc = max(rem[:k])
    # print(rem)
    if minc <maxc:
        print(maxc)
        continue
    start = maxc
    rem = rem[k:]
    # print(rem, ' after')
    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))

    # while rem:
    #     # print(rem ,' before')
    #     mincur = min(rem[:k])
    #     maxcur = max(rem[:k])
    #     start += [mincur]
    #     nextds = Counter(rem[:k])
    #     k = nextds[mincur]
    #     rem = rem[k:]
    #     # print(rem ,' after')


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])
    # print(rem, ' before')
    minc = min(rem[:k])
    maxc = max(rem[:k])
    # print(rem)
    if minc <maxc:
        print(maxc)
        continue
    start = maxc

    rem = rem[k:]
    # print(rem, ' after')
    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))

    # while rem:
    #     # print(rem ,' before')
    #     mincur = min(rem[:k])
    #     maxcur = max(rem[:k])
    #     start += [mincur]
    #     nextds = Counter(rem[:k])
    #     k = nextds[mincur]
    #     rem = rem[k:]
    #     # print(rem ,' after')


# cook your dish here
t=int(input())
for _ in range(t):
    n,k=map(int,input().split(" "))
    s=input()
    s1=s
    s=sorted(s)
    #print(s)

    m=list(set(s))
    x=max(s[:k])
    y=min(s[:k])
    if len(m)<3:
        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(max(x,y))
    else:
        for i in range(k,n):
            y=y+s[i]

        print(max(x,y))


# cook your dish here
t=int(input())
for _ in range(t):
    n,k=map(int,input().split(" "))
    s=input()
    s1=s
    s=sorted(s)
    #print(s)

    m=list(set(s))
    x=max(s[:k])
    y=min(s[:k])
    if len(m)<3:
        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(max(x,y))


# cook your dish here
t=int(input())
for _ in range(t):
    n,k=map(int,input().split(" "))
    s=input()
    s=sorted(s)
    #print(s)

    m=list(set(s))
    x=max(s[:k])
    y=min(s[:k])
    if len(m)<3:
        i=k
        while i<n:
            if x>y:
                y=y+s[i]
            else:
                x=x+s[i]
            i+=1

        print(max(x,y))
    else:
        for i in range(k,n):
            y=y+s[i]

        print(max(x,y))


# cook your dish here
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)


# cook your dish here
t=int(input())
for _ in range(t):
    n,k=map(int,input().split(" "))
    s=input()
    s1=s
    s=sorted(s)
    #print(s)

    m=list(set(s))
    x=max(s[:k])
    y=min(s[:k])
    if len(m)<3:
        ans=''
        for i in range(k-1,n,k):
            ans=ans+s[i]
        print(ans)
    else:
        for i in range(k,n):
            y=y+s[i]

        print(max(x,y))


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))


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 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))


I=input
for _ in[0]*int(I()):
 n,k=map(int,I().split());s=''.join(sorted(I()));r=s[k-1];i=k
 if s[k-1]==s[0]:
  while i<n:k=s[i:i+k].count(s[i]);r+=s[i:i+(1,k)[i+k<n]];i+=k
 print(r)


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

t = int(input())
for _ in range(t):
    print(solve())


def solve():
    n, k = map(int, input().split())
    s = ''.join(sorted(input()))
    if k == 1:
        return s

    a = [[s[0], 1]]
    for i in range(1, n):
        if s[i] == a[-1][0] and a[-1][1] < k:
            a[-1][1] += 1
        else:
            a.append([s[i], 1])

    if a[0][1] < k:
        return s[k - 1]
    if len(a) == 1:
        return a[0][0]
    if len(a) >= 3:
        return s[k - 1:]
    return a[0][0] + a[1][0] * ( (a[1][1] + k - 1) // k )

t = int(input())
for _ in range(t):
    print(solve())


def solve():
    n, k = map(int, input().split())
    s = ''.join(sorted(input()))
    if k == 1:
        return s[0]

    a = [[s[0], 1]]
    for i in range(1, n):
        if s[i] == a[-1][0] and a[-1][1] < k:
            a[-1][1] += 1
        else:
            a.append([s[i], 1])

    if a[0][1] < k:
        return s[k - 1]
    if len(a) == 1:
        return a[0][0]
    if len(a) >= 3:
        return s[k - 1:]
    return a[0][0] + a[1][0] * ( (a[1][1] + k - 1) // k )

t = int(input())
for _ in range(t):
    print(solve())


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:]

t = int(input())
for _ in range(t):
    print(solve())


from collections import Counter
from math import ceil
def solve():
    N,K = map(int,input().split())
    S=input()
    S = sorted(S)
    ans=""
    C =  Counter(S)

    if len(set(S))==1:
        print("".join(S[:ceil(N/K)]))
    elif all(v%K==0 for v in C.values()) and  len(set(S))==2:
        r="".join(map(str,[v for v in S[::K]]))
        t="".join(S[K-1:])
        print(min(r,t))
    elif len(set(S[:K]))==1:
        print("".join(S[K-1:]))
    else:
        print(S[K-1])
for _ in range(int(input())):
    solve()


from collections import Counter
from math import ceil
def solve():
    N,K = map(int,input().split())
    S=input()
    S = sorted(S)
    ans=""
    C =  Counter(S)

    if len(set(S))==1:
        print("".join(S[:ceil(N/K)]))
    elif all(v%K==0 for v in C.values()):
        print("".join(map(str,[v for v in S[::K]])))
    elif len(set(S[:K]))==1:
        print("".join(S[K-1:]))
    else:
        print(S[K-1])
for _ in range(int(input())):
    solve()


from collections import Counter
from math import ceil
def solve():
    N,K = map(int,input().split())
    S=input()
    S = sorted(S)
    ans=""
    C =  Counter(S)

    if len(set(S))==1:
        print("".join(S[:ceil(N/K)]))
    elif all(v%K==0 for v in C.values()):
        r="".join(map(str,[v for v in S[::K]]))
        t="".join(S[K-1:])
        print(min(r,t))
    elif len(set(S[:K]))==1:
        print("".join(S[K-1:]))
    else:
        print(S[K-1])
for _ in range(int(input())):
    solve()


def solve():
    N,K = map(int,input().split())
    S=input()
    S = sorted(S)

    if len(set(S[:K]))==1:
        r="".join(map(str,[v for v in S[::K]]))
        t="".join(S[K-1:])
        print(min(r,t))
    else:
        print(S[K-1])
for _ in range(int(input())):
    solve()


from collections import Counter
from math import ceil
def solve():
    N,K = map(int,input().split())
    S=input()
    S = sorted(S)
    ans=""
    C =  Counter(S)

    if len(set(S))==1:
        print("".join(S[:ceil(N/K)]))
    elif all(v%K==0 for v in C.values()) and  len(set(S))==2:
        print("".join(map(str,[v for v in S[::K]])))
    elif len(set(S[:K]))==1:
        print("".join(S[K-1:]))
    else:
        print(S[K-1])
for _ in range(int(input())):
    solve()


from collections import Counter
from math import ceil
def solve():
    N,K = map(int,input().split())
    S=input()
    S = sorted(S)
    ans=""
    C =  Counter(S)

    if len(set(S))==1:
        print("".join(S[:ceil(N/K)]))
    elif len(set(S[:K]))==1:
        r="".join(map(str,[v for v in S[::K]]))
        t="".join(S[K-1:])
        print(min(r,t))
    else:
        print(S[K-1])
for _ in range(int(input())):
    solve()


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()


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)


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

    heap = []
    for _ in range(k):
        heapq.heappush(heap, [])

    for key in sorted(letters.keys()):
        while letters[key] > 0:
            minitem = heapq.heappop(heap)
            minitem.append(key)
            heapq.heappush(heap, minitem)
            letters[key] -= 1

    strings = []
    for val in heap:
        strings.append("".join([chr(abs(e)) for e in val]))
    print(max(strings))


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))))


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 = []

		r = (n-1)%k
		for j in range(n//k):
			b.append(s[r+j*k])
		if r != k-1:
			b.append(s[r+(n//k)*k])

		print(min(''.join(a),''.join(b)))


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:
        print(s[k - 1])
    else:
        if 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)


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])
    else:
        if 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)


#------------------------template--------------------------#
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()]

#-------------------------code---------------------------#
#vsInput()

for _ in range(Int()):
    n,k=value()
    a=sorted(input())
    freq=Counter(a)

    ans=defaultdict(list)
    #print(a)

    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(ans)
    print(*max(ans.values(),key= lambda x:''.join(x)),sep="")


#------------------------template--------------------------#
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()]

#-------------------------code---------------------------#
#vsInput()

for _ in range(Int()):
    n,k=value()
    a=sorted(input())
    freq=Counter(a)

    ans=defaultdict(list)
    #print(a)

    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(ans)
    print(*max(ans.values(),key= lambda x:''.join(x)),sep="")


import math

testCases= int(input())

for _ in range(testCases):
    n, k= map(int, input().split())
    a= sorted(input())

    #Find number of charecters in each wor
    countOfWords= []
    reference= math.ceil(n/ k)
    while(n> k):
        countOfWords.append(min(reference, n))
        n-= reference
        k-= 1
    countOfWords+= [1]* k
    #print('countOfWords: '+str(countOfWords))

    answer= []
    lastIndex= len(a)
    frontIndex= 0
    for index in range(len(countOfWords)):
        word= a[frontIndex]
        fromIndex= lastIndex- countOfWords[index]+ 1
        #print('countOfWords[index]: '+str(countOfWords[index]))

        for index_ in range(fromIndex, lastIndex):
            word+= a[index_]

        frontIndex+= 1
        lastIndex= fromIndex
        answer.append(word)
        #print('word: '+str(word)+' frontIndex: '+str(frontIndex)+' lastIndex: '+str(lastIndex))
        #print()
    #print('answer: '+str(answer))

    print(max(answer))


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[0]== a[-1]):
        print(a[0]* math.ceil(n/ k))
    else:
        print(a)


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:])


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]* math.floor(n/ k))
    else:
        print(a[k- 1:])


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[0]== a[-1]):
        print(a[0]* math.ceil(n/ k))
    else:
        print(a[k- 1:])


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]* math.ceil(n/ k))
    else:
        print(a[k- 1:])


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:])


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+1] + s[k+1] * (((n-k)//k) - 1)
              else:
                  anserw = list(anserw) + s[k:]
                  anserw = "".join(anserw)
            print(anserw)

        else:
            print("".join(s))
main()


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()


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] + s[k] * (((n-k)//k) - 1)
              else:
                  anserw = list(anserw) + s[k:]
                  anserw = "".join(anserw)
            print(anserw)

        else:
            print("".join(s))
main()


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+1] + s[k+1] * ((n-k)//k)
              else:
                  anserw = list(anserw) + s[k:]
                  anserw = "".join(anserw)
            print(anserw)

        else:
            print("".join(s))
main()


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+1] * (n//k)
              else:
                  anserw = list(anserw) + s[k:]
                  anserw = "".join(anserw)
            print(anserw)

        else:
            print("".join(s))
main()


def solve():
    n,k=map(int,input().split())
    s=str(input())
    tmp=sorted(s)
    st="".join(tmp)
    if st[0]!=st[k-1]:
        print(f"{st[k-1]}\n")
    else:
        if s[k]==st[n-1]:
            diff=n-k
            print(st[0],end='')
            for i in range(diff//k):
                print(st[k],end='')
            if diff%k:
                print(st[k],end='')
            print('\n')
        else:
            print(st[0],end='')
            for i in range(k,n):
                print(st[i],end='')
            print('\n')
for _ in range(int(input())):
    solve()


def solve():
    n,k=map(int,input().split())
    s=str(input())
    tmp=sorted(s)
    st="".join(tmp)
    if st[0]!=st[k-1]:
        print(st[k-1])
        print('\n')
    else:
        if s[k]==st[n-1]:
            diff=n-k
            print(st[0],end='')
            for i in range(diff//k):
                print(st[k],end='')
            if diff%k:
                print(st[k],end='')
            print('\n')
        else:
            print(st[0],end='')
            for i in range(k,n):
                print(st[i],end='')
            print('\n')
for _ in range(int(input())):
    solve()


def solve():
    n,k=map(int,input().split())
    s=str(input())
    tmp=sorted(s)
    st="".join(tmp)
    if st[0]!=st[k-1]:
        print(f"{st[k-1]}\n")
    else:
        if s[k]==st[n-1]:
            diff=n-k
            print(st[0],end='')
            for i in range(diff//k):
                print(st[k],end='')
            if diff%k:
                print(st[k],end='')
            # print('\n')
        else:
            print(st[0],end='')
            for i in range(k,n):
                print(st[i],end='')
            # print('\n')
for _ in range(int(input())):
    solve()


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())


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())


t=int(input())
while(t>0):
    n,k=map(int,input().split())
    a=list(input())
    a.sort()
    if(a[k-1]!=a[0]):
        print(a[k-1])
    else:
        if(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())
while(t>0):
    n,k=map(int,input().split())
    a=list(input())
    a.sort()
    l=['']*k
    for i in range(n):
        l[i%(k)]+=a[i]
    print(max(l))
    t-=1


t=int(input())
while(t>0):
    n,k=map(int,input().split())
    a=list(input())
    a.sort()
    if(n==k):
        print(a[-1])
    else:
        if(a[k-1]!=a[0]):
            print(a[k-1])
        else:
            if(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


def solve(arr,k):
	# print(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()
	ans=solve(arr,k)
	print(*ans,sep="")


def solve(arr,k):
	# print(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="")


def solve(t):
    for i in range(t):
        nk = input().split()
        n, k = int(nk[0]), int(nk[1])
        s = [x for x in input()]
        if k == 1:
            print(*sorted(s), sep='')
        else:
            a = [''] * k
            for i in range(k):
                a[i] += s.pop(s.index(min(s)))
            if len(set(a)) > 1 or not s:
                print(max(a))
            elif len(set(s)) > 1:
                print(a[0] + ''.join(sorted(s)))
            else:
                print(a[0] + s[0]*((len(s)//k + 1) if (len(s) % k) else (len(s)//k)))

solve(int(input()))


#include <stdio.h>
#define MAX 100000
#define MAX_NEG -1000000000
#define MAX_POS 1000000000
unsigned long int n,i, sum_pos=0, sum_neg=0, sum=0, result=0;
signed long int arr[MAX], res[MAX] = {0};

int main(){

	if ((n<MAX) && (n>=1)) {
		for (i=0;i<n;i++){
			scanf("%d", &arr[i]);
		}
		for (i=0;i<n;i++){
			if (arr[i]>1) {
				sum_pos+= arr[i]-1;
				res[i] = 1;
			}
			if (arr[i]<-1) {
				sum_neg+= (-1*arr[i])-1;
				res[i] = -1;
			}
			if (arr[i]==0) {
				sum_pos++;
				res[i]=1;
			}
		}
		sum = sum_pos+sum_neg;
		for (i=1;i<n;i++) {
			result = res[i]*res[i-1];
		}
		if (result == -1){
			sum+=-2;
		}

		printf("%d", sum);
	} else {
		printf("%d", sum);
	}
	return 0;
}


#include <stdio.h>
#define MAX 100000
#define MAX_NEG -1000000000
#define MAX_POS 1000000000
unsigned long long int n,i, sum_pos=0, sum_neg=0, sum=0;
signed long int result=1;
signed long int arr[MAX];

int main(){
    n=20;
	scanf("%d", &n);
	if ((n<MAX) && (n>=1)) {
		for (i=0;i<n;i++){
			scanf("%d", &arr[i]);
		}
		for (i=0;i<n;i++){
			if (arr[i]>=1) {
				sum_pos+= arr[i]-1;
			} else if (arr[i]<=-1) {
				sum_neg+= (-1*(arr[i]+1));
				result *= -1;
			} else if (arr[i]==0) {
				sum_pos++;
			}
		}
		sum = sum_pos+sum_neg;
		if (result == -1){
			if (n==2)
				sum=2;
			else if (n ==1)
				sum+=2;
			else {
			}
		}
	}
	printf("%d", sum);
	return 0;
}


#include <stdio.h>
#define MAX 100000
#define MAX_NEG -1000000000
#define MAX_POS 1000000000
unsigned long int n,i, sum_pos=0, sum_neg=0, sum=0, result=0;
signed long int arr[MAX], res[MAX] = {0};

int main(){

	printf("Enter number of elements: ");
	scanf("%d", &n);

	if ((n<MAX) && (n>=2)) {
		for (i=0;i<n;i++){
			scanf("%d", &arr[i]);
		}
		for (i=0;i<n;i++){
			if (arr[i]>1) {
				sum_pos+= arr[i]-1;
				res[i] = 1;
			}
			if (arr[i]<-1) {
				sum_neg+= (-1*arr[i])-1;
				res[i] = -1;
			}
			if (arr[i]==0) {
				sum_pos++;
				res[i]=1;
			}
		}
		sum = sum_pos+sum_neg;
		for (i=1;i<n;i++) {
			result = res[i]*res[i-1];
		}
		if (result == -1){
			sum+=-2;
		}

//		if ((n%2) == 1){
//			sum--;
//		}
		printf("%d", sum);
	} else {
		printf(" Enter number of elements between 2 to 100000", n, MAX);
	}
	return 0;
}


#include <stdio.h>
#define MAX 100000
unsigned long long int n,i, sum_z=0,sum_neg=0,  sum=0l;
signed long long int arr[MAX];
int main(){
	scanf("%d", &n);
	if ((n<MAX) && (n>=1)) {
		for (i=0;i<n;i++){
			scanf("%I64d", &arr[i]);
		}
		for (i=0;i<n;i++){
			if (arr[i]<0) {
				sum+= -(arr[i]+1);
				sum_neg++;
			} else if (arr[i]>0) {
				sum+= arr[i]-1;
			} else {
				sum_z++;
			}
		}
		if (sum_neg%2 == 1){
			if (sum_z>0)
				sum+=sum_z;
			else sum+=2;
	    } else {
	        sum+=sum_z;
	    }
	}
	printf("%I64d", sum);
	return 0;
}


#include <stdio.h>
#define MAX 100000
#define MAX_NEG -1000000000
#define MAX_POS 1000000000
unsigned long int n,i, sum_pos=0, sum_neg=0, sum=0;
signed long int result=1;
signed long int arr[MAX], res[MAX] = {0};

int main(){

	scanf("%d", &n);
	if ((n<MAX) && (n>=1)) {
		for (i=0;i<n;i++){
			scanf("%d", &arr[i]);
		}
		for (i=0;i<n;i++){
			if (arr[i]>=1) {
				sum_pos+= arr[i]-1;
			} else if (arr[i]<=-1) {
				sum_neg+= (-1*(arr[i]+1));
				result *= -1;
			} else if (arr[i]==0) {
				sum_pos++;
			}
		}
		sum = sum_pos+sum_neg;
		if (result == -1){
			if (n==2)
				sum=2;
			else
				sum+=2;
		}
	}
	printf("%d", sum);
	return 0;
}


#include <stdio.h>
#define MAX 100000
#define MAX_NEG -1000000000
#define MAX_POS 1000000000
unsigned long long int n,i, sum_pos=0l, sum_neg=0l, sum=0l;
signed long int result=1;
signed long int arr[MAX];
int main(){
	scanf("%d", &n);
	if ((n<MAX) && (n>=1)) {
		for (i=0;i<n;i++){
			scanf("%I64d", &arr[i]);
		}
		for (i=0;i<n;i++){
		    if ((arr[i]<=MAX_POS) && (arr[i]>=MAX_NEG)) {
    			if (arr[i]>=1) {
    				sum+= arr[i]-1;
    			} else if (arr[i]<=-1) {
    				sum+= -(arr[i]+1);
    				sum_neg++;
    			} else if (arr[i]==0) {
    				sum++;
    			}
		   }
		}
		if (sum_neg%2 == 1){
			if (sum  == 0)
				sum+=2;
	    }
	}
	printf("%I64d", sum);
	return 0;
}


#include <stdio.h>
#define MAX 100000
#define MAX_NEG -1000000000
#define MAX_POS 1000000000
unsigned long int n,i, sum_pos=0, sum_neg=0, sum=0;
signed long int result=1;
signed long int arr[MAX], res[MAX] = {0};

int main(){

	scanf("%d", &n);
	if ((n<MAX) && (n>=1)) {
		for (i=0;i<n;i++){
			scanf("%d", &arr[i]);
		}
		for (i=0;i<n;i++){
			if (arr[i]>=1) {
				sum_pos+= arr[i]-1;
			} else if (arr[i]<=-1) {
//				result = 5;
				sum_neg+= (-1*(arr[i]+1));
				if (arr[i]%2 != 0)
					result *= -1;
			} else if (arr[i]==0) {
				sum_pos++;
			}
		}
		sum = sum_pos+sum_neg;
		if (result == -1){
			if (n==2)
				sum=2;
			else
				sum+=2;
		}

		printf("%d", sum);
//		printf("\n%d - %d - %d - %d", sum, sum_pos, sum_neg, result);
	} else {
		printf("\n-%d", sum);
	}
	return 0;
}


#include <stdio.h>
#define MAX 100000
unsigned long long int n,i, sum_z=0,sum_neg=0,  sum=0l;
signed long long int arr[MAX];
int main(){
	scanf("%d", &n);
	if ((n<MAX) && (n>=1)) {
		for (i=0;i<n;i++){
			scanf("%I64d", &arr[i]);
		}
		for (i=0;i<n;i++){
			if (arr[i]>0) {
				sum+= arr[i]-1;
			} else if (arr[i]<0) {
				sum+= -(arr[i]+1);
				sum_neg++;
			} else {
				sum_z++;
			}
		}
		if (sum_neg%2 == 1){
			if (sum_z>0)
				sum+=sum_z;
			else sum+=2;
	    } else {
	        sum+=sum_z;
	    }
	}
	printf("%I64d", sum);
	return 0;
}


#include <stdio.h>
#define MAX 100000
#define MAX_NEG -1000000000
#define MAX_POS 1000000000
unsigned long long int n,i, sum_z=0, sum=0l;
signed long int result=1;
signed long int arr[MAX];
int main(){
	scanf("%d", &n);
	if ((n<MAX) && (n>=1)) {
		for (i=0;i<n;i++){
			scanf("%I64d", &arr[i]);
		}
		for (i=0;i<n;i++){
		    if ((arr[i]<=MAX_POS) && (arr[i]>=MAX_NEG)) {
    			if (arr[i]>=1) {
    				sum+= arr[i]-1;
    			} else if (arr[i]<=-1) {
    				sum+= -(arr[i]+1);
    				sum_neg++;
    			} else if (arr[i]==0) {
    				sum++;
    				sum_z++;
    			}
		   }
		}
		if (sum_neg%2 == 1){
			if (sum_z>0)
				sum+=2;
	    }
	}
	printf("%I64d", sum);
	return 0;
}


#include <stdio.h>
#define MAX 100000
#define MAX_NEG -1000000000
#define MAX_POS 1000000000
unsigned long long int n,i, sum_z=0,sum_neg=0,  sum=0l;
signed long int result=1;
signed long int arr[MAX];
int main(){
	scanf("%d", &n);
	if ((n<MAX) && (n>=1)) {
		for (i=0;i<n;i++){
			scanf("%I64d", &arr[i]);
		}
		for (i=0;i<n;i++){
		    if ((arr[i]<=MAX_POS) && (arr[i]>=MAX_NEG)) {
    			if (arr[i]>=1) {
    				sum+= arr[i]-1;
    			} else if (arr[i]<=-1) {
    				sum+= -(arr[i]+1);
    				sum_neg++;
    			} else if (arr[i]==0) {
//    				sum++;
    				sum_z++;
    			}
		   }
		}
		sum+=sum_z;
		if (sum_neg%2 == 1){
			if (sum_z<=0)
				sum=2;
	    }
	}
	printf("%I64d", sum);
	return 0;
}


#include <stdio.h>
#define MAX 100000
#define MAX_NEG -1000000000
#define MAX_POS 1000000000
unsigned long int n,i, sum_pos=0, sum_neg=0, sum=0;
signed long int result=1;
signed long int arr[MAX], res[MAX] = {0};

int main(){

	scanf("%d", &n);
	if ((n<MAX) && (n>=1)) {
		for (i=0;i<n;i++){
			scanf("%d", &arr[i]);
		}
		for (i=0;i<n;i++){
			if (arr[i]>=1) {
				sum_pos+= arr[i]-1;
			} else if (arr[i]<=-1) {
				sum_neg+= (-1*(arr[i]+1));
				result *= -1;
			} else if (arr[i]==0) {
				sum_pos++;
			}
		}
		sum = sum_pos+sum_neg;
		if (result == -1){
			if (n==2)
				sum=2;
			else if (n ==1)
				sum+=2;
			else {
			}
		}
	}
	printf("%d", sum);
	return 0;
}


#include <stdio.h>
#define MAX 100000
#define MAX_NEG -1000000000
#define MAX_POS 1000000000
unsigned long long int n,i, sum_z=0,sum_neg=0,  sum=0l;
signed long int result=1;
signed long int arr[MAX];
int main(){
	scanf("%d", &n);
	if ((n<MAX) && (n>=1)) {
		for (i=0;i<n;i++){
			scanf("%I64d", &arr[i]);
		}
		for (i=0;i<n;i++){
//		    if ((arr[i]<=MAX_POS) && (arr[i]>=MAX_NEG)) {
    			if (arr[i]>=1) {
    				sum+= arr[i]-1;
    			} else if (arr[i]<=-1) {
    				sum+= -(arr[i]+1);
    				sum_neg++;
    			} else if (arr[i]==0) {
    				sum_z++;
    			}
//		   }
		}
		if (sum_neg%2 == 1){
			if (sum_z>0)
				sum+=sum_z;
			else sum+=2;
	    } else {
	        sum+=sum_z;
	    }
	}
	printf("%I64d", sum);
	return 0;
}


#include <stdio.h>
#define MAX 100000
long long int n,i, sum_z=0,sum_neg=0,  sum=0;
long long int arr[MAX];
int main(){
	scanf("%d", &n);
	if ((n<MAX) && (n>=1)) {
		for (i=0;i<n;i++){
			scanf("%I64d", &arr[i]);
		}
		for (i=0;i<n;i++){
			if (arr[i]<0) {
				sum+= -(arr[i]+1);
				sum_neg++;
			} else if (arr[i]>0) {
				sum+= arr[i]-1;
			} else {
				sum_z++;
			}
		}
		if (sum_neg%2 == 1){
			if (sum_z>0)
				sum+=sum_z;
			else sum+=2;
	    } else {
	        sum+=sum_z;
	    }
	}
	printf("%I64d", sum);
	return 0;
}


#include <stdio.h>
#define MAX 100000
#define MAX_NEG -1000000000
#define MAX_POS 1000000000
unsigned long long int n,i, sum_z=0,sum_neg=0,  sum=0l;
signed long int result=1;
signed long int arr[MAX];
int main(){
	scanf("%d", &n);
	if ((n<MAX) && (n>=1)) {
		for (i=0;i<n;i++){
			scanf("%I64d", &arr[i]);
		}
		for (i=0;i<n;i++){
		    if ((arr[i]<=MAX_POS) && (arr[i]>=MAX_NEG)) {
    			if (arr[i]>=1) {
    				sum+= arr[i]-1;
    			} else if (arr[i]<=-1) {
    				sum+= -(arr[i]+1);
    				sum_neg++;
    			} else if (arr[i]==0) {
//    				sum++;
    				sum_z++;
    			}
		   }
		}
		if (sum_neg%2 == 1){
			if (sum_z>0)
				sum+=sum_z;
			else sum=2;
	    } else {
	        sum+=sum_z;
	    }
	}
	printf("%I64d", sum);
	return 0;
}


#include <stdio.h>
#define MAX 100000
#define MAX_NEG -1000000000
#define MAX_POS 1000000000
unsigned long int n,i, sum_pos=0, sum_neg=0, sum=0, result=0;
signed long int arr[MAX], res[MAX] = {0};

int main(){
	scanf("%d", &n);
	if ((n<MAX) && (n>=1)) {
		for (i=0;i<n;i++){
			scanf("%d", &arr[i]);
		}
		for (i=0;i<n;i++){
			if (arr[i]>1) {
				sum_pos+= arr[i]-1;
				res[i] = 1;
			}
			if (arr[i]<-1) {
				sum_neg+= (-1*arr[i])-1;
				res[i] = -1;
			}
			if (arr[i]==0) {
				sum_pos++;
				res[i]=1;
			}
		}
		sum = sum_pos+sum_neg;
		for (i=1;i<n;i++) {
			result = res[i]*res[i-1];
		}
		if (result == -1){
			sum+=-2;
		}

		printf("%d", sum);
	} else {
		printf("%d", sum);
	}
	return 0;
}


#include <stdio.h>
#define MAX 100000
#define MAX_NEG -1000000000
#define MAX_POS 1000000000
unsigned long int n,i, sum_pos=0, sum_neg=0, sum=0;
signed long int result=1;
signed long int arr[MAX], res[MAX] = {0};

int main(){

	scanf("%d", &n);
	if ((n<MAX) && (n>=1)) {
		for (i=0;i<n;i++){
			scanf("%d", &arr[i]);
		}
		for (i=0;i<n;i++){
			if (arr[i]>=1) {
				sum_pos+= arr[i]-1;
			} else if (arr[i]<=-1) {
				sum_neg+= ((-1*arr[i]) + 1);
				if (arr[i]%2 != 0)
					result *= -1;
			} else if (arr[i]==0) {
				sum_pos++;
			}
		}
		sum = sum_pos+sum_neg;
		if (result == -1){
			if (n==2)
				sum=2;
			else
				sum+=2;
		}
	}
	printf("%d", sum);

	return 0;
}


#include <stdio.h>
#define MAX 100000
#define MAX_NEG -1000000000
#define MAX_POS 1000000000
unsigned long long int n,i, sum_z=0,sum_neg=0,  sum=0l;
signed long int result=1;
signed long int arr[MAX];
int main(){
	scanf("%d", &n);
	if ((n<MAX) && (n>=1)) {
		for (i=0;i<n;i++){
			scanf("%I64d", &arr[i]);
		}
		for (i=0;i<n;i++){
		    if ((arr[i]<=MAX_POS) && (arr[i]>=MAX_NEG)) {
    			if (arr[i]>=1) {
    				sum+= arr[i]-1;
    			} else if (arr[i]<=-1) {
    				sum+= -(arr[i]+1);
    				sum_neg++;
    			} else if (arr[i]==0) {
//    				sum++;
    				sum_z++;
    			}
		   }
		}
		if (sum_neg%2 == 1){
			if (sum_z>0)
				sum+=sum_z;
			else sum+=2;
	    } else {
	        sum+=sum_z;
	    }
	}
	printf("%I64d", sum);
	return 0;
}


#include<stdio.h>

int main() {
    int n;
    scanf("%d",&n);
    int arr[n];
    int neg=0,pos=0,pro=1;
    long sum=0;
    for(int i=0;i<n;i++){
        scanf("%d",&arr[i]);
        if(arr[i]<0){
            sum+=-1-arr[i];neg+=1;arr[i]=-1;pro*=arr[i];
        }
        if(arr[i]>0){
            sum+=arr[i]-1;pos+=1;arr[i]=1;pro*=arr[i];
        }

    }
 //   printf("%d\n",pro);
    if(neg+pos==n){
        if(pro==1){
        printf("%ld",sum);
        }else{
        printf("%ld",sum+2);
        }
    }else{
        for(int i=0;i<n;i++){
            if(arr[i]==0){
                if(pro==1){
                    arr[i]=1;sum+=1;
                }else{
                    arr[i]=-1;sum+=1;
                }
            }
        }
        printf("%ld", sum);
    }
}


#include<stdio.h>

int main() {
    int n;
    scanf("%d",&n);
    int arr[n];
    int sum=0,neg=0,pos=0,pro=1;
    for(int i=0;i<n;i++){
        scanf("%d",&arr[i]);
        if(arr[i]<0){
            sum+=-1-arr[i];neg+=1;arr[i]=-1;pro*=arr[i];
        }
        if(arr[i]>0){
            sum+=arr[i]-1;pos+=1;arr[i]=1;pro*=arr[i];
        }

    }
 //   printf("%d\n",pro);
    if(neg+pos==n){
        if(pro==1){
        printf("%d",sum);
        }else{
        printf("%d",sum+2);
        }
    }else{
        for(int i=0;i<n;i++){
            if(arr[i]==0){
                if(pro==1){
                    arr[i]=1;sum+=1;
                }else{
                    arr[i]=-1;sum+=1;
                }
            }
        }
        printf("%d", sum);
    }

}


#include<stdio.h>
#include<math.h>

int main() {
    int n;
    scanf("%d",&n);
    int arr[n];
    int sum=0,sum1;
    int pro=1,pro1=1;
    int arr1[n];
    for(int i=0;i<n;i++){
        scanf("%d",&arr[i]);
        arr1[i]=arr[i];
        if(arr[i]<0){
            sum+=-1-arr[i];
            arr[i]=-1;
            arr1[i]=-1;
        }else if(arr[i]>0){
        sum+=arr[i]-1;
        arr[i]=1;
        arr1[i]=1;
        }else{
            sum1=sum;
            sum+=1;
            sum1+=1;
            arr[i]=1;
            arr1[i]=-1;
        }
        pro*=arr[i];
        pro1*=arr1[i];
    }
    if(pro!=1){
        sum=sum1;
    }
    printf("%d",sum);

}


#include<stdio.h>
#include<math.h>

int main() {
    int n;
    scanf("%d",&n);
    int arr[n];
    int sum=0;
    for(int i=0;i<n;i++){
        scanf("%d",&arr[i]);
        if(arr[i]<0){
            sum+=-1-arr[i];
            arr[i]=-1;
        }else if(arr[i]>0){
        sum+=arr[i]-1;
        arr[i]=1;
        }else{
            sum+=1;
            arr[i]=1;
        }
    }
    int pro=1;
    for(int i=0;i<n;i++){
        pro*=arr[i];
    }
    if(pro==-1){
        sum+=2;
    }
    printf("%d",sum);

}


#include<stdio.h>
#include<math.h>

int main() {
    int n;
    scanf("%d",&n);
    int arr[n];
    int sum=0;
    for(int i=0;i<n;i++){
        scanf("%d",&arr[i]);
        if(arr[i]<0){
            sum+=-1-arr[i];
            arr[i]=-1;
        }else if(arr[i]>0){
        sum+=arr[i]-1;
        arr[i]=1;
        }else{
            sum+=1;
    }
    }
    printf("%d",sum);
}


#include<stdio.h>

int main() {
    int n;
    scanf("%d",&n);
    int arr[n];
    int neg=0,pos=0,pro=1;
    long long sum=0;
    for(int i=0;i<n;i++){
        scanf("%d",&arr[i]);
        if(arr[i]<0){
            sum+=-1-arr[i];neg+=1;arr[i]=-1;pro*=arr[i];
        }
        if(arr[i]>0){
            sum+=arr[i]-1;pos+=1;arr[i]=1;pro*=arr[i];
        }

    }
 //   printf("%d\n",pro);
    if(neg+pos==n){
        if(pro==1){
        printf("%lld",sum);
        }else{
        printf("%lld",sum+2);
        }
    }else{
        for(int i=0;i<n;i++){
            if(arr[i]==0){
                if(pro==1){
                    arr[i]=1;sum+=1;
                }else{
                    arr[i]=-1;sum+=1;
                }
            }
        }
        printf("%lld", sum);
    }
}


#include<stdio.h>

int main() {
    int n;
    scanf("%d",&n);
    int arr[n];
    int neg=0,pos=0,pro=1;
    long sum=0;
    for(int i=0;i<n;i++){
        scanf("%d",&arr[i]);
        if(arr[i]<0){
            sum+=-1-arr[i];neg+=1;arr[i]=-1;pro*=arr[i];
        }
        if(arr[i]>0){
            sum+=arr[i]-1;pos+=1;arr[i]=1;pro*=arr[i];
        }

    }
 //   printf("%d\n",pro);
    if(neg+pos==n){
        if(pro==1){
        printf("%ld",sum);
        }else{
        printf("%ld",sum+2);
        }
    }else{
        for(int i=0;i<n;i++){
            if(arr[i]==0){
                if(pro==1){
                    arr[i]=1;sum+=1;
                }else{
                    arr[i]=-1;sum+=1;
                }
            }
        }
        printf("%ld", sum);
    }

}


#include<stdio.h>
int main()
{
    long long int n,i,k=0,g=0,s=0;
    scanf("%lld",&n);
    long long int A[n];
    for(i=0;i<n;i++)
    {
        scanf("%lld",&A[i]);
        if(A[i]<0)
        {
            s=s-1-A[i];
            k++;
        }
        else if(A[i]==0)
        {
            s=s+1;
            g=1;
        }
        else
        {
            s=s+A[i]-1;
        }
    }
    if(k%2==1&&(k+g)%2==1)
    {
        printf("%lld\n",s+2);
    }
    else
    {
        printf("%lld\n",s);
    }
    return 0;
}


#include<stdio.h>
int main()
{
    long long int n,i,k=0,s=0;
    scanf("%lld",&n);
    long long int A[n];
    for(i=0;i<n;i++)
    {
        scanf("%lld",&A[i]);
        if(A[i]<0)
        {
            s=s-1-A[i];
            k++;
        }
        else if(A[i]==0)
        {
            s=s+1;
        }
        else
        {
            s=s+A[i]-1;
        }
    }
    if(k%2==1)
    {
        printf("%lld\n",s+2);
    }
    else
    {
        printf("%lld\n",s);
    }
    return 0;
}


#include<stdio.h>
int main()
{
    int n,i,sum=0,zero=0,mi=0;
    scanf("%d",&n);
    int num[n];
    for(i=0; i<n; i++)
    {
        scanf("%d",&num[i]);
    }
    for(i=0; i<n; i++)
    {
        if(num[i]>0)
        {
            sum=sum+num[i]-1;
        }
        else if(num[i]<0)

        {
            sum=sum-1-num[i];
            mi=mi+1;
        }
        else if(num[i]==0)
        {
            zero=zero+1;
        }
    }
    if(mi%2==0&&zero==0)
    {
    	printf("%d\n",sum);
    }
    else if(mi%2==0&&zero!=0)
    {
    	printf("%d\n",sum+zero);
    }
    else if(mi%2!=0&&zero==0)
    {
    	printf("%d\n",sum+2);
    }
    else if(mi%2!=0&&zero!=0)
    {
    	printf("%d\n",sum+1);
    }

}


#include<stdio.h>
int main()
{
   long long int n,i,sum=0,zero=0,mi=0;
    scanf("%lld",&n);
    int num[n];
    for(i=0; i<n; i++)
    {
        scanf("%lld",&num[i]);
    }
    for(i=0; i<n; i++)
    {
        if(num[i]>0)
        {
            sum=sum+num[i]-1;
        }
        else if(num[i]<0)

        {
            sum=sum-1-num[i];
            mi=mi+1;
        }
        else if(num[i]==0)
        {
            zero=zero+1;
        }
    }
    if(mi%2==0&&zero==0)
    {
    	printf("%lld\n",sum);
    }
    else if(mi%2!=0&&zero==0)
    {
    	printf("%lld\n",sum+2);
    }
    else printf("%lld\n",sum+zero);

}


#include<stdio.h>
int main()
{
    int n,i,sum=0,p=0,q=0;
    scanf("%d",&n);
    int num[n];
    for(i=0; i<n; i++)
    {
        scanf("%d",&num[i]);
    }
    for(i=0; i<n; i++)
    {
        if(num[i]<0)
        {
            sum=sum-1-num[i];
            p=p+1;
        }
        else if(num[i]==0)
        {
            q=q+1;
        }
        else
            sum=sum+num[i]-1;
    }
    if(p%2==0)
    {
        printf("%d\n",sum+q);
    }
    else printf("%d\n",sum+1+p+q);
}


#include<stdio.h>
int main()
{
   long long int n,i,sum=0,zero=0,mi=0;
    scanf("%lld",&n);
    int num[n];
    for(i=0; i<n; i++)
    {
        scanf("%lld",&num[i]);
    }
    for(i=0; i<n; i++)
    {
        if(num[i]>0)
        {
            sum=sum+num[i]-1;
        }
        else if(num[i]<0)

        {
            sum=sum-1-num[i];
            mi=mi+1;
        }
        else if(num[i]==0)
        {
            zero=zero+1;
        }
    }
    if(mi%2==0&&zero==0)
    {
    	printf("%lld\n",sum);
    }
    else if(mi%2==0&&zero!=0)
    {
    	printf("%lld\n",sum+zero);
    }
    else if(mi%2!=0&&zero==0)
    {
    	printf("%lld\n",sum+2);
    }
    else if(mi%2!=0&&zero!=0)
    {
    	printf("%lld\n",sum+1);
    }

}