#!/usr/bin/env python def read(): return input(), map(int, raw_input().split()) def work((N, vList)): vList.sort() used = [False for i in range(N)] A = 0 B = 1 C = 2 ans = 0 while max(A, B, C) < N: while A < N and used[A]: A += 1 while max(A, B) < N and (vList[B] <= vList[A] or used[B]): B += 1 while max(A, B, C) < N and (vList[C] <= vList[B] or used[C]): C += 1 if max(A, B, C) < N: ans += 1 used[A] = used[B] = used[C] = True print ans if __name__ == "__main__": for i in range(input()): work(read())