Given a binary string S which only contains '0' and '1' such that the '0' or '1' at the 1^{st }position is just next to '0' or '1' at the last position i.e. string is cyclic. Your task is to re arrange the string such that all the '1' in the string are next to each other (Note : the string is cyclic ).

You can choose any '1' in the string and swap its position with the first '1' in any of the two direction.

Find the minimum number of moves in which the task can be done.

**Input:**

First line of the test case contains an integer T, denoting number of test cases. Following T lines contains a string S each.

**Output:**

For each of the test case print the answer in separate lines.

**Constraints:**

1<=T<10^3

1<=|S|<=10^4

S will consist of only '0' and '1'.

S will contain minimum of one '1'.

**Example:**

**Input:**

1

010110101

**Output:**

3

**Explanation:**

In the first move 01011010**1 ** is changed to 0101101**1**0. In the second move 0101101**1**0 is changed to 01011**1**100. In the third move 0**1**0111100 is change to 00**1**111100.

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

hardikJain5 | 258 |

CodeBuddy | 250 |

bhatabhi554 | 232 |

Akkki111 | 197 |

clone | 174 |

KshatriyaYash | 1932 |

nikhil_sojan | 1374 |

lonecoder | 1236 |

SumitSingh27 | 1127 |

mazumderrohit8 | 1124 |

blackshadows | 5327 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4591 |

Quandray | 4444 |

Login to report an issue on this page.