You are given an array $a$ of length $n$ consisting of integers. You can apply the following operation, consisting of several steps, on the array $a$ zero or more times:

you select two different numbers in the array $a_i$ and $a_j$;

you remove $i$-th and $j$-th elements from the array.

For example, if $n=6$ and $a=[1, 6, 1, 1, 4, 4]$, then you can perform the following sequence of operations:

select $i=1, j=5$. The array $a$ becomes equal to $[6, 1, 1, 4]$;

select $i=1, j=2$. The array $a$ becomes equal to $[1, 4]$.

What can be the minimum size of the array after applying some sequence of operations to it?


-----Input-----

The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.

The first line of each test case contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) is length of the array $a$.

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.


-----Output-----

For each test case, output the minimum possible size of the array after applying some sequence of operations to it.


-----Examples-----

Input
5
6
1 6 1 1 4 4
2
1 2
2
1 1
5
4 5 4 5 4
6
2 3 2 1 3 1
Output
0
0
2
1
0


-----Note-----

None

Difficulty: MEDIUM

Solutions:
import sys
from os import path

def open_inputs():
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')

def get_int():
	return int(sys.stdin.readline().strip())

def get_ints():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def printf(_s):
	sys.stdout.write(str(_s))

def main():
	open_inputs()
	cases = get_int()
	for case in range(cases):
		get_int()
		numbers = get_ints()
		numbers.sort()
		n = int(len(numbers) / 2)
		numbers_one = numbers[n:]
		numbers_two = numbers[:n]
		matches = 0
		while len(numbers_one) and len(numbers_two):
			one = numbers_one.pop()
			two = numbers_two.pop()
			if one == two:
				matches += 2
		matches += len(numbers_one) + len(numbers_two)
		printf(str(matches) + '\n')
main()


t = int(input())
while t > 0:
	t = t - 1
	dict = {}
	n = int(input())
	L = input().split()
	Max = 0
	for x in L:
		if x not in dict.keys():
			dict[x] = 1
		else:
			dict[x] = dict[x] + 1
		if dict[x] > Max:
			Max = dict[x]
	if 2 * Max > n:
		print(2 * Max - n)
	elif n % 2 == 0:
		print(0)
	else:
		print(1)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	i = n // 2 - 1
	j = n - 1
	ans = 0
	while i >= 0 and j >= n // 2:
		if l[i] != l[j]:
			ans += 2
		i -= 1
		j -= 1
	print(n - ans)


import collections
t = int(input())
for i in range(t):
	n = int(input())
	nums = collections.Counter()
	nums2 = list(map(int, input().split()))
	for i in nums2:
		nums[i] += 1
	del nums2
	nums2 = list(nums.values())
	nums2.sort(reverse=True)
	if n % 2 == 1:
		if nums2[0] <= n // 2:
			print(1)
			continue
		elif nums2[0] > n // 2:
			print(nums2[0] - n + nums2[0])
			continue
	elif n % 2 == 0:
		if nums2[0] <= n // 2:
			print(0)
		else:
			print(nums2[0] - n + nums2[0])
			continue


from collections import Counter
for s in [*open(0)][2::2]:
	l = [*Counter(map(int, s.split())).values()]
	m = max(l)
	n = sum(l)
	print(max(2 * m - n, n & 1))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	d = {}
	for i in arr:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	mx = max(list(d.values()))
	if 2 * mx - n <= 0:
		if n % 2 == 0:
			ans = 0
		else:
			ans = 1
	else:
		ans = 2 * mx - n
	print(ans)


from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	p = set(arr)
	c = Counter(arr)
	k = []
	for i in p:
		k.append(c[i])
	m = max(k)
	sm = sum(k) - m
	if m > sm:
		print(m - sm)
	elif n % 2:
		print('1')
	else:
		print('0')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	dic = {}
	for num in a:
		if num in dic:
			dic[num] += 1
		else:
			dic[num] = 1
	k = max(dic.values())
	if k <= (n + 1) // 2:
		print(1 if n & 1 else 0)
	else:
		print(2 * k - n)


import sys, functools, collections, bisect, math, heapq
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	d = collections.Counter(map(int, input().strip().split()))
	x = d.most_common(1)[0][1]
	y = n - x
	curr = x - y
	if curr >= 0:
		print(curr)
	elif (y - x) % 2:
		print(1)
	else:
		print(0)


t = int(input())
for _ in range(t):
	n = int(input())
	array = [int(i) for i in input().split()]
	l = len(array)
	if len(set(array)) < 2:
		print(l)
	else:
		d = dict()
		for a in array:
			d.setdefault(a, 0)
			d[a] += 1
		m = max(d.values())
		if m > l // 2:
			print(2 * m - l)
		else:
			print(l % 2)


import heapq
from collections import Counter
for _ in range(int(input())):
	n = int(input())
	c = Counter(map(int, input().split()))
	max_heap = []
	for (value, count) in c.items():
		heapq.heappush(max_heap, (-count, value))
	while len(max_heap) > 1:
		(c1, v1) = heapq.heappop(max_heap)
		(c2, v2) = heapq.heappop(max_heap)
		n -= 2
		c1 += 1
		c2 += 1
		if c1 < 0:
			heapq.heappush(max_heap, (c1, v1))
		if c2 < 0:
			heapq.heappush(max_heap, (c2, v2))
	print(n)


import sys, io, os
input = lambda : sys.stdin.readline().encode()
read = lambda : map(int, input().split())
from collections import defaultdict
O = []
for _ in range(int(input())):
	n = int(input())
	a = list(read())
	d = defaultdict(lambda : 0)
	for i in a:
		d[i] += 1
	c = []
	for i in d:
		c.append(d[i])
	c.sort()
	v = c[-1]
	O.append(str(max(v + v - n, n % 2)))
print('\n'.join(O))


def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		bloki = []
		a = sorted(list(map(int, input().split())))
		por = a[0]
		lic = 0
		for liczba in a:
			if liczba == por:
				lic += 1
			else:
				bloki.append(lic)
				lic = 1
				por = liczba
			bloki.append(lic)
		maks = max(bloki)
		resz = n - maks
		if n % 2 != 0:
			if maks > 0:
				print(1 + max(0, maks - 1 - resz))
			else:
				print(1 + maks(0, maks + 1 - resz))
		else:
			print(max(0, maks - resz))
main()


from collections import deque
from heapq import heappop, heappush
import sys
lines = list(map(str.strip, sys.stdin.readlines()))
for line in lines[2::2]:
	nums = list(map(int, line.split(' ')))
	counts = {}
	for x in nums:
		counts[x] = 1 if x not in counts else counts[x] + 1
	biggest = max([counts[key] for key in counts])
	totalwob = sum([counts[key] for key in counts]) - biggest
	bmt = biggest - totalwob
	print(bmt if bmt > 0 else 1 if len(nums) % 2 == 1 else 0)


import collections
import math
t = int(input())
for _ in range(t):
	n = int(input())
	a = collections.Counter(list(map(int, input().split())))
	mx = max(a.values())
	if mx > n // 2:
		print(n - 2 * (n - mx))
	else:
		print(n % 2)


for i in [*open(0)][2::2]:
	a = i.split()
	a.sort()
	tem = a[0]
	ma = 0
	b = 0
	for j in a:
		if j == tem:
			b += 1
		else:
			if ma < b:
				ma = b
			b = 1
			tem = j
	if ma < b:
		ma = b
	if ma > len(a) / 2:
		print(2 * ma - len(a))
	elif len(a) % 2:
		print(1)
	else:
		print(0)


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	maxi = max(Counter(list(map(int, input().strip().split()))).values())
	maxi -= n - maxi
	print(max(n % 2, maxi))


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from functools import cmp_to_key
from heapq import *
from math import gcd, factorial, floor, ceil, sqrt, log2
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def testcase(t):
	for pp in range(t):
		solve(pp)

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def modInverse(b):
	g = gcd(b, mod)
	if g != 1:
		return -1
	else:
		return pow(b, mod - 2, mod)

def power(x, y, p):
	y %= p - 1
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
inf = pow(10, 20)
mod = 10 ** 9 + 7

def solve(case):
	n = int(inp())
	a = lis()
	cnt = {}
	for i in range(n):
		if a[i] not in cnt:
			cnt[a[i]] = 1
		else:
			cnt[a[i]] += 1
	h = []
	for i in cnt:
		heappush(h, -cnt[i])
	cnt = 0
	while len(h) > 1:
		f = heappop(h)
		s = heappop(h)
		if f == 0:
			heappush(h, s)
			continue
		if s == 0:
			heappush(h, f)
			continue
		cnt += 2
		heappush(h, f + 1)
		heappush(h, s + 1)
	print(n - cnt)
testcase(int(inp()))


from collections import Counter
import heapq
import sys
input = sys.stdin.readline
for nt in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = Counter(a)
	maxx = []
	for i in c:
		maxx.append(c[i])
	m = max(maxx)
	ans = 0
	if n % 2:
		if maxx.count(m) == 1:
			m -= 1
		ans = 1
	print(ans + max(0, 2 * m - n + ans))


def solve():
	n = int(input())
	t = list(map(int, input().split()))
	numbers = {}
	for e in t:
		if e in numbers:
			numbers[e] += 1
		else:
			numbers[e] = 1
	mx = max(numbers.values())
	if mx >= (n + 1) // 2:
		print(mx - (n - mx))
	else:
		print(n % 2)
tests = int(input())
for _ in range(tests):
	solve()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	my_key = {}
	for c in a:
		if c in my_key.keys():
			my_key[c] += 1
		else:
			my_key[c] = 0
	z = max(my_key.values()) + 1
	if z > n - z:
		print(2 * z - n)
	else:
		print(n % 2)


t = int(input())
l1 = []
for i in range(t):
	n = int(input())
	x = input()
	l1.append(list(map(int, x.split())))
for i in l1:
	dic = {}
	for j in i:
		if j not in dic:
			dic[j] = 1
		else:
			dic[j] += 1
	d = dic.values()
	e = max(d)
	if e <= len(i) / 2:
		if len(i) % 2 == 0:
			print(0)
		else:
			print(1)
	elif e > len(i) / 2:
		u = e - (len(i) - e)
		print(u)


import sys
import math

def fn(n, a):
	s = dict()
	s1 = list(set(a))
	for i in range(len(s1)):
		s[s1[i]] = 0
	for i in range(n):
		s[a[i]] = s[a[i]] + 1
	cnt = s.values()
	m = max(cnt)
	if n % 2 == 0 and m <= n / 2:
		return 0
	elif n % 2 == 0 and m > n / 2:
		return 2 * m - n
	elif n % 2 != 0 and m <= n // 2:
		return 1
	else:
		return 2 * m - n
input = sys.stdin.read()
data = list(map(int, input.split()))
t = int(data[0])
l = 0
for i in range(t):
	n = data[l + 1]
	a = data[l + 2:l + 2 + n]
	l = l + 1 + n
	print(fn(n, a))


def transform(list_num):
	mem = {}
	for el in list_num:
		if el in mem.keys():
			mem[el] += 1
		else:
			mem[el] = 1
	min_val = len(list_num) % 2
	max_val = max(mem.values())
	diff = max_val - (len(list_num) - max_val)
	if diff > 0:
		return diff
	else:
		return min_val
num = int(input())
for i in range(num):
	s = input()
	list_num = [int(el) for el in input().split()]
	print(transform(list_num))


from collections import defaultdict

def func():
	n = int(input())
	for _ in range(n):
		m = int(input())
		nums = map(int, input().split())
		d = defaultdict(int)
		max_value = 0
		for c in nums:
			d[c] += 1
			max_value = max(max_value, d[c])
		if m % 2 == 0:
			if max_value > m - max_value:
				print(max_value - m + max_value)
			else:
				print(0)
		elif max_value > m - max_value:
			print(max_value - m + max_value)
		else:
			print(1)
func()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = {}
	for i in a:
		if i not in s:
			s[i] = 1
		else:
			s[i] += 1
	m = 0
	s2 = 0
	for i in s.keys():
		m = max(s[i], m)
		s2 += s[i]
	print(max(m - s2 + m, n % 2))


import sys
N = int(200000.0 + 5)
sys.setrecursionlimit(N)

def charming():
	n = int(input())
	a = list(map(int, input().split()))
	d = dict()
	mx = 0
	for i in a:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
		mx = max(mx, d[i])
	if mx <= n - mx:
		print(n & 1)
		return
	else:
		print(mx - n + mx)
