Flip Sorting

 Chef has a binary string 

of length . Chef can perform the following operation on

any number of times (possibly zero):

  • Choose a number
() that hasn't been chosen in any previous operation and flip any substring of having length (i.e. change all s to s and all s to s in any substring of having length
  • ).

Chef wants to sort

in non-decreasing order using any sequence of operations. Can you help Chef find such a sequence of operations?

If there are multiple answers, print any.

Input Format

  • The first line contains a single integer
  • - the number of test cases. Then the test cases follow.
  • The first line of each test case contains an integer
  • - the length of the binary string
  • .
  • The second line of each test case contains a binary string
  • of length containing s and
    • s only.

    Output Format

    For each test case,

    • Output in the first line
  • - the number of operations applied.
  • In each of the following
  • lines, output two integers and - the starting index of the substring selected and the length of the substring. (Note that
    • selected should not be used in any of the previous operations)

    Constraints

    Sample Input 1

    3
    6
    110111
    9
    110110111
    5
    00111
    

    Sample Output 1

    1
    1 2
    2
    1 2
    4 3
    0
    

    Explanation

    Test Case 1: The operations applied are as follows:

    .

    Test Case 2: The operations applied are as follows:

    .

    Comments

    Popular posts from this blog

    Walmart Sparkplug 2022 | 150 students will be selected for summer internship | ₹1-1.1 lakh monthly

    Flipkart Runway: Season 3 | 2025 | Internship

    Python for Data Science NPTEL Assignment Solutions Week 4 2022

    GATE 2022 Answer Key Release Date Announced; Details Here