Timer is Running

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.

abnandi04 | 801 |

KshamaGupta | 412 |

srivastavad270 | 223 |

bhavyapratap56 | 206 |

anshusingh20112001 | 181 |

abnandi04 | 776 |

KshamaGupta | 296 |

srivastavad270 | 223 |

bhavyapratap56 | 206 |

afreensartaj131 | 170 |

blackshadows | 5362 |

Ibrahim Nash | 5244 |

akhayrutdinov | 5111 |

mb1973 | 4976 |

Quandray | 4748 |

Login to report an issue on this page.