Problem: Let's define a cyclic shift of some string as a transformation from into . In other words, you take one last character and place it before the first character while moving all other characters to the right.
You are given a binary string (a string consisting of only 0-s and/or 1-s).
In one operation, you can choose any substring () and cyclically shift it. The cost of such operation is equal to (or the length of the chosen substring).
You can perform the given operation any number of times. What is the minimum total cost to make sorted in non-descending order?
Input Format: The first line contains a single integer () — the number of test cases.
The first and only line of each test case contains a binary string (; {0, 1}) — the string you need to sort.
Additional constraint on the input: the sum of lengths of strings over all test cases doesn't exceed .
Output Format: For each test case, print the single integer — the minimum total cost to make string sorted using operation above any number of times.
Note: In the first test case, you can choose the whole string and perform a cyclic shift: 10 01. The length of the substring is , so the cost is .
In the second test case, the string is already sorted, so you don't need to perform any operations.
In the third test case, one of the optimal strategies is the next:
- choose substring : 11000 01100;
- choose substring : 01100 00110;
- choose substring : 00110 00011.