Intermediate1100

Binary Cut

Codeforces
View on Codeforces
Time: 2 secondsMemory: 256 megabytes

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:

^ A binary string is a string consisting of characters 0 and 1. A sorted binary string is a binary string such that all characters 0 come before all characters 1.

Input

The first line contains a single integer t (1 ≤ t ≤ 500) — the number of test cases.The only line of each test case contains a single string s (1 ≤ |s| ≤ 500) consisting of characters 0 and 1, where |s| denotes the length of the string s.

Output

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.

Examples

Input
6 11010 00000000 1 10 0001111 0110
Output
3 1 1 2 1 2

Note

The first test case is pictured in the statement. It can be proven that you can't use fewer than 3 pieces.In the second and third test cases, the binary string is already sorted, so only 1 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 01.

dpgreedyimplementationsortingsstrings

Discussion

(0)
Sign in to join the discussion.
Loading editor...
0 online