class Case:
    def __init__(self, size, moves, string):
        self.size = size
        self.moves = moves
        self.string = string


SPACE = ' '
ZERO = '0'
ONE = '1'


def get_case():
    line_elements = input().split(SPACE)
    size = int(line_elements[0])
    moves = int(line_elements[1])
    string = list(input())
    return Case(size, moves, string)


def swap(index, next_zero_index, string):
    string[index], string[next_zero_index] = string[next_zero_index], string[index]
    return string


def solve(case):
    next_zero_index = 0
    remaining_moves = case.moves
    string = case.string
    for index in range(case.size):
        if remaining_moves == 0:
            break

        current_char = string[index]
        if index == 0:
            if current_char == ZERO:
                next_zero_index += 1
            continue

        previous_char = string[index - 1]
        need_to_move = current_char == ZERO and previous_char == ONE
        if need_to_move:
            desired_moves = index - next_zero_index
            allowed_moves = min(remaining_moves, desired_moves)
            target_index = next_zero_index + abs(desired_moves - allowed_moves)
            string = swap(index, target_index, string)
            remaining_moves -= allowed_moves
            next_zero_index += 1
        elif current_char == ZERO:
            next_zero_index += 1
    return string


if __name__ == "__main__":
    number_of_cases = int(input())
    for i in range(number_of_cases):
        case = get_case()
        solvedList = solve(case)
        solution = "".join(solvedList)
        print(solution)

@@ -366,23 +366,10 @@
 def 
-swap(index, nex
+ge
 t_ze
@@ -370,28 +370,29 @@
 get_zero_ind
-ex, 
+ices(
 string):%0A   
@@ -396,87 +396,131 @@
     
-string%5B
+zero_indices = %5B%5D%0A    for 
 index
-%5D
 , 
-string%5Bnext_zero_index%5D = string%5Bnext_zero_index%5D, string%5B
+char in enumerate(string):%0A        if char == ZERO:%0A            zero_indices.append(
 index
-%5D
+)
 %0A   
@@ -531,42 +531,110 @@
 urn 
-string%0A%0A%0Adef solve(case
+zero_indices%0A%0A%0Adef get_zero_indices_after_moves(initial_zero_indices, ideal_indices, moves
 ):%0A    
-next
+final
 _zer
@@ -642,196 +642,255 @@
 _ind
-ex = 0
+ices = %5B%5D
 %0A    
-remaining_moves = case.moves%0A    string = case.string%0A    for index in range(case.size):%0A        if remaining_moves == 0:%0A            break%0A%0A        current_char = string%5Bindex%5D
+if len(initial_zero_indices) != len(ideal_indices):%0A        raise ValueError('initial_zero_indices and ideal_indices should be of '%0A                         'the same length')%0A    for i, zero_index in enumerate(initial_zero_indices):
 %0A   
@@ -901,16 +901,15 @@
  if 
-index ==
+moves %3C
  0:%0A
@@ -924,132 +924,226 @@
     
-if current_char == ZERO:%0A                next_zero_index += 1%0A            continue%0A%0A        previous_char = string%5Bindex - 1
+raise ValueError('moves should be %3E= 0')%0A        if moves == 0:%0A            final_zero_indices.extend(initial_zero_indices%5Bi:%5D)%0A            return final_zero_indices%0A        desired_moves = zero_index - ideal_indices%5Bi
 %5D%0A  
@@ -1152,134 +1152,139 @@
     
-need_to
+allowed
 _move
+s
  = 
-current_char == ZERO and previous_char == ONE%0A        if need_to_move:%0A            desired_moves = index - next
+min(moves, desired_moves)%0A        new_zero_index = zero_index - allowed_moves%0A        final_zero_indices.append(new
 _zer
@@ -1290,16 +1290,17 @@
 ro_index
+)
 %0A       
@@ -1304,255 +1304,384 @@
     
-    allowed_moves = min(remaining_moves, desired_moves)%0A            target_index = next_zero_index + abs(desired_moves - allowed_moves)%0A            string = swap(index, target_index, string)%0A            remaining_moves -= allowed
+moves = moves - allowed_moves%0A    return final_zero_indices%0A%0A%0Adef add_zeros(ones, zero_indices):%0A    for index in zero_indices:%0A        ones%5Bindex%5D = ZERO%0A    return ones%0A%0A%0Adef solve(case):%0A    initial_zero_indices = get_zero_indices(case.string)%0A    ideal_zero_indices = list(range((len(initial_zero_indices))))%0A    final_zero_indices = get_zero_indices_after
 _moves
+(
 %0A
-   
         
  nex
@@ -1668,37 +1668,39 @@
 _moves(%0A        
- next
+initial
 _zero_index += 1
@@ -1696,67 +1696,111 @@
 _ind
-ex += 1%0A        elif current_char == ZERO:%0A            next
+ices, ideal_zero_indices, case.moves)%0A    ones = %5BONE%5D * case.size%0A    response = add_zeros(ones, final
 _zer
@@ -1808,15 +1808,13 @@
 _ind
-ex += 1
+ices)
 %0A   
@@ -1821,22 +1821,24 @@
  return 
-string
+response
 %0A%0A%0Aif __

Simplify algorithm