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.

mantan_g | 267 |

tushki | 198 |

aksht7 | 182 |

ayush1101 | 128 |

namansharmacse17 | 110 |

ARUN_PUNDIR | 730 |

manishgupta8497 | 627 |

AMAN__JAIN | 625 |

Abhimanyu_kumar | 562 |

AJ786 | 541 |

blackshadows | 5335 |

Ibrahim Nash | 5223 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4584 |

Login to report an issue on this page.