Shubham has a binary string $s$. A binary string is a string containing only characters "0" and "1".

He can perform the following operation on the string any amount of times:   Select an index of the string, and flip the character at that index. This means, if the character was "0", it becomes "1", and vice versa. 

A string is called good if it does not contain "010" or "101" as a subsequence  — for instance, "1001" contains "101" as a subsequence, hence it is not a good string, while "1000" doesn't contain neither "010" nor "101" as subsequences, so it is a good string.

What is the minimum number of operations he will have to perform, so that the string becomes good? It can be shown that with these operations we can make any string good.

A string $a$ is a subsequence of a string $b$ if $a$ can be obtained from $b$ by deletion of several (possibly, zero or all) characters.


-----Input-----

The first line of the input contains a single integer $t$ $(1\le t \le 100)$ — the number of test cases.

Each of the next $t$ lines contains a binary string $s$ $(1 \le |s| \le 1000)$.


-----Output-----

For every string, output the minimum number of operations required to make it good.


-----Example-----
Input
7
001
100
101
010
0
1
001100

Output
0
0
1
1
0
0
2



-----Note-----

In test cases $1$, $2$, $5$, $6$ no operations are required since they are already good strings.

For the $3$rd test case: "001" can be achieved by flipping the first character  — and is one of the possible ways to get a good string.

For the $4$th test case: "000" can be achieved by flipping the second character  — and is one of the possible ways to get a good string.

For the $7$th test case: "000000" can be achieved by flipping the third and fourth characters  — and is one of the possible ways to get a good string.

Difficulty: interview

Starter code:

Solutions:
T = int(input())

for _ in range(T):
    s = input()
    n = len(s)
    res = 10 ** 100
    for i in range(n + 1):
        p,q = s[:i], s[i:]
        res = min(res, p.count('0') + q.count('1'))
        res = min(res, p.count('1') + q.count('0'))
    print(res)


import sys, random, math
from bisect import bisect_left, bisect_right
input = sys.stdin.readline

def main():
    inf = 10 ** 20

    t = int(input())
#    t, a, b = map(int, input().split())
#    t = 1
    
    for _ in range(1, t+1):
    #    print("Case #{}: ".format(_), end = '')
        
        s = input().strip()
        ps0, ps1 = [0], [0]
        for i in range(len(s)):
            if(s[i] == '0'):
                ps0.append(ps0[-1]+1)
                ps1.append(ps1[-1])
            else:
                ps0.append(ps0[-1])
                ps1.append(ps1[-1]+1)
        ans = inf
        for i in range(len(s)):
            ans = min(ans, (ps0[i] - ps0[0]) + (ps1[len(s)] - ps1[i]))
            ans = min(ans, (ps1[i] - ps1[0]) + (ps0[len(s)] - ps0[i]))
        
        print(ans)
        
main()

N, = list(map(int, input().split()))
for _ in range(N):
    s = input().strip()
    x = [0]*(len(s)+1)
    y = [0]*(len(s)+1)
    for i in range(1, len(s)+1):
        if s[i-1] == "1":
            x[i] = x[i-1]+1
            y[i] = y[i-1]
        else:
            x[i] = x[i-1]
            y[i] = y[i-1]+1
    r1=r2=len(s)
    for i in range(1, len(s)+1):
        r1=min(r1, x[i-1]+(y[-1]-y[i]))
        r2=min(r2, y[i-1]+(x[-1]-x[i]))
    print(min(r1, r2))


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
  s = input().rstrip()
  n = len(s)
  x = s.count("1")
  op1 = [n]*n
  cnt = 0
  ans = n
  for i in range(n):
    if s[i] == "1":
      cnt += 1
    op1[i] = (i+1)-cnt+x-cnt
    ans = min(ans,op1[i],n-op1[i])
  print(ans)


