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.

vamsikrishna55 | 162 |

Vagesh Verma | 154 |

UrGuru | 133 |

chaolinyu | 98 |

Akhil varma | 97 |

abducodes | 650 |

harshtyagi36 | 304 |

highway_to_hell | 252 |

Akhil varma | 250 |

arpit_anshuman | 250 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.