for t in range(int(input())):
	charming()


from collections import Counter
import heapq
T = int(input())
for t in range(T):
	n = int(input())
	l = list(map(int, input().split()))
	c = Counter(l)
	h = [(-value, key) for (key, value) in c.items()]
	heapq.heapify(h)
	sz = n
	while len(h) >= 2:
		[cnt1, key1] = heapq.heappop(h)
		[cnt2, key2] = heapq.heappop(h)
		cnt1 = -1 * cnt1
		cnt2 = -1 * cnt2
		sz -= 2
		cnt1 -= 1
		cnt2 -= 1
		if cnt1 > 0:
			heapq.heappush(h, (-1 * cnt1, key1))
		if cnt2 > 0:
			heapq.heappush(h, (-1 * cnt2, key2))
	print(sz)


import collections
import math
import sys
from functools import reduce
import decimal
sys.setrecursionlimit(10 ** 9)
decimal.getcontext().rounding = decimal.ROUND_HALF_UP

def rounding(n):
	return int(decimal.Decimal(f'{n}').to_integral_value())

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def inp():
	return sys.stdin.readline().strip()

def map_inp(v_type):
	return map(v_type, inp().split())

def list_inp(v_type):
	return list(map_inp(v_type))
for _ in range(int(inp())):
	n = int(inp())
	arr = list_inp(int)
	dic = {}
	for item in arr:
		if item not in dic:
			dic[item] = 1
		else:
			dic[item] += 1
	counter_arr = []
	for item in dic.keys():
		counter_arr.append(dic[item])
	counter_arr.sort(reverse=True)
	if len(counter_arr) == 1:
		print(n)
	elif counter_arr[0] > n - counter_arr[0]:
		print(n - 2 * (n - counter_arr[0]))
	else:
		print(n % 2)


def solve(arr):
	freqs = dict()
	for num in arr:
		if num not in freqs:
			freqs[num] = 1
		else:
			freqs[num] += 1
	max_freq = max(freqs.values())
	return max(len(arr) % 2, max_freq - (len(arr) - max_freq))

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		arr = [int(s) for s in input().split()]
		print(solve(arr))
main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 0 or n == 1:
		print(n)
		continue
	d = dict()
	for i in a:
		d[i] = d.get(i, 0) + 1
	m = max(d.values())
	if m <= n // 2:
		print(n % 2)
	else:
		print(2 * m - n)


from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(s) for s in input().split(' ')]
	d = Counter(a)
	count = list(d.values())
	count.sort()
	l = len(count)
	lst = count.pop()
	if sum(count) < lst:
		ans = n - 2 * sum(count)
	else:
		ans = n % 2
	print(ans)


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	h = max(Counter(l).values())
	print(n % 2 if h <= n - h + 1 else h - (n - h))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = {}
	for i in a:
		if i in s:
			s[i] += 1
		else:
			s[i] = 1
	f = 0
	for i in s.values():
		if i > n // 2:
			f = 1
			break
	if f == 0:
		print(n % 2)
	else:
		print(i * 2 - n)


