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$.
[{"code": "from collections import defaultdict as dd\nfor _ in range(int(input())):\n    n=int(input())\n    a=list(map(int,input().split()))\n    d=dd(int)\n    for i in a:\n        d[i]+=1\n    ma=0\n    r=len(d.keys())\n    for i in d.keys():\n        ma=max(ma,min(d[i]-1,r),min(d[i],r-1))\n    print(ma)", "passed": true, "time": 0.14, "memory": 14160.0, "status": "done"}, {"code": "#!usr/bin/env python3\nfrom collections import defaultdict, deque\nfrom heapq import heappush, heappop\nfrom itertools import permutations, accumulate\nimport sys\nimport math\nimport bisect\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\ndef I(): return int(sys.stdin.readline())\ndef LS():return [list(x) for x in sys.stdin.readline().split()]\ndef S():\n    res = list(sys.stdin.readline())\n    if res[-1] == \"\\n\":\n        return res[:-1]\n    return res\ndef IR(n):\n    return [I() for i in range(n)]\ndef LIR(n):\n    return [LI() for i in range(n)]\ndef SR(n):\n    return [S() for i in range(n)]\ndef LSR(n):\n    return [LS() for i in range(n)]\n\nsys.setrecursionlimit(1000000)\nmod = 1000000007\n\ndef solve():\n    t = I()\n    for _ in range(t):\n        n = I()\n        a = LI()\n        x = len(set(a))\n        d = defaultdict(lambda : 0)\n        for i in a:\n            d[i] += 1\n        y = max(d.values())\n        if x < y:\n            print(x)\n        elif x == y:\n            print(x-1)\n        else:\n            print(y)\n    return\n\n#Solve\ndef __starting_point():\n    solve()\n\n__starting_point()", "passed": true, "time": 0.74, "memory": 14440.0, "status": "done"}, {"code": "t = int(input())\nfor i in range(t):\n\tn = int(input())\n\tl = list(map(int,input().split()))\n\td = {}\n\tfor i in l:\n\t\td[i] = 0\n\tfor i in l:\n\t\td[i] += 1\n\tmyk = len(d)\n\tmaksik = 0\n\tdupa = -12131\n\tfor i in l:\n\t\tif d[i] > maksik:\n\t\t\tmaksik = min(d[i],myk-1)\n\t\tif d[i] > myk:\n\t\t\tdupa = myk\n\tprint(max(maksik,dupa))", "passed": true, "time": 0.14, "memory": 14348.0, "status": "done"}, {"code": "from collections import Counter\n\nfor _ in range(int(input())):\n    n = int(input())\n    a = list(map(int, input().split()))\n\n    c = sorted(Counter(a).values())\n\n    maxi = 0\n\n    for i in range(len(c)):\n        maxi = max(maxi, min(c[i], i), min(c[i] - 1, i + 1))\n\n    print(maxi)", "passed": true, "time": 0.14, "memory": 14124.0, "status": "done"}, {"code": "from operator import itemgetter\nimport sys\ninput = sys.stdin.readline\n\n\ndef compress(string):\n    string.append(\"#\")\n    n = len(string)\n    begin, end, cnt = 0, 1, 1\n    ans = []\n    while end < n:\n        if string[begin] == string[end]:\n            end, cnt = end + 1, cnt + 1\n        else:\n            ans.append((string[begin], cnt))\n            begin, end, cnt = end, end + 1, 1\n    return ans\n\n\nt = int(input())\nfor _ in range(t):\n    n = int(input())\n    a = list(map(int, input().split()))\n    a = sorted(a)\n    comp = compress(a)\n    comp = sorted(comp, key=itemgetter(1))\n    same_max = comp[-1][-1]\n    kind_max = len(comp)\n    if same_max == kind_max:\n        print(same_max - 1)\n    else:\n        print(min(same_max, kind_max))\n", "passed": true, "time": 0.14, "memory": 14168.0, "status": "done"}, {"code": "'''\n4\n7\n4 2 4 1 4 3 4\n5\n2 1 5 4 3\n1\n1\n4\n1 1 1 3\n'''\nfrom collections import Counter as c\nfor _ in range(int(input())):\n    n = int(input())\n    a = list(map(int, input().split()))\n    a.sort()\n    t = c(a)\n    l = [[t[a], a] for a in t]\n    l.sort(reverse=True)\n    b = l[0][0]\n    a = len(l)-1\n    print (max(min(a,b), min(a+1,b-1)))", "passed": true, "time": 0.14, "memory": 14260.0, "status": "done"}, {"code": "import sys\n\n_INPUT_LINES = sys.stdin.read().splitlines()\ninput = iter(_INPUT_LINES).__next__\n\nfrom collections import Counter\n\ndef go():\n    n = int(input())\n    # n,a,b = map(int, input().split())\n    a = list(map(int, input().split()))\n    c = Counter(a)\n    m = len(c)\n    best=-1\n    for cnt in list(c.values()):\n        best = max(best,min(cnt,m-1))\n        best = max(best,min(cnt-1,m))\n\n    return best\n\n# x,s = map(int,input().split())\nt = int(input())\n# t = 1\nans = []\nfor _ in range(t):\n    # print(go())\n    ans.append(str(go()))\n#\nprint('\\n'.join(ans))\n", "passed": true, "time": 0.22, "memory": 14096.0, "status": "done"}, {"code": "t=int(input())\nwhile t:\n    n=int(input())\n    a=list(map(int,input().split()))\n    ls=[0 for i in range(n+1)]\n    for i in range(n):\n        ls[a[i]]+=1\n    dis=len(set(a))\n    sam=max(ls)\n    print(max(min(dis-1,sam),min(dis,sam-1)))\n    t-=1    ", "passed": true, "time": 0.14, "memory": 14144.0, "status": "done"}, {"code": "t = int(input())\nfor q in range(0, t):\n    n = int(input())\n    a = list(map(int, input().split()))\n    a.sort()\n    number = 1\n    for i in range(0, n - 1):\n        if a[i] != a[i + 1]:\n            number += 1\n    mn = 0\n    now = 1\n    for i in range(0, n - 1):\n        if a[i] == a[i + 1]:\n            now += 1\n        else:\n            mn = max(mn, now)\n            now = 1\n    mn = max(mn, now)\n    print(max(min(number - 1, mn), min(number, mn - 1)))\n", "passed": true, "time": 0.14, "memory": 14096.0, "status": "done"}, {"code": "import sys\ninput = sys.stdin.readline\nfrom collections import Counter\n\nt=int(input())\nfor tests in range(t):\n    n=int(input())\n    C=Counter(list(map(int,input().split())))\n\n    LEN=len(C)\n    MAX=max(C.values())\n\n    if MAX<LEN:\n        print(MAX)\n    elif MAX==LEN:\n        print(MAX-1)\n    else:\n        print(LEN)\n        \n", "passed": true, "time": 0.14, "memory": 14192.0, "status": "done"}, {"code": "t = int(input())\nfor _ in range(t):\n    n = int(input())\n    skills = map(int, input().split())\n    d = {}\n    for s in skills:\n        if s in d:\n            d[s] += 1\n        else:\n            d[s] = 1\n\n    m = 0\n    for k in d.keys():\n        m = max(m, max(min(d[k], len(d) - 1), min(d[k] - 1, len(d))))\n    print(m)", "passed": true, "time": 0.14, "memory": 14112.0, "status": "done"}, {"code": "t = int(input(''))\nfor _ in range(t):\n    n = int(input(''))\n    a = list(map(int,input('').split(' ')))\n    d = {}\n    for i in range(n):\n        if(a[i] not in d):\n            d[a[i]] = 0\n        d[a[i]] = d[a[i]]+1\n    mx = 0\n    l = len(d)\n    for k in d:\n        if(min(d[k],l-1) > mx):\n            mx = min(d[k],l-1)\n        if(min(d[k]-1,l) > mx):\n            mx = min(d[k]-1,l)\n    print(mx)", "passed": true, "time": 0.14, "memory": 14248.0, "status": "done"}]