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 = 'import numpy as np\ni8 = np.int64\n\n\ndef solve_core(a, n):\n res = 0\n s1 = a[0]\n s2 = a[1]\n s3 = np.sum(a[2::2])\n for i in range(1, n, 2):\n  t3 = s3\n  for j in range(i + 1, n + 1, 2):\n   res = max(res, s1 + s2 + t3)\n   s2 += a[j + 1]\n   t3 -= a[j]\n  s1 += a[i + 1]\n  s2 = a[i + 2]\n  s3 -= a[i + 1]\n return res\n\n\ndef solve(S):\n N = len(S)\n a = np.zeros(N + 2, i8)\n i = 0\n prev = S[0]\n count = 0\n for c in S:\n  if c == prev:\n   count += 1\n  else:\n   a[i] = count\n   prev = c\n   count = 1\n   i += 1\n else:\n  a[i] = count\n  i += 1\n if i < 4:\n  return 0\n else:\n  res = max(solve_core(a, i), solve_core(a[1:], i - 1))\n  return N - res\n\ndef main():\n T = int(input())\n for _ in range(T):\n  S = input()\n  print(solve(S))\n\ndef __starting_point():\n main()\n__starting_point()'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 6166002