import collections import heapq T = int(input()) def kado(): N = int(input()) L = collections.Counter(map(int, input().strip().split(" "))) Lv = L.values() if len(Lv) < 3: return 0 heap = [-i for i in Lv] heapq.heapify(heap) total = 0 while True: k1 = heapq.heappop(heap) k2 = heapq.heappop(heap) k3 = heapq.heappop(heap) if k3 == 0: break total += 1 heapq.heappush(heap, k1+1) heapq.heappush(heap, k2+1) heapq.heappush(heap, k3+1) return total print("\n".join([str(kado()) for i in range(T)]))