Problem: You are given a binary string. Please find the minimum number of pieces you need to cut it into, so that the resulting pieces can be rearranged into a sorted binary string.
Note that:
- each character must lie in exactly one of the pieces;
- the pieces must be contiguous substrings of the original string;
- you must use all the pieces in the rearrangement.
A binary string is a string consisting of characters and . A sorted binary string is a binary string such that all characters come before all characters .
Input Format: The first line contains a single integer () — the number of test cases.
The only line of each test case contains a single string () consisting of characters and , where denotes the length of the string .
Output Format: For each test case, output a single integer — the minimum number of pieces needed to be able to rearrange the string into a sorted binary string.
Note: The first test case is pictured in the statement. It can be proven that you can't use fewer than pieces.
In the second and third test cases, the binary string is already sorted, so only piece is needed.
In the fourth test case, you need to make a single cut between the two characters and rearrange them to make the string .