from collections import Counter
tests = int(input())
for t in range(tests):
	n = int(input())
	ls = list(map(int, input().split()))
	cnter = Counter(ls)
	m_ls = cnter.most_common(2)
	if len(m_ls) == 1:
		print(n)
	else:
		top_two_freq = [m_ls[0][1], m_ls[1][1]]
		remain = n - top_two_freq[1] - top_two_freq[0]
		diff = top_two_freq[0] - top_two_freq[1]
		res = max(diff - remain, 0)
		if n % 2 == 1 and max(diff - remain, 0) == 0:
			print(res + 1)
		else:
			print(res)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	a.sort()
	(i, c) = (0, 0)
	for j in range((n + 1) // 2, n):
		if a[i] != a[j]:
			c += 1
		i += 1
	print(n - c * 2)


for t in range(int(input())):
	n = int(input())
	a = map(int, input().split())
	c = {}
	for x in a:
		if x in c:
			c[x] += 1
		else:
			c[x] = 1
	m = max(c.values())
	print(2 * m - n if m > n // 2 else n % 2)


import heapq
from collections import Counter
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = Counter(a)
	ans = n
	q = []
	heapq.heapify(q)
	for i in d:
		heapq.heappush(q, [-d[i], i])
	while len(q) > 1:
		(cnt1, x1) = heapq.heappop(q)
		(cnt2, x2) = heapq.heappop(q)
		cnt1 += 1
		cnt2 += 1
		if abs(cnt1):
			heapq.heappush(q, [cnt1, x1])
		if abs(cnt2):
			heapq.heappush(q, [cnt2, x2])
		ans -= 2
	print(ans)


import os
import sys
from io import BytesIO, IOBase
import threading
from bisect import bisect_right
from math import gcd, log
from collections import Counter, defaultdict, deque
from pprint import pprint
from itertools import permutations
from bisect import bisect_left
import heapq

def main(tnum):
	n = int(input())
	arr = list(map(int, input().split()))
	arr = list(Counter(arr).values())
	arr = [-x for x in arr]
	heapq.heapify(arr)
	while len(arr) > 1:
		n1 = -heapq.heappop(arr)
		n2 = -heapq.heappop(arr)
		n1 -= 1
		n2 -= 1
		if n1 > 0:
			heapq.heappush(arr, -n1)
		if n2 > 0:
			heapq.heappush(arr, -n2)
	print(-sum(arr))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	main(_ + 1)


from collections import Counter

def main():
	for i in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		count = Counter(a).values()
		Max = max(count)
		print(n - 2 * (n - Max)) if Max > n // 2 else print(n % 2)
main()


from heapq import heappush as push, heappop as pop
import sys
from math import *
from collections import Counter as count
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	n = int(input())
	z = list(map(int, input().split()))
	s = count(z)
	b = max(s.values())
	if b < ceil(n / 2):
		if n % 2 == 0:
			print(0)
		else:
			print(1)
	else:
		print(n - 2 * (n - b))


from sys import stdin
input = stdin.readline
from heapq import heapify, heappush, heappop, heappushpop
from collections import defaultdict as dd, deque as dq, Counter as C
from math import factorial as f, ceil, gcd, sqrt, log
from bisect import bisect_left as bl, bisect_right as br
from itertools import combinations as c, permutations as p
from math import factorial as f, ceil, gcd, sqrt, log
mp = lambda : map(int, input().split())
it = lambda : int(input())
ls = lambda : list(input().strip())
mt = lambda r: [list(map(int, ls())) for _ in range(r)]
lcm = lambda a, b: a * b // gcd(a, b)

def fibo_n(n):
	return ((1 + sqrt(5)) / 2) ** n / sqrt(5)
mod = 1000000007

def solve(a, b):
	if b in a:
		return len(a) - len(b)
	return min(solve(a, b[1:]), solve(a, b[:-1]))
for _ in range(it()):
	a = it()
	b = list(mp())
	k = C(b)
	mx = max(list(k.values()))
	if mx <= a // 2:
		print(a % 2)
	else:
		rem = a - mx
		print(a - rem * 2)


import sys
import math
import bisect
from math import sqrt
from heapq import heappop, heappush, heapify

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def rinput():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
mod = int(1000000000.0) + 7

def bruteforce(cnt):
	q = []
	for k in cnt:
		q.append(-1 * cnt[k])
	heapify(q)
	ans = n
	while len(q) > 1:
		cntf = -1 * heappop(q)
		cnts = -1 * heappop(q)
		cntf -= 1
		cnts -= 1
		ans -= 2
		if cntf != 0:
			heappush(q, -1 * cntf)
		if cnts != 0:
			heappush(q, -1 * cnts)
	return ans

def logic(cnt, n):
	m = max(cnt.values())
	if m <= n // 2:
		ans = n % 2
	else:
		ans = 2 * m - n
	return ans
for _ in range(iinput()):
	n = iinput()
	a = get_list()
	cnt = {}
	for item in a:
		cnt[item] = cnt.get(item, 0) + 1
	print(logic(cnt, n))


for t in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	dic = {}
	for j in l:
		if j in dic:
			dic[j] += 1
		else:
			dic[j] = 1
	k = list(dic.values())
	k.sort()
	z = k[-1]
	if 2 * z - n <= 0:
		if n % 2 == 0:
			c = 0
		else:
			c = 1
	else:
		c = 2 * z - n
	print(c)


from collections import Counter
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = Counter(a)
	f = 0
	for x in b:
		if b[x] > len(a) // 2:
			print(len(a) - (len(a) - b[x]) * 2)
			f = 1
			break
	if not f:
		print(len(a) % 2)


import sys
import math
from bisect import bisect_right as br
from collections import deque, Counter
from itertools import combinations as cb

def int_arr():
	return list(map(int, sys.stdin.readline().strip().split()))

def str_arr():
	return list(map(str, sys.stdin.readline().strip().split()))

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	n = int(input())
	arr = int_arr()
	mx = max(Counter(arr).values())
	if mx >= n // 2 + n % 2:
		print(2 * mx - n)
	else:
		print(n % 2)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	freq = {}
	for i in a:
		if i in freq:
			freq[i] += 1
		else:
			freq[i] = 1
	if max(freq.values()) <= (n + 1) // 2:
		if n % 2 == 0:
			print(0)
		else:
			print(1)
	else:
		print(2 * max(freq.values()) - n)


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	count = Counter(input().split())
	print(max(2 * count.most_common(1)[0][1] - n, n & 1))


from collections import Counter
import heapq
from sys import stdin, stderr
input = stdin.readline

def dbp(*args, **kwargs):
	pass

def get_int_list():
	return [int(x) for x in input().strip().split()]

def do_thing():
	n = int(input())
	alist = get_int_list()
	c = Counter(alist)
	pq = [(-v, k) for (k, v) in c.items()]
	heapq.heapify(pq)
	dbp(pq)
	while len(pq) > 1:
		v1 = heapq.heappop(pq)
		v2 = heapq.heappop(pq)
		if v1[0] < -1:
			heapq.heappush(pq, (v1[0] + 1, v1[1]))
		if v2[0] < -1:
			heapq.heappush(pq, (v2[0] + 1, v2[1]))
		dbp(pq)
	return -pq[0][0] if pq else 0

def multicase():
	maxcc = int(input().strip())
	for cc in range(maxcc):
		print(do_thing())
multicase()


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	i = 0
	ans = 0
	w = n // 2
	while i < n // 2 and w < n:
		if l[i] != l[w]:
			i += 1
			w += 1
			ans += 1
		elif l[i] == l[w]:
			w += 1
	print(n - 2 * ans)


T = int(input())
for t in range(T):
	n = int(input())
	A = [int(i) for i in input().split()]
	freq = dict()
	for i in A:
		if i not in freq:
			freq[i] = 1
		else:
			freq[i] += 1
	ans = 0
	exists = 0
	key = -1
	for i in freq:
		if freq[i] > n // 2:
			exists = 1
			key = i
	others = 0
	if not exists:
		if n % 2 == 0:
			print(0)
		else:
			print(1)
	else:
		for i in freq:
			if i != key:
				others += freq[i]
		print(freq[key] - others)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	a.append(-5)
	maxi = 0
	count = 1
	for i in range(n):
		if a[i] == a[i + 1]:
			count += 1
		else:
			maxi = max(maxi, count)
			count = 1
	if n % 2 == 0:
		print(max(0, maxi - (n - maxi)))
	else:
		print(max(1, maxi - (n - maxi)))


t = int(input())
for _ in range(t):
	n = int(input())
	arr = input().split(' ')
	arr = [int(x) for x in arr]
	cnt = {}
	for x in arr:
		cnt[x] = 0
	for x in arr:
		cnt[x] += 1
	mx = 0
	for a in cnt.values():
		if a > mx:
			mx = a
	if mx + mx >= n:
		rem = n - mx
		ans = n - (rem + rem)
	else:
		ans = n % 2
	print(ans)


import sys
import math
import random
from queue import PriorityQueue as PQ
from bisect import bisect_left as BSL
from bisect import bisect_right as BSR
from collections import OrderedDict as OD
from collections import Counter
from itertools import permutations
mod = 1000000007
sys.setrecursionlimit(1000000)
try:
	sys.stdin = open('actext.txt', 'r')
	OPENFILE = 1
except:
	pass

def get_ints():
	return map(int, input().split())

def palindrome(s):
	mid = len(s) // 2
	for i in range(mid):
		if s[i] != s[len(s) - i - 1]:
			return False
	return True

def check(i, n):
	if 0 <= i < n:
		return True
	else:
		return False

def solve(arr, n):
	mp = {}
	for i in arr:
		if i not in mp:
			mp[i] = 0
		mp[i] += 1
	maxmp = max(mp.values())
	ans = 0
	if n % 2 != 0:
		maxmp -= 1
		n -= 1
		ans += 1
	ans += max(0, 2 * (maxmp - n // 2))
	print(ans)
t = int(input())
for tt in range(t):
	n = int(input())
	arr = list(get_ints())
	solve(arr, n)


for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	dic = {}
	for i in lis:
		if i in dic:
			dic[i] += 1
		else:
			dic[i] = 1
	m = max(list(dic.values()))
	if n % 2 == 1 and m <= n // 2 + 1:
		ans = 1
	elif n % 2 == 0 and m <= n // 2:
		ans = 0
	else:
		ans = m - (n - m)
	print(ans)


import collections
for _ in range(int(input())):
	a = int(input())
	b = list(map(int, input().split()))
	c = collections.Counter()
	for i in range(len(b)):
		c[b[i] - 1] += 1
	c = sorted(c.values())
	summ = sum(c)
	if len(c) == 1:
		print(summ)
	elif summ - c[-1] < c[-1]:
		print(c[-1] - (summ - c[-1]))
	elif a % 2 == 1:
		print(1)
	else:
		print(0)


import sys
from collections import Counter
from heapq import *
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
MOD = 10 ** 9 + 7

def solve():
	n = int(input())
	A = list(map(int, input().split()))
	D = Counter(A)
	B = [-v for v in D.values()]
	heapify(B)
	while len(B) >= 2:
		a = heappop(B)
		b = heappop(B)
		if a + 1 != 0:
			heappush(B, a + 1)
		if b + 1 != 0:
			heappush(B, b + 1)
	res = sum(B) * -1
	print(res)
t = int(input())
for _ in range(t):
	solve()


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	freq = {}
	for x in a:
		freq[x] = freq.get(x, 0) + 1
	mx = max(freq.values())
	if mx > n // 2:
		print(mx - (n - mx))
	elif n % 2 == 1:
		print(1)
	else:
		print(0)
t = int(input())
for _ in range(t):
	solve()


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7

def LI():
	return list(map(int, input().split()))

def II():
	return int(input())

def LS():
	return list(input().split())

def S():
	return input()

def solve():
	n = II()
	a = LI()
	cnt_dict = collections.Counter(a)
	cnt_max = max(cnt_dict.values())
	if cnt_max > n // 2:
		return cnt_max - (n - cnt_max)
	else:
		return n % 2

def main():
	t = II()
	res = list()
	for _ in range(t):
		res.append(solve())
	for ans in res:
		print(ans)
	return 0
main()


import sys, os.path
from collections import Counter
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = Counter(a)
	l = []
	for (key, value) in c.items():
		l.append([value, key])
	l.sort(reverse=True)
	m = l[0][0]
	if n % 2 == 0:
		if m <= n // 2:
			print(0)
		else:
			print(m - (n - m))
	elif m <= n // 2:
		print(1)
	else:
		print(m - (n - m))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	i = 0
	if n % 2 == 0:
		j = int(n / 2)
	else:
		j = int(n / 2) + 1
	count = 0
	while j < n:
		if a[i] != a[j]:
			count += 2
			j += 1
			i += 1
		else:
			j += 1
	print(n - count)


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree2:

	def __init__(self, data, default=3000006, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree1:

	def __init__(self, data, default=10 ** 10, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] > k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

class TrieNode:

	def __init__(self):
		self.children = [None] * 26
		self.isEndOfWord = False

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def _charToIndex(self, ch):
		return ord(ch) - ord('a')

	def insert(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				pCrawl.children[index] = self.getNode()
			pCrawl = pCrawl.children[index]
		pCrawl.isEndOfWord = True

	def search(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
		return pCrawl != None and pCrawl.isEndOfWord

class Node:

	def __init__(self, data):
		self.data = data
		self.count = 0
		self.left = None
		self.right = None

class BinaryTrie:

	def __init__(self):
		self.root = Node(0)

	def insert(self, pre_xor, t):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = pre_xor & 1 << i
			if val:
				if not self.temp.right:
					self.temp.right = Node(0)
				self.temp = self.temp.right
				self.temp.count += t
			if not val:
				if not self.temp.left:
					self.temp.left = Node(0)
				self.temp = self.temp.left
				self.temp.count += t
		self.temp.data = pre_xor

	def query(self, p, l):
		ans = 0
		self.temp = self.root
		for i in range(31, -1, -1):
			val = p & 1 << i
			val1 = l & 1 << i
			if val1 == 0:
				if val == 0:
					if self.temp.left and self.temp.left.count > 0:
						self.temp = self.temp.left
					else:
						return ans
				elif self.temp.right and self.temp.right.count > 0:
					self.temp = self.temp.right
				else:
					return ans
			elif val != 0:
				if self.temp.right:
					ans += self.temp.right.count
				if self.temp.left and self.temp.left.count > 0:
					self.temp = self.temp.left
				else:
					return ans
			else:
				if self.temp.left:
					ans += self.temp.left.count
				if self.temp.right and self.temp.right.count > 0:
					self.temp = self.temp.right
				else:
					return ans
		return ans
for ik in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = defaultdict(int)
	for i in range(n):
		d[l[i]] += 1
	a = []
	for i in d:
		a.append(d[i])
	a.sort()
	left = sum(a) - a[-1]
	print(max(n % 2, a[-1] - left))


def solve():
	n = int(input())
	a = sorted(list(map(int, input().split())))
	c = 0
	i = 0
	h = n // 2 + n % 2
	while i < n // 2:
		if a[i] != a[h + i]:
			c += 2
		i += 1
	return n - c
t = int(input())
while t > 0:
	print(solve())
	t -= 1


import math as mt

def mostFrequent(arr, n):
	Hash = dict()
	for i in range(n):
		if arr[i] in Hash.keys():
			Hash[arr[i]] += 1
		else:
			Hash[arr[i]] = 1
	max_count = 0
	res = -1
	for i in Hash:
		if max_count < Hash[i]:
			res = i
			max_count = Hash[i]
	return res
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	t = mostFrequent(arr, n)
	d = arr.count(t)
	if d > n // 2:
		print(n - 2 * (n - d))
	elif n % 2 != 0:
		print(1)
	else:
		print(0)


from collections import Counter
cases = int(input())
while cases:
	cases -= 1
	num = int(input())
	arr = list(map(int, input().split()))
	count = Counter(arr)
	mx = max(count.values())
	dif = num - mx
	if dif >= mx:
		if num % 2 == 0:
			print(0)
		else:
			print(1)
	else:
		print(mx - dif)


from collections import Counter, defaultdict
import sys

def get_ints():
	return list(map(int, sys.stdin.readline().strip().split()))

def solve(N, nums):
	ans = 0
	vis = defaultdict(int)
	max_cnt = 0
	for n in nums:
		vis[n] += 1
		max_cnt = max(max_cnt, vis[n])
	left = N - max_cnt
	if max_cnt > left:
		return max_cnt - left
	if N & 1:
		return 1
	return 0
T = int(input())
for i in range(T):
	N = int(input())
	nums = get_ints()
	print(solve(N, nums))


from heapq import *
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = {}
	for i in l:
		if i in d:
			d[i] -= 1
		else:
			d[i] = -1
	if len(d) == 1:
		print(n)
	else:
		h = []
		for i in d:
			heappush(h, d[i])
		c = 0
		while len(h) > 1:
			a = heappop(h)
			b = heappop(h)
			if a == 0:
				heappush(h, a)
				continue
			if b == 0:
				heappush(h, b)
				continue
			c += 2
			heappush(h, a + 1)
			heappush(h, b + 1)
		print(n - c)


from collections import *
from heapq import *
for _ in range(int(input())):
	p = int(input())
	arr = list(map(int, input().split()))
	heap = []
	for (key, values) in Counter(arr).items():
		heappush(heap, -values)
	(heap, len(heap))
	n = len(heap)
	while n >= 2:
		n -= 2
		val1 = heappop(heap)
		val2 = heappop(heap)
		val1 += 1
		val2 += 1
		if val1 != 0:
			heappush(heap, val1)
			n += 1
		if val2 != 0:
			heappush(heap, val2)
			n += 1
	if n == 0:
		print(0)
	else:
		print(abs(heappop(heap)))


import math, random, time
from collections import *
from itertools import *

def ass(a, b):
	print(f'Assertion error: {a} != {b}' if a != b else 'OK')

def nr():
	return int(input())

def nrs():
	return [int(i) for i in input().split()]

def nrss(n):
	return [nrs() for _ in range(n)]

def word():
	return input()

def words():
	return [w for w in input().split()]

def dump(lst):
	for (i, item) in enumerate(lst):
		print(i, item)

def binsearch(arr, a, b):
	m = (a + b) // 2
	if a >= b:
		return a - 1 if arr[a] == 0 else a
	return binsearch(arr, a, m - 1) if arr[m] == 0 else binsearch(arr, m + 1, b)

def gcd(x, y):
	return x if y == 0 else gcd(y, x % y)

def lcm(x, y):
	return x * y // gcd(x, y)

def sign(a):
	return 0 if a == 0 else int(a / abs(a))

def f(arr):
	arr.sort()
	antal = 0
	n = len(arr)
	orig = n
	if n % 2 == 1:
		arr.pop(n // 2)
		n -= 1
	n2 = n // 2
	for i in range(n2):
		if arr[i] != arr[i + n2]:
			antal += 2
	return orig - antal
for i in range(nr()):
	n = nrs()
	print(f(nrs()))


import math
from collections import defaultdict
from sys import stdin
T = int(input())
for _ in range(T):
	n = int(input())
	arr = list(map(int, input().split()))
	d = defaultdict(int)
	m = 0
	for i in arr:
		d[i] += 1
	for i in d:
		m = max(m, d[i])
	if n % 2 == 0:
		if m <= n // 2:
			print(0)
		else:
			print(abs(n - 2 * m))
	if n % 2:
		if m <= n // 2:
			print(1)
		else:
			print(abs(n - 2 * m))


from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	a = map(int, input().split())
	count = Counter(a)
	max_occr = max(count.values())
	if max_occr > n // 2:
		print(abs(2 * max_occr - n))
	elif n % 2 == 1:
		print(1)
	else:
		print(0)


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	count = Counter(arr)
	to = list(count.values())
	to.sort()
	f = to[-1]
	res = 0
	if f > n - f:
		res = f - (n - f)
	if res == 0 and n % 2 == 1:
		res = 1
	print(res)


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	counter = Counter(arr)
	maxe = max(counter.values())
	print(max(n % 2, n - 2 * (n - maxe)))


from collections import defaultdict
test_cases = int(input())
while test_cases:
	n = int(input())
	arr = list(map(int, input().split()))
	d = defaultdict(lambda : 0)
	max_freq = 0
	for num in arr:
		d[num] += 1
		max_freq = max(max_freq, d[num])
	a = 0 if n % 2 == 0 else 1
	print(max(a, 2 * max_freq - n))
	test_cases -= 1


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	numbers = list(map(int, input().split()))
	d = Counter(numbers)
	maxx = max(d.values())
	if 2 * maxx <= n:
		print(0 if n % 2 == 0 else 1)
	else:
		print(2 * maxx - n)


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(Counter(a).values())
	mx = b.pop()
	sum_rest = sum(b)
	ans = mx - sum_rest
	if ans < 0:
		ans %= 2
	print(ans)


import sys
input = sys.stdin.buffer.readline
from collections import Counter
for _ in range(int(input())):
	n = int(input())
	a = Counter(map(int, input().split()))
	mx = a.most_common(1)[0][1]
	if 2 * mx > n:
		print(mx - (n - mx))
	else:
		print(n % 2)


def zip_sorted(a, b):
	(a, b) = zip(*sorted(zip(a, b)))
	sorted(zip(a, b), key=lambda x: x[1])
	return (a, b)

def number_to_list(a):
	b = []
	while a >= 1:
		c = a % 10
		a = int(a / 10)
		b.append(c)
	return list(reversed(b))

def str_list_to_int_list(a):
	a = list(map(int, a))
	return a

def make_1d_array(n, inti=0):
	a = [inti for _ in range(n)]
	return a

def make_2d_array(n, m, inti=0):
	a = [[inti for _ in range(m)] for _ in range(n)]
	return a

def make_3d_array(n, m, k, inti=0):
	a = [[[inti for _ in range(k)] for _ in range(m)] for _ in range(n)]
	return a

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
import sys
from collections import defaultdict
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
S = lambda : list(map(str, input()))
(t,) = I()
for t1 in range(t):
	(n,) = I()
	a = I()
	mem1 = defaultdict(int)
	for i in range(len(a)):
		mem1[a[i]] += 1
	val = list(mem1.values())
	if len(val) == 1:
		print(val[0])
	elif max(val) <= n // 2:
		print(n - 2 * (n // 2))
	else:
		print(n - 2 * (len(a) - max(val)))


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	d = defaultdict(int)
	for i in range(n):
		d[a[i]] += 1
	b = set(a)
	if len(b) == 1:
		print(n)
		continue
	if len(b) == 2:
		c = list(b)
		out = abs(d[c[0]] - d[c[1]])
		print(out)
		continue
	c = list(b)
	s = []
	for i in range(len(c)):
		x = c[i]
		s.append(d[x])
	s.sort()
	mx = s[-1]
	el = sum(s[:-1])
	if mx >= el:
		print(mx - el)
		continue
	t = abs(mx - el)
	if t % 2 == 1:
		print(1)
	else:
		print(0)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
from copy import deepcopy
mod = 10 ** 9 + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var, end='\n'):
	sys.stdout.write(str(var) + end)

def outa(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	n = int(data())
	cnt = C(l())
	b = False
	for i in cnt.values():
		if i >= n // 2 + n % 2:
			b = i
			break
	if not b:
		out(n % 2)
		continue
	out(2 * b - n)


for _ in range(int(input())):
	(n, l) = (int(input()), list(map(int, input().split())))
	m = {}
	k = 0
	for i in l:
		if i in m:
			m[i] += 1
		else:
			m[i] = 1
		k = max(m[i], k)
	print(max(2 * k - n, n % 2))


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	boro = max(Counter(ar).values())
	print(n % 2 if boro <= n - boro + 1 else boro - (n - boro))


import collections, heapq

def sign(val):
	return -val

def solve(a, n):
	hm = collections.defaultdict(int)
	for val in a:
		hm[val] += 1
	h = []
	for (k, v) in hm.items():
		heapq.heappush(h, sign(v))
	ans = n
	while len(h) > 1:
		c1 = sign(heapq.heappop(h))
		c2 = sign(heapq.heappop(h))
		c1 -= 1
		c2 -= 1
		ans -= 2
		if c1 > 0:
			heapq.heappush(h, sign(c1))
		if c2 > 0:
			heapq.heappush(h, sign(c2))
	return ans
local_ans = []
local_mode = False

def getArr():
	return list(map(int, input().split()))

def getNums():
	return map(int, input().split())
t = int(input())
for _ in range(t):
	n = int(input())
	a = getArr()
	if local_mode:
		local_ans.append(solve(a, n))
	else:
		print(solve(a, n))
if local_mode:

	def printAll(sol):
		for val in sol:
			print(val)
	printAll(local_ans)


import logging
import sys
from collections import Counter
from inspect import currentframe
input = sys.stdin.readline
logging.basicConfig(level=logging.DEBUG)

def dbg(*args):
	id2names = {id(v): k for (k, v) in currentframe().f_back.f_locals.items()}
	logging.debug(', '.join((id2names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args)))

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	c = Counter(a)
	f = sorted(c.values(), reverse=True)
	if len(f) == 1:
		print(n)
		return
	if f[0] >= (n + 1) // 2:
		print(f[0] - sum(f[1:]))
		return
	if n % 2 == 1:
		print(1)
		return
	else:
		print(0)

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


for t in range(int(input())):
	n = int(input())
	a = sorted(list(map(int, input().split())))

	def solve():
		cnt = 0
		i = 0
		h = n // 2 + n % 2
		while i < n // 2:
			if a[i] != a[h + i]:
				cnt += 2
			i += 1
		return n - cnt
	print(solve())


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	d = Counter(ar)
	e = max(d.values())
	if e == n:
		print(n)
	elif e > n // 2:
		print(e - (n - e))
	elif n % 2 == 0:
		print(0)
	else:
		print(1)


from collections import defaultdict

def func():
	n = int(input())
	for _ in range(n):
		m = int(input())
		nums = map(int, input().split())
		d = defaultdict(int)
		for c in nums:
			d[c] += 1
		l = sorted(d.values())
		if m % 2 == 0:
			if l[-1] > m - l[-1]:
				print(l[-1] - m + l[-1])
			else:
				print(0)
		elif l[-1] > m - l[-1]:
			print(l[-1] - m + l[-1])
		else:
			print(1)
func()


import sys
mod = 1000000007
input = lambda : sys.stdin.readline().rstrip('\r\n')
from _collections import deque
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = dict()
	for i in a:
		d[i] = d.get(i, 0) + 1
	t = 0
	for i in d:
		if d[i] > n // 2:
			t = d[i]
			break
	if t == 0:
		if n % 2:
			print(1)
		else:
			print(0)
	else:
		print(2 * t - n)


try:
	t = int(input())
	for _ in range(t):
		n = int(input())
		l = list(input().split())
		d = {}
		for i in l:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		mx = 0
		for i in d:
			if d[i] > mx:
				mx = d[i]
		print(max(n % 2, 2 * mx - n))
except:
	pass


from sys import stdin, stdout
from collections import Counter, OrderedDict, defaultdict
import math
import re
cin = stdin.readline
cout = stdout.write
mp = lambda : list(map(int, cin().split()))

def chars():
	s = cin()
	return list(s[:len(s) - 1])

def pl(a):
	for val in a:
		cout(str(val) + ' ')
	cout('\n')

def binSearch(l, val, start, end):
	if end < start:
		return False
	mid = (start + end) // 2
	if l[mid] == val:
		return True
	elif l[mid] < val:
		return binSearch(l, val, mid + 1, end)
	elif l[mid] > val:
		return binSearch(l, val, start, mid - 1)

def myLog(x, y):
	z = int(math.log(x, y))
	if y ** (z + 1) > x:
		return z
	elif y ** (z + 1) == x:
		return z + 1
(t,) = mp()
for _ in range(t):
	(n,) = mp()
	a = mp()
	d = {}
	maxi = 0
	for item in a:
		if item in d:
			d[item] += 1
		else:
			d[item] = 1
		maxi = max(maxi, d[item])
	if maxi <= n // 2:
		if n % 2:
			cout('1\n')
		else:
			cout('0\n')
	else:
		cout(str(2 * maxi - n) + '\n')


for _ in range(int(input())):
	n = int(input())
	list1 = list(map(int, input().split()))
	dict1 = dict()
	for i in list1:
		if i not in dict1.keys():
			dict1[i] = 1
		else:
			dict1[i] += 1
	list2 = list()
	for i in dict1.keys():
		list2.append(dict1[i])
	list2.sort(reverse=True)
	total = 0
	if len(list2) == 1:
		print(list2[0])
		continue
	for i in list2[1:]:
		total += i
	if total - list2[0] >= 0:
		print((total - list2[0]) % 2)
	else:
		print(list2[0] - total)


Z = input
for _ in [0] * int(Z()):
	n = int(Z())
	c = {}
	for i in Z().split():
		c[i] = c.get(i, 0) + 1
	m = max(c.values())
	print(max(m + m - n, n % 2))


def frequency(l):
	d = {}
	for i in lis:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	return d
for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	d = {}
	for i in lis:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	fin = []
	for i in d:
		fin.append(d[i])
	fin.sort()
	l = len(fin)
	if l == 1:
		print(n)
	else:
		a = 2 * fin[-1] - sum(fin)
		if a >= 0:
			print(a)
		else:
			print(n % 2)


import sys
from collections import Counter

def I():
	return int(sys.stdin.readline().rstrip())

def MI():
	return map(int, sys.stdin.readline().rstrip().split())

def LI():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def LI2():
	return list(map(int, sys.stdin.readline().rstrip()))

def S():
	return sys.stdin.readline().rstrip()

def LS():
	return list(sys.stdin.readline().rstrip().split())

def LS2():
	return list(sys.stdin.readline().rstrip())
t = I()
for _ in range(t):
	n = I()
	A = LI()
	count = Counter(A)
	M = max(count.values())
	m = n - M
	if n % 2 == 0:
		ans = max(0, n - 2 * m)
	else:
		ans = max(1, n - 2 * m)
	print(ans)


from heapq import heapify, heappush, heappop

def transformation(numbers):
	counter = {}
	for n in numbers:
		counter[n] = counter.get(n, 0) + 1
	items = [v * -1 for v in counter.values()]
	heapify(items)
	while len(items) > 1:
		(peek1, peek2) = (heappop(items), heappop(items))
		peek1 += 1
		peek2 += 1
		if peek1 != 0:
			heappush(items, peek1)
		if peek2 != 0:
			heappush(items, peek2)
	if len(items) > 0:
		return -1 * items[0]
	return 0
results = []
for _ in range(int(input())):
	_ = input()
	arr = [int(e) for e in input().split(' ')]
	results.append(str(transformation(arr)))
print('\n'.join(results))


from os import path
from io import BytesIO, IOBase
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, Counter, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('0')
file = 1

def ceil(a, b):
	return (a + b - 1) // b

def solve():
	for _ in range(ii()):
		n = ii()
		a = li()
		m = {}
		mx = 0
		for i in a:
			if i not in m:
				m[i] = 0
			m[i] += 1
			mx = max(mx, m[i])
		rem = n - mx
		if n & 1:
			print(max(1, mx - rem))
		else:
			print(max(0, mx - rem))
if file:
	if path.exists('tmp/input.txt'):
		sys.stdin = open('tmp/input.txt', 'r')
		sys.stdout = open('tmp/output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


t = int(input())
for _ in range(t):
	n = int(input())
	s = list(map(int, input().split()))
	p = {}
	for i in s:
		p[i] = p.get(i, 0) + 1
	if n % 2 == 0:
		if max(p.values()) <= n // 2:
			print(0)
		else:
			print(2 * max(p.values()) - n)
	elif max(p.values()) <= n // 2:
		print(1)
	else:
		print(2 * max(p.values()) - n)


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = sorted(list(map(int, input().split())))
		if n % 2 == 0:
			cnt = n
			for i in range(n // 2):
				if a[i] != a[i + n // 2]:
					cnt -= 2
			print(cnt)
		else:
			cnt = n
			for i in range(n // 2):
				if a[i] != a[i + n // 2 + 1]:
					cnt -= 2
			print(cnt)
main()


from collections import Counter
for t in range(int(input())):
	n = int(input())
	a = Counter(list(map(int, input().split())))
	mx = max(a.values())
	if mx * 2 >= n:
		print(2 * mx - n)
	elif n % 2 == 1:
		print(1)
	else:
		print(0)


import sys
from collections import Counter

def solve(nums):
	c = Counter(nums)
	max_ = max(c.values())
	s = sum(c.values())
	if 2 * max_ - s >= 0:
		return 2 * max_ - s
	if s % 2 == 1:
		return 1
	return 0
t = int(sys.stdin.readline().strip())
for _ in range(t):
	line = sys.stdin.readline().strip()
	n = list(map(int, line.split()))[0]
	line = sys.stdin.readline().strip()
	nums = list(map(int, line.split()))
	print(solve(nums))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	if a.count(a[n // 2]) <= n // 2:
		if n % 2 == 1:
			print(1)
		else:
			print(0)
	else:
		print(2 * a.count(a[n // 2]) - n)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	d = dict()
	for x in a:
		if not x in d:
			d[x] = 0
		d[x] += 1
	print(max(0, 2 * max(d.values()) - n, n % 2))


import sys
from sys import stdin
import math
from collections import deque

def iinput():
	return int(input())

def minput():
	return map(int, input().split())

def linput():
	return list(map(int, input().split()))

def fiinput():
	return int(stdin.readline())

def fminput():
	return map(int, stdin.readline().strip().split())

def flinput():
	return list(map(int, stdin.readline().strip().split()))
for _ in range(iinput()):
	n = iinput()
	list1 = linput()
	list1.sort()
	list1 = deque(list1)
	c = 0
	dict1 = {}
	for i in range(len(list1)):
		if list1[i] in dict1:
			dict1[list1[i]] += 1
		else:
			dict1[list1[i]] = 1
	m = max(dict1.values())
	if n % 2 == 0:
		if m > n // 2:
			print((m - n // 2) * 2)
		else:
			print(0)
	elif m > n // 2:
		print((m - 1 - n // 2) * 2 + 1)
	else:
		print(1)


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	a.sort()
	temp = 1
	if n == 1:
		print(1)
		continue
	count = []
	for i in range(1, n):
		if a[i] == a[i - 1]:
			temp += 1
			if i == n - 1:
				count.append(temp)
		else:
			count.append(temp)
			temp = 1
			if i == n - 1:
				count.append(temp)
	count.sort()
	if len(count) == 1:
		print(count[0])
		continue
	if count[-1] <= sum(count[:len(count) - 1]):
		print(n % 2)
	else:
		print(count[-1] - sum(count[:len(count) - 1]))


from sys import stdin, stdout
input = stdin.readline
import heapq
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	d = {}
	for i in a:
		d[i] = d.get(i, 0) - 1
	val = list(d.values())
	heapq.heapify(val)
	while len(val):
		if len(val) <= 1:
			break
		val1 = abs(heapq.heappop(val))
		val2 = abs(heapq.heappop(val))
		val1 = max(0, val1 - 1)
		val2 = max(0, val2 - 1)
		if val1:
			heapq.heappush(val, -val1)
		if val2:
			heapq.heappush(val, -val2)
	if len(val) == 0:
		print(0)
	else:
		print(-val[0])


n = int(input())
X = []
for i in range(n):
	m = int(input())
	X.append(list(map(int, input().split(' '))))
for x in X:
	counter = {}
	counter[0] = 0
	has_max_count = 0
	result = 0
	for (i, y) in enumerate(x):
		if y in counter:
			counter[y] += 1
		else:
			counter[y] = 1
		if counter[y] > counter[has_max_count]:
			has_max_count = y
			result = 0
		if y == has_max_count and counter[y] > (i + 1) // 2:
			result += 1
		elif result > 0:
			result -= 1
	if result == 0 and i % 2 == 0:
		result = 1
	print(result)


import sys
input = sys.stdin.readline
from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = Counter(a).most_common()
	if len(c) == 1:
		print(c[0][1])
	else:
		xx = c[0][1]
		yy = 0
		for y in range(1, len(c)):
			yy += c[y][1]
		if xx < yy:
			print(n % 2)
		else:
			print(xx - yy)


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	dic = defaultdict(lambda : 0)
	for el in a:
		dic[el] += 1
	b = list(dic.values())
	b.sort()
	k = 0
	for i in range(1, len(b)):
		if i != len(b) - 1:
			k += 2 * b[i - 1]
		b[i] -= b[i - 1]
	left = b[-1]
	ans = 0
	if left % 2 != 0 and k > 0:
		ans = 1
		left -= 1
	ans += max(0, left - k)
	print(ans)


from collections import defaultdict
from heapq import heappush, heappop
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = defaultdict(int)
	for x in a:
		d[x] += 1
	if len(d) < 2:
		print(n)
		continue
	heap = []
	for (k, v) in d.items():
		heappush(heap, [-v, k])
	while len(heap) > 1:
		first = heappop(heap)
		second = heappop(heap)
		d[first[1]] -= 1
		d[second[1]] -= 1
		if d[first[1]] > 0:
			heappush(heap, [-d[first[1]], first[1]])
		if d[second[1]] > 0:
			heappush(heap, [-d[second[1]], second[1]])
	if len(heap) == 0:
		print(0)
	else:
		print(d[heap[0][1]])


t = int(input())
for p in range(t):
	n = int(input())
	a = dict()
	my_input = input().split()
	for x in my_input:
		a[x] = 0
	for i in range(len(my_input)):
		a[my_input[i]] += 1
	b = set(my_input)
	mx = max(a.values())
	for x in a:
		if a[x] == mx:
			c = x
			break
	for x in b:
		if x == c:
			continue
		mx -= a[x]
	if mx < 0:
		mx = 0
	if n % 2 and mx == 0:
		mx = 1
	print(mx)


from collections import *
from sys import *
input = stdin.readline
for u in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = defaultdict(int)
	for i in l:
		d[i] += 1
	ka = list(d.values())
	m = max(ka)
	x = min(m, n - m)
	if x == m:
		print((n - m - x) % 2)
	else:
		print(max(0, n - 2 * x))


import sys
inputlines = sys.stdin.readlines()
number_of_testcases = int(inputlines[0].strip())

def make_freq_dict(input_list):
	freq_dict = {}
	for i in input_list:
		if i not in freq_dict:
			freq_dict[i] = 0
		freq_dict[i] += 1
	return freq_dict
for i in range(number_of_testcases):
	n = int(inputlines[2 * i + 1].strip())
	integers = list(map(int, inputlines[2 * i + 2].strip().split(' ')))
	freq_dict = make_freq_dict(integers)
	values_list = list(freq_dict.values())
	values_list.sort(reverse=True)
	length_values_list = len(values_list)
	if length_values_list == 1:
		print(n)
		continue
	sum_other_than_maximum = 0
	for j in range(1, length_values_list):
		sum_other_than_maximum += values_list[j]
	if values_list[0] <= sum_other_than_maximum:
		if n % 2 == 0:
			print(0)
		else:
			print(1)
	else:
		print(values_list[0] - sum_other_than_maximum)


def helper(a, n):
	d = {}
	for i in range(n):
		d[a[i]] = d.get(a[i], 0) + 1
	m = max(d.values())
	if m <= (n + 1) // 2:
		return n % 2
	else:
		return m - (n - m)
t = int(input())
for i in range(t):
	n = int(input())
	a = list(input().split(' '))
	print(helper(a, n))


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	s = input().split()
	count = Counter(s)
	maxc = 0
	for i in count:
		if maxc < count[i]:
			maxc = count[i]
	print((1 if len(s) % 2 == 1 else 0) if maxc * 2 <= len(s) else maxc * 2 - len(s))


for k in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	for i in a:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	max_count = max(d.values())
	if max_count > n // 2:
		ans = max_count - (n - max_count)
		print(ans)
	elif n % 2 == 0:
		print(0)
	else:
		print(1)


for u in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	dic = {}
	for num in a:
		if num in dic:
			dic[num] += 1
		else:
			dic[num] = 1
	k = max(dic.values())
	if k <= (n + 1) // 2:
		print(1 if n & 1 else 0)
	else:
		print(2 * k - n)


t = int(input().strip())
for _ in range(t):
	n = int(input().strip())
	d = {}
	for i in input().split():
		d[i] = d.get(i, 0) + 1
	M = max(d.values())
	S = sum(d.values())
	if 2 * M > S:
		print(2 * M - S)
	else:
		print(n % 2)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = list(set(a))
	if len(s) == 1:
		print(n)
		continue
	elif len(s) == n:
		print(n % 2)
		continue
	else:
		d = {}
		for i in a:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		maxx = max(d.values())
		if n < 2 * maxx:
			print(2 * maxx - n)
		elif n % 2 == 1:
			print(1)
		else:
			print(0)


t = int(input())
ans = []
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	a.sort()
	mx = 0
	l = 1
	for i in range(n - 1):
		if a[i] == a[i + 1]:
			l += 1
		else:
			mx = max(l, mx)
			l = 1
	mx = max(l, mx)
	if mx * 2 <= n:
		ans.append(n % 2)
	else:
		ans.append(mx * 2 - n)
for i in ans:
	print(i)


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	d = {}
	K = []
	k = 0
	for j in arr:
		if j in d.keys():
			d[j] += 1
		else:
			d.update({j: 1})
			k += 1
	for j in d:
		K.append(d[j])
	if k == 1:
		print(K[0])
		continue
	if max(K) > sum(K) - max(K):
		print(2 * max(K) - sum(K))
	else:
		print(sum(K) % 2)


import math
from sys import stdin
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	l = list(map(int, stdin.readline().split()))
	d = {}
	for i in l:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	m = max(d.values())
	if m * 2 <= n:
		if n % 2 == 1:
			print(1)
		else:
			print(0)
	else:
		print(m * 2 - n)


from collections import Counter as cc
from copy import deepcopy
import random
from collections import defaultdict as dd
try:
	t = int(input())
	while t:
		n = int(input())
		a = list(map(int, input().split()))
		ac = cc(a)
		ac = {k: v for (k, v) in sorted(ac.items(), key=lambda item: item[1], reverse=True)}
		al = list(ac.keys())
		ans = 0
		if ac[al[0]] > n // 2:
			ans = n - 2 * (n - ac[al[0]])
		else:
			ans = n % 2
		print(ans)
		t -= 1
except EOFError as e:
	pass


import sys
import math

def ans(x):
	dito = {}
	for i in x:
		if i not in dito:
			dito[i] = 1
		else:
			dito[i] += 1
	arr = list(dito.values())
	if len(x) % 2 == 0:
		sol = 0
	else:
		sol = 1
	maxi = max(arr)
	return max(sol, maxi - (len(x) - maxi))
for _ in range(int(input())):
	n = int(input())
	x = [int(n) for n in input().split()]
	print(ans(x))


T = int(input())
for _ in range(T):
	n = int(input())
	arr = list(map(int, input().split()))
	d = {}
	for i in arr:
		d[i] = d.get(i, 0) + 1
	d = sorted(d.items(), key=lambda x: x[1])
	k = d[-1][1]
	if n % 2 == 1:
		ans = max(1, k - (n - k))
	else:
		ans = max(0, k - (n - k))
	print(ans)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect, insort
from time import perf_counter
from fractions import Fraction
import copy
from copy import deepcopy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass

def pmat(A):
	for ele in A:
		print(*ele, end='\n')
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	c = C(arr)
	maxc = 0
	for x in c:
		if c[x] > maxc:
			maxc = c[x]
	if 2 * maxc <= n:
		if n % 2 == 0:
			print(0)
		else:
			print(1)
	else:
		print(2 * maxc - n)
endtime = time.time()


import sys
import math
import itertools
input = sys.stdin.readline

def solve():
	n = int(input())
	dat = list(map(int, input().split()))
	dat.sort()
	v = dat[0]
	count = 1
	res = []
	for i in range(1, n):
		if dat[i] == v:
			count += 1
		else:
			res.append(count)
			v = dat[i]
			count = 1
	res.append(count)
	res.sort()
	if len(res) == 1:
		print(res[0])
	else:
		sm = sum(res[:-1])
		if sm < res[-1]:
			print(res[-1] - sm)
		elif sm == res[-1]:
			print(0)
		else:
			print(sum(res) % 2)
for _ in range(int(input())):
	solve()


for _ in range(int(input())):
	n = int(input())
	s = input().split()
	d = dict()
	for i in s:
		d[i] = d.get(i, 0) + 1
	mx = 0
	for i in d:
		if d[i] > mx:
			mx = d[i]
	if mx >= n - mx:
		print(n - 2 * (n - mx))
	elif n % 2 != 0:
		print(1)
	else:
		print(0)


def divisors(M):
	d = []
	i = 1
	while M >= i ** 2:
		if M % i == 0:
			d.append(i)
			if i ** 2 != M:
				d.append(M // i)
		i = i + 1
	return d

def popcount(x):
	x = x - (x >> 1 & 1431655765)
	x = (x & 858993459) + (x >> 2 & 858993459)
	x = x + (x >> 4) & 252645135
	x = x + (x >> 8)
	x = x + (x >> 16)
	return x & 127

def eratosthenes(n):
	res = [0 for i in range(n + 1)]
	prime = set([])
	for i in range(2, n + 1):
		if not res[i]:
			prime.add(i)
			for j in range(1, n // i + 1):
				res[i * j] = 1
	return prime

def factorization(n):
	res = []
	for p in prime:
		if n % p == 0:
			while n % p == 0:
				n //= p
			res.append(p)
	if n != 1:
		res.append(n)
	return res

def euler_phi(n):
	res = n
	for x in range(2, n + 1):
		if x ** 2 > n:
			break
		if n % x == 0:
			res = res // x * (x - 1)
			while n % x == 0:
				n //= x
	if n != 1:
		res = res // n * (n - 1)
	return res

def ind(b, n):
	res = 0
	while n % b == 0:
		res += 1
		n //= b
	return res

def isPrimeMR(n):
	d = n - 1
	d = d // (d & -d)
	L = [2, 3, 5, 7, 11, 13, 17]
	for a in L:
		t = d
		y = pow(a, t, n)
		if y == 1:
			continue
		while y != n - 1:
			y = y * y % n
			if y == 1 or t == n - 1:
				return 0
			t <<= 1
	return 1

def findFactorRho(n):
	from math import gcd
	m = 1 << n.bit_length() // 8
	for c in range(1, 99):
		f = lambda x: (x * x + c) % n
		(y, r, q, g) = (2, 1, 1, 1)
		while g == 1:
			x = y
			for i in range(r):
				y = f(y)
			k = 0
			while k < r and g == 1:
				ys = y
				for i in range(min(m, r - k)):
					y = f(y)
					q = q * abs(x - y) % n
				g = gcd(q, n)
				k += m
			r <<= 1
		if g == n:
			g = 1
			while g == 1:
				ys = f(ys)
				g = gcd(abs(x - ys), n)
		if g < n:
			if isPrimeMR(g):
				return g
			elif isPrimeMR(n // g):
				return n // g
			return findFactorRho(g)

def primeFactor(n):
	i = 2
	ret = {}
	rhoFlg = 0
	while i * i <= n:
		k = 0
		while n % i == 0:
			n //= i
			k += 1
		if k:
			ret[i] = k
		i += 1 + i % 2
		if i == 101 and n >= 2 ** 20:
			while n > 1:
				if isPrimeMR(n):
					(ret[n], n) = (1, 1)
				else:
					rhoFlg = 1
					j = findFactorRho(n)
					k = 0
					while n % j == 0:
						n //= j
						k += 1
					ret[j] = k
	if n > 1:
		ret[n] = 1
	if rhoFlg:
		ret = {x: ret[x] for x in sorted(ret)}
	return ret

def divisors(n):
	res = [1]
	prime = primeFactor(n)
	for p in prime:
		newres = []
		for d in res:
			for j in range(prime[p] + 1):
				newres.append(d * p ** j)
		res = newres
	res.sort()
	return res

def xorfactorial(num):
	if num == 0:
		return 0
	elif num == 1:
		return 1
	elif num == 2:
		return 3
	elif num == 3:
		return 0
	else:
		x = baseorder(num)
		return 2 ** x * ((num - 2 ** x + 1) % 2) + function(num - 2 ** x)

def xorconv(n, X, Y):
	if n == 0:
		res = [X[0] * Y[0] % mod]
		return res
	x = [X[i] + X[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	y = [Y[i] + Y[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	z = [X[i] - X[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	w = [Y[i] - Y[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	res1 = xorconv(n - 1, x, y)
	res2 = xorconv(n - 1, z, w)
	former = [(res1[i] + res2[i]) * inv for i in range(2 ** (n - 1))]
	latter = [(res1[i] - res2[i]) * inv for i in range(2 ** (n - 1))]
	former = list(map(lambda x: x % mod, former))
	latter = list(map(lambda x: x % mod, latter))
	return former + latter

def merge_sort(A, B):
	(pos_A, pos_B) = (0, 0)
	(n, m) = (len(A), len(B))
	res = []
	while pos_A < n and pos_B < m:
		(a, b) = (A[pos_A], B[pos_B])
		if a < b:
			res.append(a)
			pos_A += 1
		else:
			res.append(b)
			pos_B += 1
	res += A[pos_A:]
	res += B[pos_B:]
	return res

class UnionFindVerSize:

	def __init__(self, N):
		self._parent = [n for n in range(0, N)]
		self._size = [1] * N
		self.group = N

	def find_root(self, x):
		if self._parent[x] == x:
			return x
		self._parent[x] = self.find_root(self._parent[x])
		stack = [x]
		while self._parent[stack[-1]] != stack[-1]:
			stack.append(self._parent[stack[-1]])
		for v in stack:
			self._parent[v] = stack[-1]
		return self._parent[x]

	def unite(self, x, y):
		gx = self.find_root(x)
		gy = self.find_root(y)
		if gx == gy:
			return
		self.group -= 1
		if self._size[gx] < self._size[gy]:
			self._parent[gx] = gy
			self._size[gy] += self._size[gx]
		else:
			self._parent[gy] = gx
			self._size[gx] += self._size[gy]

	def get_size(self, x):
		return self._size[self.find_root(x)]

	def is_same_group(self, x, y):
		return self.find_root(x) == self.find_root(y)

class WeightedUnionFind:

	def __init__(self, N):
		self.parent = [i for i in range(N)]
		self.size = [1 for i in range(N)]
		self.val = [0 for i in range(N)]
		self.flag = True
		self.edge = [[] for i in range(N)]

	def dfs(self, v, pv):
		stack = [(v, pv)]
		new_parent = self.parent[pv]
		while stack:
			(v, pv) = stack.pop()
			self.parent[v] = new_parent
			for (nv, w) in self.edge[v]:
				if nv != pv:
					self.val[nv] = self.val[v] + w
					stack.append((nv, v))

	def unite(self, x, y, w):
		if not self.flag:
			return
		if self.parent[x] == self.parent[y]:
			self.flag = self.val[x] - self.val[y] == w
			return
		if self.size[self.parent[x]] > self.size[self.parent[y]]:
			self.edge[x].append((y, -w))
			self.edge[y].append((x, w))
			self.size[x] += self.size[y]
			self.val[y] = self.val[x] - w
			self.dfs(y, x)
		else:
			self.edge[x].append((y, -w))
			self.edge[y].append((x, w))
			self.size[y] += self.size[x]
			self.val[x] = self.val[y] + w
			self.dfs(x, y)

class Dijkstra:

	class Edge:

		def __init__(self, _to, _cost):
			self.to = _to
			self.cost = _cost

	def __init__(self, V):
		self.G = [[] for i in range(V)]
		self._E = 0
		self._V = V

	@property
	def E(self):
		return self._E

	@property
	def V(self):
		return self._V

	def add_edge(self, _from, _to, _cost):
		self.G[_from].append(self.Edge(_to, _cost))
		self._E += 1

	def shortest_path(self, s):
		import heapq
		que = []
		d = [10 ** 15] * self.V
		d[s] = 0
		heapq.heappush(que, (0, s))
		while len(que) != 0:
			(cost, v) = heapq.heappop(que)
			if d[v] < cost:
				continue
			for i in range(len(self.G[v])):
				e = self.G[v][i]
				if d[e.to] > d[v] + e.cost:
					d[e.to] = d[v] + e.cost
					heapq.heappush(que, (d[e.to], e.to))
		return d

def Z_algorithm(s):
	N = len(s)
	Z_alg = [0] * N
	Z_alg[0] = N
	i = 1
	j = 0
	while i < N:
		while i + j < N and s[j] == s[i + j]:
			j += 1
		Z_alg[i] = j
		if j == 0:
			i += 1
			continue
		k = 1
		while i + k < N and k + Z_alg[k] < j:
			Z_alg[i + k] = Z_alg[k]
			k += 1
		i += k
		j -= k
	return Z_alg

class BIT:

	def __init__(self, n, mod=0):
		self.BIT = [0] * (n + 1)
		self.num = n
		self.mod = mod

	def query(self, idx):
		res_sum = 0
		mod = self.mod
		while idx > 0:
			res_sum += self.BIT[idx]
			if mod:
				res_sum %= mod
			idx -= idx & -idx
		return res_sum

	def update(self, idx, x):
		mod = self.mod
		while idx <= self.num:
			self.BIT[idx] += x
			if mod:
				self.BIT[idx] %= mod
			idx += idx & -idx
		return

class dancinglink:

	def __init__(self, n, debug=False):
		self.n = n
		self.debug = debug
		self._left = [i - 1 for i in range(n)]
		self._right = [i + 1 for i in range(n)]
		self.exist = [True for i in range(n)]

	def pop(self, k):
		if self.debug:
			assert self.exist[k]
		L = self._left[k]
		R = self._right[k]
		if L != -1:
			if R != self.n:
				(self._right[L], self._left[R]) = (R, L)
			else:
				self._right[L] = self.n
		elif R != self.n:
			self._left[R] = -1
		self.exist[k] = False

	def left(self, idx, k=1):
		if self.debug:
			assert self.exist[idx]
		res = idx
		while k:
			res = self._left[res]
			if res == -1:
				break
			k -= 1
		return res

	def right(self, idx, k=1):
		if self.debug:
			assert self.exist[idx]
		res = idx
		while k:
			res = self._right[res]
			if res == self.n:
				break
			k -= 1
		return res

class SparseTable:

	def __init__(self, A, merge_func, ide_ele):
		N = len(A)
		n = N.bit_length()
		self.table = [[ide_ele for i in range(n)] for i in range(N)]
		self.merge_func = merge_func
		for i in range(N):
			self.table[i][0] = A[i]
		for j in range(1, n):
			for i in range(0, N - 2 ** j + 1):
				f = self.table[i][j - 1]
				s = self.table[i + 2 ** (j - 1)][j - 1]
				self.table[i][j] = self.merge_func(f, s)

	def query(self, s, t):
		b = t - s + 1
		m = b.bit_length() - 1
		return self.merge_func(self.table[s][m], self.table[t - 2 ** m + 1][m])

class BinaryTrie:

	class node:

		def __init__(self, val):
			self.left = None
			self.right = None
			self.max = val

	def __init__(self):
		self.root = self.node(-10 ** 15)

	def append(self, key, val):
		pos = self.root
		for i in range(29, -1, -1):
			pos.max = max(pos.max, val)
			if key >> i & 1:
				if pos.right is None:
					pos.right = self.node(val)
					pos = pos.right
				else:
					pos = pos.right
			elif pos.left is None:
				pos.left = self.node(val)
				pos = pos.left
			else:
				pos = pos.left
		pos.max = max(pos.max, val)

	def search(self, M, xor):
		res = -10 ** 15
		pos = self.root
		for i in range(29, -1, -1):
			if pos is None:
				break
			if M >> i & 1:
				if xor >> i & 1:
					if pos.right:
						res = max(res, pos.right.max)
					pos = pos.left
				else:
					if pos.left:
						res = max(res, pos.left.max)
					pos = pos.right
			elif xor >> i & 1:
				pos = pos.right
			else:
				pos = pos.left
		if pos:
			res = max(res, pos.max)
		return res

def solveequation(edge, ans, n, m):
	x = [0] * m
	used = [False] * n
	for v in range(n):
		if used[v]:
			continue
		y = dfs(v)
		if y != 0:
			return False
	return x

	def dfs(v):
		used[v] = True
		r = ans[v]
		for (to, dire, id) in edge[v]:
			if used[to]:
				continue
			y = dfs(to)
			if dire == -1:
				x[id] = y
			else:
				x[id] = -y
			r += y
		return r

class Matrix:
	mod = 10 ** 9 + 7

	def set_mod(m):
		Matrix.mod = m

	def __init__(self, L):
		self.row = len(L)
		self.column = len(L[0])
		self._matrix = L
		for i in range(self.row):
			for j in range(self.column):
				self._matrix[i][j] %= Matrix.mod

	def __getitem__(self, item):
		if type(item) == int:
			raise IndexError('you must specific row and column')
		elif len(item) != 2:
			raise IndexError('you must specific row and column')
		(i, j) = item
		return self._matrix[i][j]

	def __setitem__(self, item, val):
		if type(item) == int:
			raise IndexError('you must specific row and column')
		elif len(item) != 2:
			raise IndexError('you must specific row and column')
		(i, j) = item
		self._matrix[i][j] = val

	def __add__(self, other):
		if (self.row, self.column) != (other.row, other.column):
			raise SizeError('sizes of matrixes are different')
		res = [[0 for j in range(self.column)] for i in range(self.row)]
		for i in range(self.row):
			for j in range(self.column):
				res[i][j] = self._matrix[i][j] + other._matrix[i][j]
				res[i][j] %= Matrix.mod
		return Matrix(res)

	def __sub__(self, other):
		if (self.row, self.column) != (other.row, other.column):
			raise SizeError('sizes of matrixes are different')
		res = [[0 for j in range(self.column)] for i in range(self.row)]
		for i in range(self.row):
			for j in range(self.column):
				res[i][j] = self._matrix[i][j] - other._matrix[i][j]
				res[i][j] %= Matrix.mod
		return Matrix(res)

	def __mul__(self, other):
		if type(other) != int:
			if self.column != other.row:
				raise SizeError('sizes of matrixes are different')
			res = [[0 for j in range(other.column)] for i in range(self.row)]
			for i in range(self.row):
				for j in range(other.column):
					temp = 0
					for k in range(self.column):
						temp += self._matrix[i][k] * other._matrix[k][j]
					res[i][j] = temp % Matrix.mod
			return Matrix(res)
		else:
			n = other
			res = [[n * self._matrix[i][j] % Matrix.mod for j in range(self.column)] for i in range(self.row)]
			return Matrix(res)

	def __pow__(self, m):
		if self.column != self.row:
			raise MatrixPowError('the size of row must be the same as that of column')
		n = self.row
		res = Matrix([[int(i == j) for i in range(n)] for j in range(n)])
		while m:
			if m % 2 == 1:
				res = res * self
			self = self * self
			m //= 2
		return res

	def __str__(self):
		res = []
		for i in range(self.row):
			for j in range(self.column):
				res.append(str(self._matrix[i][j]))
				res.append(' ')
			res.append('\n')
		res = res[:len(res) - 1]
		return ''.join(res)
import sys, random, bisect
from collections import deque, defaultdict
from heapq import heapify, heappop, heappush
from itertools import permutations
from math import log, gcd
input = lambda : sys.stdin.readline().rstrip()
mi = lambda : map(int, input().split())
li = lambda : list(mi())
ans = []
for _ in range(int(input())):
	n = int(input())
	A = li()
	dic = {a: 0 for a in A}
	for a in A:
		dic[a] += 1
	m = max((dic[a] for a in A))
	if 2 * m > n:
		ans.append(2 * m - n)
	else:
		ans.append(n % 2)
print(*ans, sep='\n')


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	arr = [int(w) for w in input().split(' ')]
	d = Counter(arr)
	v = [w for w in d.values()]
	import heapq
	maxHeap = []
	for item in v:
		if item != 0:
			heapq.heappush(maxHeap, -item)
	while len(maxHeap) >= 2:
		(f, g) = (-heapq.heappop(maxHeap), -heapq.heappop(maxHeap))
		f = f - 1
		g = g - 1
		if f != 0:
			heapq.heappush(maxHeap, -f)
		if g != 0:
			heapq.heappush(maxHeap, -g)
	ans = 0
	for item in maxHeap:
		ans = ans - item
	print(ans)


import sys
input = sys.stdin.readline

class Problem:

	def __init__(self):
		pass

	def solve(self):
		ans = 0
		n = int(input())
		A = list(map(int, input().split()))
		count = {}
		maxcount = 0
		for a in A:
			if a not in count:
				count[a] = 0
			count[a] += 1
			maxcount = max(maxcount, count[a])
		ans = max(n % 2, 2 * maxcount - n)
		print(ans)

def main():
	p = Problem()
	t = int(input())
	while t:
		p.solve()
		t -= 1
main()


import collections
for i in range(int(input())):
	n = int(input())
	a = [int(j) for j in input().split()]
	a.sort()
	counter = collections.Counter(a)
	b = list(counter.values())
	b.sort(reverse=True)
	if b[0] <= n / 2:
		print(n % 2)
	elif b[0] > n / 2:
		print(b[0] - (n - b[0]))


import io
import os
from collections import defaultdict
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	counts = defaultdict(int)
	for x in a:
		counts[x] += 1
	counts = counts.values()
	m = max(counts)
	if m >= n / 2:
		print(m - (n - m))
		return
	print(n % 2)
t = int(input())
for _ in range(t):
	solve()


def ret(a, n):
	res = 0
	prind = 0
	val = a[0]
	for i in range(1, n):
		vali = a[i]
		if vali != val:
			res = max(res, i - prind)
			prind = i
			val = vali
	res = max(res, n - prind)
	return res
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	r = ret(a, n)
	if r > n / 2:
		print(2 * r - n)
	elif n % 2 == 1:
		print(1)
	else:
		print(0)


import os
import math
true = True
false = False
from collections import defaultdict, deque, Counter
from functools import reduce
from heapq import *
is_dev = 'vscode' in os.environ
if is_dev:
	inF = open('in.txt', 'r')
	outF = open('out.txt', 'w')

def ins():
	return list(map(int, input_().split(' ')))

def inss():
	return list(input_().split(' '))

def inti():
	return int(input_())

def input_():
	if is_dev:
		return inF.readline()[:-1]
	else:
		return input()

def ranin():
	return range(int(input_()))

def print_(data):
	if is_dev:
		outF.write(str(data) + '\n')
	else:
		print(data)
epsilon = 1e-07

def q1():
	for _ in ranin():
		(n, m, x) = ins()
		c = (x - 1) // n
		r = (x - 1) % n
		print_(r * m + c + 1)

def q2():
	for _ in ranin():
		(n, k) = ins()
		s = input_()
		prev = s.index('*')
		last = s.rfind('*')
		last_star = prev
		last_star_solved = True
		c = 2 if last != prev else 1
		for idx in range(prev + 1, last + 1):
			if idx - prev > k and (not last_star_solved):
				c += 1
				prev = last_star
				last_star_solved = True
			if s[idx] == '*':
				last_star = idx
				last_star_solved = False
		print_(c)

def q3():
	a = input_()
	b = input_()
	n = len(a)
	m = len(b)
	maxi = 0
	for si in range(n):
		sj = 0
		p1 = 0
		p2 = 1
		while si < n and sj < m:
			if a[si] != b[sj]:
				p1 = p2
			maxi = max(p2 - p1, maxi)
			p2 += 1
			si += 1
			sj += 1
	for sj in range(m):
		si = 0
		p1 = 0
		p2 = 1
		while si < n and sj < m:
			if a[si] != b[sj]:
				p1 = p2
			maxi = max(p2 - p1, maxi)
			p2 += 1
			si += 1
			sj += 1
	return n - maxi + m - maxi

def q4():
	n = inti()
	a = ins()
	a = list(map(lambda x: -x, Counter(a).values()))
	heapify(a)
	while len(a) > 1:
		a1 = -heappop(a)
		a2 = -heappop(a)
		if a1 - 1:
			heappush(a, -(a1 - 1))
		if a2 - 1:
			heappush(a, -(a2 - 1))
	return -a[0] if a else 0
for _ in ranin():
	print_(q4())
if is_dev:
	outF.close()

	def compare_file():
		print(open('out.txt', 'r').read() == open('outactual.txt', 'r').read())
	compare_file()


def main():
	from sys import stdin, stdout
	from collections import Counter
	rl = stdin.readline
	wl = stdout.write
	for _ in range(int(rl())):
		n = int(rl().strip())
		c = Counter(rl().strip().split())
		a = c.most_common(1)[0][1]
		if a * 2 <= n:
			wl(str(n % 2) + '\n')
		else:
			wl(str(2 * a - n) + '\n')
main()


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	a.sort()
	h = n // 2 + n % 2
	cnt = n
	for i in range(n // 2):
		if a[i] != a[i + h]:
			cnt -= 2
	print(cnt)


from collections import Counter
from sys import stdin, stdout
import heapq
ans = []

def solve():
	n = int(stdin.readline())
	arr = Counter(list(map(int, stdin.readline().split())))
	ans_arr = list(arr.values())
	if len(ans_arr) == 1:
		ans.append(str(ans_arr[0]))
		return
	ans_arr = [-x for x in ans_arr]
	heapq.heapify(ans_arr)
	while len(ans_arr) >= 2:
		a = -heapq.heappop(ans_arr) - 1
		b = -heapq.heappop(ans_arr) - 1
		if a:
			heapq.heappush(ans_arr, -a)
		if b:
			heapq.heappush(ans_arr, -b)
	if ans_arr:
		ans.append(str(-sum(ans_arr)))
	else:
		ans.append('0')
for _ in range(int(stdin.readline())):
	solve()
print('\n'.join(ans))


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(Counter(a).values())
	last = b.pop()
	sumb = sum(b)
	ans = last - sumb
	if sumb > last:
		ans %= 2
	print(ans)


from collections import defaultdict

def func():
	n = int(input())
	a_dict = defaultdict(int)
	a_list = input().split()
	for i in a_list:
		a_dict[i] += 1
	if len(a_dict) < 2:
		return n
	freq = list(a_dict.values())
	freq.sort(reverse=True)
	y = n
	x = freq[0]
	if x > y - x:
		ans = 2 * x - y
	elif y & 1:
		ans = 1
	else:
		ans = 0
	return ans
t = int(input())
ans = []
for i in range(t):
	ans.append(func())
for i in range(len(ans)):
	print(ans[i])


from sys import stdin
import heapq
input = stdin.readline

class MaxHeap:

	def __init__(self):
		self.data = []

	def top(self):
		return -self.data[0]

	def push(self, val):
		heapq.heappush(self.data, -val)

	def pop(self):
		return -heapq.heappop(self.data)
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	dic = {}
	for d in arr:
		if d not in dic:
			dic[d] = 0
		dic[d] += 1
	new = []
	for d in dic:
		new.append(dic[d])
	k = len(new)
	maxheap = MaxHeap()
	for d in dic:
		maxheap.push(dic[d])
	while True:
		if k >= 2:
			k -= 2
			x = maxheap.pop()
			y = maxheap.pop()
			x -= 1
			y -= 1
			if x > 0:
				maxheap.push(x)
				k += 1
			if y > 0:
				maxheap.push(y)
				k += 1
		elif k == 1:
			print(maxheap.pop())
			break
		else:
			print(0)
			break


from collections import Counter, defaultdict, deque
import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	arr = [int(_) for _ in input().split()]
	c = Counter(arr)
	m = max(c.items(), key=lambda x: x[1])
	if n % 2:
		n -= 1
		print(max(1, 1 + n - 2 * (n - m[1] + 1)))
	else:
		print(max(0, n - 2 * (n - m[1])))
tt = int(input())
for test in range(tt):
	solve()


k = int(input())

def chop(x):
	if 2 * max(x) > sum(x):
		return 2 * max(x) - sum(x)
	else:
		return sum(x) % 2
for i in range(k):
	g = int(input())
	ar = list(map(int, input().split()))
	d = {}
	for x in ar:
		d[x] = d.get(x, 0) + 1
	count_list = list(d.values())
	print(chop(count_list))


for _ in range(int(input())):
	n = int(input())
	l3 = sorted(list(map(int, input().split())))
	a = 1
	l = []
	for i in range(n - 1):
		if l3[i] == l3[i + 1]:
			a += 1
		else:
			l.append(a)
			a = 1
	else:
		l.append(a)
	print(max(max(l) * 2 - n, n % 2))


from collections import Counter
t = int(input())
res = []
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	acount = Counter(a)
	if max(acount.values()) > n // 2:
		superm = max(acount.values())
		diff = 2 * superm - n
		res.append(diff)
	elif n % 2 == 0:
		res.append(0)
	else:
		res.append(1)
print(*res)


from collections import Counter
from sys import stdin, stdout
input = stdin.readline
print = stdout.write
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arr = sorted(arr)
	(i, j) = (0, n // 2)
	ans = 0
	while i < n // 2 and j < n:
		if arr[i] != arr[j]:
			ans += 1
			i += 1
			j += 1
		else:
			j += 1
	print(str(n - 2 * ans) + '\n')


from sys import stdin, stdout, setrecursionlimit
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log, log2
from random import seed, randint
from datetime import datetime
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
from collections import defaultdict as dd
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def def_value():
	return 0

def def_inf():
	return inf

def atoi(s):
	return ord(s) - ord('a')

def inc(s, n=1):
	return chr((ord(s) - ord('a') + n) % 26 + ord('a'))
for _ in range(iinp()):
	n = iinp()
	a = lmp()
	f = dd(int)
	for i in a:
		f[i] += 1
	x = []
	for i in f.keys():
		x.append(-1 * f[i])
	heapify(x)
	while len(x) > 1:
		a = heappop(x) + 1
		b = heappop(x) + 1
		if a < 0:
			heappush(x, a)
		if b < 0:
			heappush(x, b)
	if len(x) == 0:
		print(0)
	else:
		print(-1 * x[0])


from collections import *
for s in [*open(0)][2::2]:
	l = s.split()
	n = len(l)
	print(max(max(Counter(l).values()) * 2 - n, n % 2))


def Trans(array, n):
	m = 0
	answer = 0
	how_much = {}
	for i in array:
		if i not in how_much:
			how_much[i] = 0
		how_much[i] += 1
	for i in how_much:
		if how_much[i] > m:
			m = how_much[i]
			answer = i
	if n - 2 * (n - m) < 0:
		if n % 2 == 1:
			return 1
		return 0
	return n - 2 * (n - m)
t = int(input())
for i in range(t):
	n = int(input())
	lista = list(map(int, input().split()))
	print(Trans(lista, n))


from sys import stdin, stdout
Pi = lambda x: stdout.write(str(x) + '\n')
Ps = lambda x: stdout.write(str(x))
S = lambda x: (x + (x + 1) // 2) * (x // 2)
I = lambda x: 1 + 2 * x
R = lambda : stdin.readline()
Ri = lambda x: map(int, x.split())
Rs = lambda x: map(str, x.split())
Rf = lambda x: map(float, x.split())
char = lambda x, y: ord(x) - ord(y)
gcd = lambda a, b: a if b == 0 else gcd(b, a % b)
lcm = lambda a, b: a * b // gcd(a, b)
distance = lambda a, b, c, d: (a - c) ** 2 + (b - d) ** 2
Matriz = lambda n, m: [[0 for i in range(m)] for i in range(n)]
MaxN = int(100000.0) + 10
mod = int(1000000000.0) + 7
(fx, fy) = ([0, 0, -1, 1], [1, -1, 0, 0])

def find(u, p):
	if u != p[u]:
		p[u] = find(p[u], p)
	return p[u]

def isPrime(n):
	if n == 2:
		return 1
	if n < 2 or n % 2 == 0:
		return 0
	for i in range(3, int(n ** 0.5) + 1):
		if n % i == 0:
			return 0
	return 1

def bs(A, l, r, x):
	while r - l > 1:
		m = (l + r) // 2
		if A[m] >= x:
			r = m
		else:
			l = m
	return r

def f(a, b):
	(n, m) = (len(a), len(b))
	ans = n + m
	for i in range(1, n + 1):
		for j in range(i, n + 1):
			if a[j - i:j] in b:
				ans = min(ans, n + m - i * 2)
	return ans

def main():
	t = int(R())
	for _ in range(t):
		n = int(R())
		A = list(Ri(R()))
		dic = {}
		mx = 0
		for x in A:
			if x in dic:
				dic[x] += 1
			else:
				dic[x] = 1
			mx = max(mx, dic[x])
		ans = 0
		if mx > n // 2:
			ans = n - (n - mx) * 2
		else:
			ans = n % 2
		Pi(ans)
main()


from sys import stdin, stdout
import math, bisect
from collections import Counter, deque, defaultdict
L = lambda : list(map(int, stdin.readline().strip().split()))
M = lambda : map(int, stdin.readline().strip().split())
I = lambda : int(stdin.readline().strip())
S = lambda : stdin.readline().strip()
C = lambda : stdin.readline().strip().split()

def pr(a):
	return ''.join(list(map(str, a)))

def solve():
	n = I()
	a = L()
	d = Counter(a)
	m = max(d.values())
	if 2 * m > n:
		print(2 * m - n)
	else:
		print(n % 2)
for _ in range(I()):
	solve()


import os
import sys
import math
from io import BytesIO, IOBase
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def dijkstra(start, distance, path, n):
	visited = [False for _ in range(n)]
	distance[start] = 0
	for i in range(n):
		v = -1
		for j in range(n):
			if not visited[v] and (v == -1 or distance[j] < distance[v]):
				v = j
		if distance[v] == math.inf:
			break
		visited[v] = True
		for edge in adj[v]:
			destination = edge[0]
			weight = edge[1]
			if distance[v] + weight < distance[destination]:
				distance[destination] = distance[v] + weight
				path[destination] = v

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def ncr(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def npr(n, r):
	return math.factorial(n) // math.factorial(n - r)

def seive(n):
	primes = [True] * (n + 1)
	ans = []
	for i in range(2, n):
		if not primes[i]:
			continue
		j = 2 * i
		while j <= n:
			primes[j] = False
			j += i
	for p in range(2, n + 1):
		if primes[p]:
			ans += [p]
	return ans

def factors(n):
	factors = []
	x = 1
	while x * x <= n:
		if n % x == 0:
			if n // x == x:
				factors.append(x)
			else:
				factors.append(x)
				factors.append(n // x)
		x += 1
	return factors

def main():
	try:
		for _ in range(inp()):
			n = inp()
			a = inlt()
			d = {}
			mx = 0
			for i in range(n):
				if a[i] not in d:
					d[a[i]] = 0
				d[a[i]] += 1
				mx = max(mx, d[a[i]])
			rest = n - mx
			if mx - rest >= 1:
				print(mx - rest)
			elif n & 1:
				print(1)
			else:
				print(0)
	except Exception as e:
		print(e)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys, os, io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
import math
alphabets = list('abcdefghijklmnopqrstuvwxyz')

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def si():
	return input()

def prefix_sum(arr):
	r = [0] * (len(arr) + 1)
	for (i, el) in enumerate(arr):
		r[i + 1] = r[i] + el
	return r

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')

def power_set(L):
	cardinality = len(L)
	n = 2 ** cardinality
	powerset = []
	for i in range(n):
		a = bin(i)[2:]
		subset = []
		for j in range(len(a)):
			if a[-j - 1] == '1':
				subset.append(L[j])
		powerset.append(subset)
	powerset_orderred = []
	for k in range(cardinality + 1):
		for w in powerset:
			if len(w) == k:
				powerset_orderred.append(w)
	return powerset_orderred

def fastPlrintNextLines(a):
	print('\n'.join(map(str, a)))

def sortByFirstAndSecond(A):
	A = sorted(A, key=lambda x: x[0])
	A = sorted(A, key=lambda x: x[1])
	return list(A)
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def solve():
	n = ii()
	l = li()
	d = defaultdict(lambda : 0)
	for i in l:
		d[i] += 1
	m = max(list(d.values()))
	if 2 * m - n <= 0:
		if n % 2 == 0:
			ans = 0
		else:
			ans = 1
	else:
		ans = 2 * m - n
	print(ans)
t = 1
t = int(input())
for _ in range(t):
	solve()


import sys
from collections import Counter
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		C = Counter(a)
		max_num = max(C, key=C.get)
		if C[max_num] * 2 > n:
			ans = C[max_num] * 2 - n
		elif n % 2 == 1:
			ans = 1
		else:
			ans = 0
		print(ans)
main()


t = int(input())
while t > 0:
	n = int(input())
	a = [int(x) for x in input().split()]
	d = {}
	for i in a:
		if d.get(i) != None:
			d[i] += 1
		else:
			d[i] = 1
	m = max(list(d.values()))
	if m > (n + 1) // 2:
		ans = m - (n - m)
	else:
		ans = n % 2
	print(ans)
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	mp = {}
	for x in a:
		if x in mp:
			mp[x] += 1
		else:
			mp[x] = 1
	b = list(mp.values())
	b.sort(reverse=True)
	res = n % 2
	if b[0] * 2 > n:
		d = n - b[0]
		res = n - 2 * d
	print(res)


from collections import defaultdict
import math
for cases in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = defaultdict(int)
	for i in range(0, len(l)):
		d[l[i]] += 1
	max1 = 0
	for i in d.keys():
		max1 = max(max1, d[i])
	if max1 <= math.ceil(n / 2):
		if n % 2 == 0:
			print(0)
		else:
			print(1)
	else:
		cnt = max1
		for i in d.keys():
			if d[i] != max1:
				cnt = cnt - d[i]
		print(cnt)


t = int(input())
for case in range(t):
	n = int(input())
	d = dict()
	max_count = 1
	for i in map(int, input().split()):
		if i in d:
			d[i] += 1
			if max_count < d[i]:
				max_count = d[i]
		else:
			d[i] = 1
	if n - max_count >= max_count:
		print(n % 2)
	else:
		print(max_count - (n - max_count))


from collections import Counter
for iii in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if len(set(arr)) == 1:
		print(len(arr))
		continue
	if len(set(arr)) == len(arr):
		if n % 2:
			print(1)
		else:
			print(0)
		continue
	ss = dict(Counter(arr))
	rr = list(ss.values())
	maxi = max(rr)
	print(max(n % 2, 2 * maxi - n))


from sys import stdin, stdout
from collections import defaultdict, Counter, deque
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	l = list(map(int, stdin.readline().split()))
	m = dict(Counter(l))
	c = 0
	for (i, j) in m.items():
		c = max(c, j)
	if c <= n - c:
		if n & 1:
			print(1)
		else:
			print(0)
	else:
		print(c - (n - c))


import math
import operator as op
from functools import reduce
from collections import defaultdict
from math import comb
from sys import stdout
NO = 'NO'
YES = 'YES'
MOD = 1000000007

def input_int():
	return int(input())

def input_list():
	return input().split(' ')

def input_list_int():
	return list(map(int, input_list()))

def z_func(s):
	n = len(s)
	z = [0] * n
	l = r = 0
	for i in range(1, n):
		if r >= i:
			z[i] = min(z[i - l], r - i + 1)
		while z[i] + i < n and s[z[i]] == s[z[i] + i]:
			z[i] += 1
		if i + z[i] - 1 > r:
			l = i
			r = i + z[i] - 15
	return z
global_ans = []

def pr(a):
	global_ans.append(a)

def solve():
	n = input_int()
	a = input_list_int()
	tmp = defaultdict(int)
	for i in a:
		tmp[i] += 1
	b = list(tmp.values())
	b.sort(reverse=True)
	mx = b[0]
	for i in range(1, len(b)):
		mx -= b[i]
	pr(max(mx, n % 2))
query_count = 1
query_count = input_int()
while query_count:
	query_count -= 1
	solve()
for global_ans_line in global_ans:
	print(global_ans_line)


import math
from queue import PriorityQueue
t = int(input())

def get_answer(n, a):
	status = {}
	for v in a:
		if v not in status:
			status[v] = -1
		else:
			status[v] -= 1
	q = PriorityQueue(maxsize=n + 1)
	for v in status:
		q.put((status[v], v))
	if q.qsize() == 1:
		ik = q.get()
		return -ik[0]
	while True:
		ia = q.get()
		ib = q.get()
		(va, a) = ia
		(vb, b) = ib
		if vb == 0:
			return -va
		else:
			va += 1
			vb += 1
			q.put((va, a))
			q.put((vb, b))
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(get_answer(n, a))


for _ in range(int(input())):
	(n, d) = (int(input()), {})
	for i in input().split():
		d[i] = d[i] + 1 if i in d.keys() else 1
	m = max(d.values())
	print(2 * m - n if m > n // 2 else n & 1)


kk = int(input())
for i in range(kk):
	l = int(input())
	lst = list(map(int, input().split()))
	lst.sort()
	ans = len(lst)
	if len(lst) % 2 == 0:
		ans1 = lst[:len(lst) // 2]
		ans2 = lst[len(lst) // 2:]
		for i in range(len(lst) // 2):
			if ans1[i] != ans2[i]:
				ans -= 2
	else:
		ans1 = lst[:len(lst) // 2]
		ans2 = lst[len(lst) // 2 + 1:]
		for i in range(len(lst) // 2):
			if ans1[i] != ans2[i]:
				ans -= 2
	print(ans)


from collections import Counter
t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	count = Counter(l)
	maxi = 0
	for k in count:
		if count[k] > maxi:
			maxi = count[k]
	if maxi <= n // 2:
		if n % 2 == 0:
			print(0)
		else:
			print(1)
	else:
		print(maxi - (n - maxi))


test_n = int(input())

class node:

	def __init__(self, v):
		self.v = v
		self.amount = 0
for _ in range(test_n):
	n = int(input())
	a = map(int, input().split(' '))
	m = {}
	l = []
	for i in a:
		if m.get(i):
			m[i] += 1
		else:
			m[i] = 1
	max_val = max(m.values())
	if max_val >= n - max_val:
		print(2 * max_val - n)
		continue
	if n % 2 == 1:
		print(1)
	else:
		print(0)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import heapq
T = int(input())
r = 1
while r <= T:
	n = int(input())
	arr = list(map(int, input().split()))
	dic = {}
	for num in arr:
		if num not in dic:
			dic[num] = 0
		dic[num] += 1
	heap = []
	for num in dic:
		heapq.heappush(heap, -dic[num])
	ans = n
	while len(heap) > 1:
		fre1 = heapq.heappop(heap)
		fre2 = heapq.heappop(heap)
		if fre1 < -1:
			heapq.heappush(heap, fre1 + 1)
		if fre2 < -1:
			heapq.heappush(heap, fre2 + 1)
		ans -= 2
	print(ans)
	r += 1


t = int(input().strip())
for _ in range(t):
	n = int(input().strip())
	d = {}
	for i in input().split():
		d[i] = d.get(i, 0) + 1
	print(max(2 * max(d.values()) - n, n % 2))