import sys from collections import Counter from heapq import heapify, heappush, heappop def debug(x, table): for name, val in table.items(): if x is val: print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr) return None def solve(): T = int(input()) for i in range(T): N = int(input()) Ls = [int(i) for i in input().split()] cnt = Counter(Ls) hpq = [-i for i in cnt.values()] heapify(hpq) ans = 0 # debug(hpq, locals()) while len(hpq) >= 3: # debug(hpq, locals()) ans += 1 tmp = [] for j in range(3): tmp.append(hpq[0] + 1) heappop(hpq) for j in range(3): if tmp[j] < 0: heappush(hpq, tmp[j]) print(ans) if __name__ == '__main__': solve()