You have $n$ students under your control and you have to compose exactly two teams consisting of some subset of your students. Each student had his own skill, the $i$-th student skill is denoted by an integer $a_i$ (different students can have the same skills).

So, about the teams. Firstly, these two teams should have the same size. Two more constraints:  The first team should consist of students with distinct skills (i.e. all skills in the first team are unique).  The second team should consist of students with the same skills (i.e. all skills in the second team are equal). 

Note that it is permissible that some student of the first team has the same skill as a student of the second team.

Consider some examples (skills are given):  $[1, 2, 3]$, $[4, 4]$ is not a good pair of teams because sizes should be the same;  $[1, 1, 2]$, $[3, 3, 3]$ is not a good pair of teams because the first team should not contain students with the same skills;  $[1, 2, 3]$, $[3, 4, 4]$ is not a good pair of teams because the second team should contain students with the same skills;  $[1, 2, 3]$, $[3, 3, 3]$ is a good pair of teams;  $[5]$, $[6]$ is a good pair of teams. 

Your task is to find the maximum possible size $x$ for which it is possible to compose a valid pair of teams, where each team size is $x$ (skills in the first team needed to be unique, skills in the second team should be the same between them). A student cannot be part of more than one team.

You have to answer $t$ independent test cases.


-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Then $t$ test cases follow.

The first line of the test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of students. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$), where $a_i$ is the skill of the $i$-th student. Different students can have the same skills.

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


-----Output-----

For each test case, print the answer — the maximum possible size $x$ for which it is possible to compose a valid pair of teams, where each team size is $x$.


-----Example-----
Input
4
7
4 2 4 1 4 3 4
5
2 1 5 4 3
1
1
4
1 1 1 3

Output
3
1
0
2



-----Note-----

In the first test case of the example, it is possible to construct two teams of size $3$: the first team is $[1, 2, 4]$ and the second team is $[4, 4, 4]$. Note, that there are some other ways to construct two valid teams of size $3$.

Difficulty: introductory

Starter code:

Solutions:
from collections import defaultdict as dd
for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    d=dd(int)
    for i in a:
        d[i]+=1
    ma=0
    r=len(d.keys())
    for i in d.keys():
        ma=max(ma,min(d[i]-1,r),min(d[i],r-1))
    print(ma)

#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    t = I()
    for _ in range(t):
        n = I()
        a = LI()
        x = len(set(a))
        d = defaultdict(lambda : 0)
        for i in a:
            d[i] += 1
        y = max(d.values())
        if x < y:
            print(x)
        elif x == y:
            print(x-1)
        else:
            print(y)
    return

#Solve
def __starting_point():
    solve()

__starting_point()

t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int,input().split()))
	d = {}
	for i in l:
		d[i] = 0
	for i in l:
		d[i] += 1
	myk = len(d)
	maksik = 0
	dupa = -12131
	for i in l:
		if d[i] > maksik:
			maksik = min(d[i],myk-1)
		if d[i] > myk:
			dupa = myk
	print(max(maksik,dupa))

from collections import Counter

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

    c = sorted(Counter(a).values())

    maxi = 0

    for i in range(len(c)):
        maxi = max(maxi, min(c[i], i), min(c[i] - 1, i + 1))

    print(maxi)

from operator import itemgetter
import sys
input = sys.stdin.readline


def compress(string):
    string.append("#")
    n = len(string)
    begin, end, cnt = 0, 1, 1
    ans = []
    while end < n:
        if string[begin] == string[end]:
            end, cnt = end + 1, cnt + 1
        else:
            ans.append((string[begin], cnt))
            begin, end, cnt = end, end + 1, 1
    return ans


t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    a = sorted(a)
    comp = compress(a)
    comp = sorted(comp, key=itemgetter(1))
    same_max = comp[-1][-1]
    kind_max = len(comp)
    if same_max == kind_max:
        print(same_max - 1)
    else:
        print(min(same_max, kind_max))


'''
4
7
4 2 4 1 4 3 4
5
2 1 5 4 3
1
1
4
1 1 1 3
'''
from collections import Counter as c
for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    t = c(a)
    l = [[t[a], a] for a in t]
    l.sort(reverse=True)
    b = l[0][0]
    a = len(l)-1
    print (max(min(a,b), min(a+1,b-1)))

import sys

_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__

from collections import Counter

def go():
    n = int(input())
    # n,a,b = map(int, input().split())
    a = list(map(int, input().split()))
    c = Counter(a)
    m = len(c)
    best=-1
    for cnt in list(c.values()):
        best = max(best,min(cnt,m-1))
        best = max(best,min(cnt-1,m))

    return best

# x,s = map(int,input().split())
t = int(input())
# t = 1
ans = []
for _ in range(t):
    # print(go())
    ans.append(str(go()))
#
print('\n'.join(ans))


from math import *
from collections import *
t = int(input())
for y in range(t):
	n = int(input())
	a = list(map(int,input().split()))
	d = Counter(a)
	diff = len(d)
	same = 0
	for i in d.values():
		same = max(i,same)
	if(diff < same):
		print(diff)
	elif(diff == same):
		print(diff-1)
	else:
		print(same)

t=int(input())
while t:
    n=int(input())
    a=list(map(int,input().split()))
    ls=[0 for i in range(n+1)]
    for i in range(n):
        ls[a[i]]+=1
    dis=len(set(a))
    sam=max(ls)
    print(max(min(dis-1,sam),min(dis,sam-1)))
    t-=1    

t = int(input())
for q in range(0, t):
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    number = 1
    for i in range(0, n - 1):
        if a[i] != a[i + 1]:
            number += 1
    mn = 0
    now = 1
    for i in range(0, n - 1):
        if a[i] == a[i + 1]:
            now += 1
        else:
            mn = max(mn, now)
            now = 1
    mn = max(mn, now)
    print(max(min(number - 1, mn), min(number, mn - 1)))


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

t=int(input())
for tests in range(t):
    n=int(input())
    C=Counter(list(map(int,input().split())))

    LEN=len(C)
    MAX=max(C.values())

    if MAX<LEN:
        print(MAX)
    elif MAX==LEN:
        print(MAX-1)
    else:
        print(LEN)
        


t = int(input())
for _ in range(t):
    n = int(input())
    skills = map(int, input().split())
    d = {}
    for s in skills:
        if s in d:
            d[s] += 1
        else:
            d[s] = 1

    m = 0
    for k in d.keys():
        m = max(m, max(min(d[k], len(d) - 1), min(d[k] - 1, len(d))))
    print(m)

t = int(input(''))
for _ in range(t):
    n = int(input(''))
    a = list(map(int,input('').split(' ')))
    d = {}
    for i in range(n):
        if(a[i] not in d):
            d[a[i]] = 0
        d[a[i]] = d[a[i]]+1
    mx = 0
    l = len(d)
    for k in d:
        if(min(d[k],l-1) > mx):
            mx = min(d[k],l-1)
        if(min(d[k]-1,l) > mx):
            mx = min(d[k]-1,l)
    print(mx)