"""
Author: Q.E.D
Time: 2020-05-31 09:41:24
"""
T = int(input())
for _ in range(T):    
    s = input()
    one = [0]
    zero = [0]
    for i, c in enumerate(s):
        if c == '0':
            zero.append(zero[-1] + 1)
            one.append(one[-1])
        else:
            one.append(one[-1] + 1)
            zero.append(zero[-1])
    n = len(s)
    ans = n
    for i in range(1, n + 1):
        ans = min(ans, zero[i] + one[n] - one[i])
        ans = min(ans, one[i] + zero[n] - zero[i])
    print(ans)

import sys
input = sys.stdin.readline

t = int(input())
for _ in range(t):
    s = input().strip()
    n = len(s)

    tot0 = 0
    tot1 = 0
    for c in s:
        if c == '0':
            tot0 += 1
        else:
            tot1 += 1
    
    best = min(tot0, tot1)


    cur0 = 0
    cur1 = 0
    for c in s:
        if c == '0':
            cur0 += 1
        else:
            cur1 += 1

        best = min((best, cur0 + (tot1 - cur1), cur1 + (tot0 - cur0)))

    print(best)
        
    


q = int(input())
for ii in range(q):
	s = input()
	n = len(s)
	wyn = 5298528589245892
	wyn = min(wyn, s.count('0'))
	wyn = min(wyn, s.count('1'))
	#00001111
	cyk = s.count('0')
	for i in range(n):
		if s[i] == '1':
			cyk +=1
		else:
			cyk -= 1
		wyn = min(wyn,cyk)
	cyk = s.count('1')
	for i in range(n):
		if s[i] == '0':
			cyk += 1
		else:
			cyk -= 1
		wyn = min(wyn,cyk)
	print(wyn)

T = int(input())

def solve():
    S = input()
    total_0 = 0
    total_1 = 0

    for i in range(len(S)):
        if S[i] == '0':
            total_0 += 1
        else:
            total_1 += 1
    ans = len(S)
    count_0, count_1 = 0,0
#    print(total_0,total_1)
    for i in range(len(S)):
        # all 0 then all 1
        ans01 = count_1 + (total_0-count_0)
        # all 1 then all 0
        ans10 = count_0 + (total_1-count_1)

        if S[i] == '0':
            count_0 += 1
        else:
            count_1 += 1

        ans = min(ans,ans01,ans10)
    print(ans)

for _ in range(T):
    solve()


from math import *

def r1(t):
    return t(input().strip())

def r2(t):
    return [t(i) for i in input().strip().split()]

def r3(t):
    return [t(i) for i in input().strip()]

for _ in range(int(input())):
    t = r3(int)
    ps = 0
    ss = sum(t)
    n = len(t)
    ans = n
    for i in range(0, n):
        if (i > 0):
            ss -= t[i - 1]
            ps += t[i - 1]
        res = min(i - ps + ss, ps + n - i - ss)
        ans = min(res, ans)

    print(ans)
    


for _ in range(int(input())):
    A = str(input())
    x = 0
    for i in range(len(A)):
        if A[i] == '1':
            x += 1
    minn = x
    xx = x
    for i in range(len(A)):
        if A[i] == '1':
            xx -= 1
        else:
            xx += 1
        minn = min(minn, xx)
    xx = len(A) - x
    minn = min(minn, len(A) - x)
    for i in range(len(A)):
        if A[i] == '0':
            xx -= 1
        else:
            xx += 1
        minn = min(minn, xx)
    print(minn)

import sys
readline = sys.stdin.readline

T = int(readline())
Ans = [None]*T
for qu in range(T):
    S = list(map(int, readline().strip()))
    N = len(S)
    so = S.count(1)
    ans = min(so, N-so)

    table = S[:]
    for i in range(1, N):
        table[i] += table[i-1]
    
    for i in range(N):
        one = table[i]
        zero = i+1-one
        
        no = so - one
        nz = N-(i+1)-no
        
        ans = min(ans, no+zero, one+nz)
    Ans[qu] = ans

print('\n'.join(map(str, Ans)))