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.

RatneshTiwari3 | 24 |

AnmolPassi | 20 |

Swords | 20 |

baranwalsuraj96 | 17 |

tarun711 | 16 |

Bishnu Dev Panda | 727 |

yk12 | 512 |

DevMittal | 472 |

okayboss | 458 |

VijethaShastri | 431 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4921 |

Quandray | 4547 |

Login to report an issue on this page.