We say that a binary string (a string containing only characters '0' and '1') is pure if it does not contain either of the strings "0101" or "1010" as a subsequence.
Recall that string T is a subsequence of string S if we can delete some of the letters of S (possibly none) such that the resulting string will become T.
You are given a binary string $S$ with length $N$. We want to make this string pure by deleting some (possibly zero) characters from it. What is the minimum number of characters we have to delete?

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first and only line of each test case contains a single string $S$ with length $N$.

-----Output-----
For each test case, print a single line containing one integer — the minimum number of characters we have to delete from $S$.

-----Constraints-----
- $1 \le T \le 40$
- $1 \le N \le 1,000$
- $S$ contains only characters '0' and '1'

-----Example Input-----
4
010111101
1011100001011101
0110
111111

-----Example Output-----
2
3
0
0

-----Explanation-----
Example case 1: We can delete the first and third character of our string. There is no way to make the string pure by deleting only one character.
Example case 3: The given string is already pure, so the answer is zero.

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = '# cook your dish here\nimport math;\nfrom math import gcd,sqrt,floor,factorial,ceil\nfrom bisect import bisect_left,bisect_right\nimport bisect;\nimport sys;\nfrom sys import stdin,stdout\nimport os\nsys.setrecursionlimit(pow(10,7))\nimport collections\nfrom collections import defaultdict,Counter\nfrom statistics import median\n# input=stdin.readline\n# print=stdout.write\nfrom queue import Queue\ninf = float("inf")\nfrom operator import neg;\nmod=pow(10,9)+7\ndef fun(l):\n m=[[l[0]]]\n for i in range(1,n):\n  if m[-1][-1]==l[i]:\n   m[-1]+=[l[i]]\n  else:\n   m.append([l[i]])\n count=[]\n for i in range(len(m)):\n  count.append(len(m[i]))\n return count;\ndef function(l1,index,prev,count):\n tuple=(index,prev,count)\n if tuple in dict:\n  return dict[tuple]\n n=len(l1)\n if index==n:\n  return 0;\n if count>=3:\n  if index%2==prev:\n   dict[tuple]=function(l1,index+1,prev,count)\n   return function(l1,index+1,prev,count)\n  else:\n   dict[tuple]=l1[index]+function(l1,index+1,prev,count);\n   return dict[tuple]\n if prev==None:\n  skip=l1[index]+function(l1,index+1,prev,count)\n  not_skip=function(l1,index+1,index%2,count+1)\n  maxa=min(skip,not_skip)\n  dict[tuple]=maxa\n  return maxa;\n\n if index%2==prev:\n  dict[tuple]=function(l1,index+1,index%2,count)\n  return dict[tuple]\n if index%2!=prev:\n  skip=l1[index]+function(l1,index+1,prev,count)\n  not_skip=function(l1,index+1,index%2,1+count)\n  maxa = min(skip, not_skip)\n  dict[tuple]=maxa\n  return maxa;\n\nt=int(input())\nfor i in range(t):\n s=input()\n l=list(s)\n n=len(l)\n l=[int(i) for i in l]\n l1=fun(l)\n dict=defaultdict(int)\n theta=function(l1,0,None,0)\n print(theta)\n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 287668