import heapq import collections t=int(input()) for i in range(t): n=int(input()) l=list(map(int,input().split())) l=collections.Counter(l) l=list(l.values()) if len(l)<3: print(0) else: for i in range(len(l)): l[i]*=-1 heapq.heapify(l) ans=0 for i in range(n//3+1): a=heapq.heappop(l) b=heapq.heappop(l) c=heapq.heappop(l) if a<0 and b<0 and c<0: a+=1;b+=1;c+=1 ans+=1 else: break heapq.heappush(l,a) heapq.heappush(l,b) heapq.heappush(l,c) print(ans)