"Everything in the universe is balanced. Every disappointment you face in life will be balanced by something good for you! Keep going, never give up."
Let's call a string balanced if all characters that occur in this string occur in it the same number of times.
You are given a string $S$; this string may only contain uppercase English letters. You may perform the following operation any number of times (including zero): choose one letter in $S$ and replace it by another uppercase English letter. Note that even if the replaced letter occurs in $S$ multiple times, only the chosen occurrence of this letter is replaced.
Find the minimum number of operations required to convert the given string to a balanced string.

-----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$.

-----Output-----
For each test case, print a single line containing one integer ― the minimum number of operations.

-----Constraints-----
- $1 \le T \le 10,000$
- $1 \le |S| \le 1,000,000$
- the sum of $|S|$ over all test cases does not exceed $5,000,000$
- $S$ contains only uppercase English letters

-----Subtasks-----
Subtask #1 (20 points):
- $T \le 10$
- $|S| \le 18$
Subtask #2 (80 points): original constraints

-----Example Input-----
2
ABCB
BBC

-----Example Output-----
1
1

-----Explanation-----
Example case 1: We can change 'C' to 'A'. The resulting string is "ABAB", which is a balanced string, since the number of occurrences of 'A' is equal to the number of occurrences of 'B'.
Example case 2: We can change 'C' to 'B' to make the string "BBB", which is a balanced string.

```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 = 'def solve_equal(lst,no_of_elem_in_group):\n dist = 0\n for i in lst:\n  if i > no_of_elem_in_group:\n   dist += abs(no_of_elem_in_group-i)\n return dist\n\ndef solve(lst,l,no_of_group):\n no_of_elem_in_group = l//no_of_group\n list_len = len(lst)\n dist = 0\n if no_of_group >= list_len:\n  return solve_equal(lst,no_of_elem_in_group)\n\n else:  # no_of_group < list_len\n  lst.sort()\n  dist = sum(lst[0:list_len-no_of_group])\n  return dist + solve_equal(lst,no_of_elem_in_group)\n\nT = int(input())\nfor z in range(T):\n dct = {}\n s = list(input())\n for elem in s:\n  try:\n   dct[elem] += 1\n  except:\n   dct[elem] = 1\n   \n lst = list(dct.values())\n l = len(s)\n mn = 99999999999999999\n for i in range(1,min(l+1,27)):\n  no_of_group = i\n  if l%no_of_group == 0:\n   lst2 = lst[:]\n   tmp = solve(lst2,l,no_of_group)\n   #print(i,tmp)\n   if tmp < mn:\n    mn = tmp\n print(mn)\n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 13477