You are given a sequence of non-negative integers $A_1, A_2, \ldots, A_N$. At most once, you may choose a non-negative integer $X$ and for each valid $i$, change $A_i$ to $A_i \oplus X$ ($\oplus$ denotes bitwise XOR).
Find the minimum possible value of the sum of all elements of the resulting sequence.

-----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 line of the input contains a single integer $N$.
- The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$.

-----Output-----
For each test case, print a single line containing one integer ― the minimum possible sum.

-----Constraints-----
- $1 \le T \le 1,000$
- $1 \le N \le 10^5$
- $1 \le A_i \le 10^9$ for each valid $i$
- the sum of $N$ over all test cases does not exceed $10^6$

-----Subtasks-----
Subtask #1 (50 points):
- $1 \le N \le 10^3$
- $1 \le A_i \le 10^3$ for each valid $i$
Subtask #2 (50 points): original constraints

-----Example Input-----
3
5
2 3 4 5 6
4
7 7 7 7
3
1 1 3

-----Example Output-----
14
0
2

-----Explanation-----
Example case 1: If we choose $X = 6$, the sequence becomes $(4, 5, 2, 3, 0)$.
Example case 2: We can choose $X = 7$ to make all elements of the resulting sequence equal to $0$.
Example case 3: We can choose $X = 1$. The sequence becomes $(0, 0, 2)$, with sum $2$.

```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\n# def more_frequent_item(lst):\n#     new_lst = []\n#     times = 0\n#     for item in lst:\n#         count_num = lst.count(item)\n#         new_lst.append(count_num)\n#         times = max(new_lst)\n#     key = max(lst, key=lst.count)\n#     return [key, times]\n# try:\n#     t = int(input())\n#     for _ in range(t):\n#         jk = int(input())\n#         lst = list(map(int, input().split()))\n#         Nlst = [0]*len(lst)\n#         Nlst2 = [0]*len(lst)\n#         z = more_frequent_item(lst)\n#         if z[0] * z[1] > max(lst):\n#             x = z[0]\n#         else:\n#             x = max(lst)\n#         for i in range(len(lst)):\n#             Nlst[i] = lst[i] ^ x\n#         for j in range(len(lst)):\n#             Nlst2[j] = lst[j] ^ z[0]\n#         print(min(sum(Nlst), sum(Nlst2)))\n# except:\n#     pass4\n\nfrom math import log2 \ndef findX(arr, n): \n itr = arr[0] \n for i in range(len(arr)): \n  if(arr[i] > itr): \n   itr = arr[i] \n p = int(log2(itr)) + 1\n X = 0\n for i in range(p): \n  count = 0\n  for j in range(n): \n   if (arr[j] & (1 << i)): \n    count += 1\n  if (count > int(n / 2)): \n   X += 1 << i \n sum = 0\n for i in range(n): \n  sum += (X ^ arr[i]) \n print(sum)\ndef __starting_point(): \n t = int(input())\n for _ in range(t):\n  ss = int(input())\n  arr = list(map(int, input().split()))\n  n = len(arr) \n  findX(arr, n)\n__starting_point()'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 13619