#UnknownID12. JIXMPII5JUgT100#-`]

JIXMPII5JUgT100#-`]

Statement

Let's define a cyclic shift of some string s s as a transformation from s1s2sn1sn s_1 s_2 \dots s_{n-1} s_{n} into sns1s2sn1 s_{n} s_1 s_2 \dots s_{n-1} . In other words, you take one last character sn s_n and place it before the first character while moving all other characters to the right.

You are given a binary string s s (a string consisting of only 0-s and/or 1-s).

In one operation, you can choose any substring slsl+1sr s_l s_{l+1} \dots s_r ( 1l<rs 1 \le l < r \le |s| ) and cyclically shift it. The cost of such operation is equal to rl+1 r - l + 1 (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 s s sorted in non-descending order?

Format

Input

The first line contains a single integer t t ( 1t104 1 \le t \le 10^4 ) — the number of test cases.

The first and only line of each test case contains a binary string s s ( 2s2105 2 \le |s| \le 2 \cdot 10^5 ; si s_i \in {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 2105 2 \cdot 10^5 .

Output

For each test case, print the single integer — the minimum total cost to make string sorted using operation above any number of times.

Sample

5
10
0000
11000
101011
01101001
2
0
9
5
11