Problem: You are given a binary string consisting of only characters 0 and/or 1.
You can perform several operations on this string (possibly zero). There are two types of operations:
- choose two consecutive elements and swap them. In order to perform this operation, you pay coins;
- choose any element from the string and remove it. In order to perform this operation, you pay coins.
Your task is to calculate the minimum number of coins required to sort the string in non-decreasing order (i. e. transform so that , where is the length of the string after applying all operations). An empty string is also considered sorted in non-decreasing order.
Input Format: The first line contains a single integer () — the number of test cases.
The only line of each test case contains the string (), consisting of only characters 0 and/or 1.
The sum of lengths of all given strings doesn't exceed .
Output Format: For each test case, print a single integer — the minimum number of coins required to sort the string in non-decreasing order.
Note: In the first example, you have to remove the -st element, so the string becomes equal to 00.
In the second example, the string is already sorted.
In the third example, you have to swap the -nd and the -rd elements, so the string becomes equal to 0011.
In the fourth example, you have to swap the -rd and the -th elements, so the string becomes equal to 00011101, and then remove the -th element, so the string becomes equal to 0001111.
In the fifth example, you have to remove the -st element, so the string becomes equal to 001101, and then remove the -th element, so the string becomes equal to 00111.
In the sixth example, the string is already sorted.