A new locking device has been built.
The device consists of switches s1,s2,…,sN, each of which is either open or closed. The state of a switch is 0 or 1, so the state of the device is an array of N bits.
The table below shows an example array with 8 switches.
| switch | s1 | s2 | s3 | s4 | s5 | s6 | s7 | s8 |
|---|---|---|---|---|---|---|---|---|
| state | 0 | 1 | 1 | 0 | 1 | 1 | 0 | 0 |
In an array of N switches, the rules for operating a switch are as follows.
The device opens when every switch is 0.
Following the rules above, find the minimum number of toggles that turns the given array into all zeros.
The table below is a shortest sequence that turns the array 1111 into 0000. The array 1111 needs at least 10 toggles.
| toggles | s1 | s2 | s3 | s4 |
|---|---|---|---|---|
| 0 | 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 0 | 1 |
| 2 | 1 | 1 | 0 | 0 |
| 3 | 0 | 1 | 0 | 0 |
| 4 | 0 | 1 | 0 | 1 |
| 5 | 0 | 1 | 1 | 1 |
| 6 | 0 | 1 | 1 | 0 |
| 7 | 0 | 0 | 1 | 0 |
| 8 | 0 | 0 | 1 | 1 |
| 9 | 0 | 0 | 0 | 1 |
| 10 | 0 | 0 | 0 | 0 |
The first line contains the number of test cases T.
Each test case follows on its own line as a bit string B. The first bit of B is s1 and the last bit is sN.
The length of B satisfies 2≤∣B∣≤31.
For each test case, print on one line the minimum number of toggles needed to turn every switch to 0.