import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class pcteamcompose {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-->0){
            int n= sc.nextInt();
            int[] c = new int[n+1];
            Arrays.fill(c,0);
            HashSet<Integer> h = new HashSet<Integer>();
            int count =0;
            for(int i =0;i<n;i++){
                int temp = sc.nextInt();
                h.add(temp);
                c[temp]++;
                if(h.size()>count){
                    count=h.size();
                }
            }
            //System.out.println(count);
            Arrays.sort(c);
            if(c[n]>count) System.out.println(count);
            else if(c[n]==count) System.out.println(count-1);
            else System.out.println(c[n]);
            }
    }
}


import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class pcteamcompose {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-->0){
            int n= sc.nextInt();
            int[] c = new int[n+1];
            Arrays.fill(c,0);
            HashSet<Integer> h = new HashSet<Integer>();
            int count =0;
            for(int i =0;i<n;i++){
                int temp = sc.nextInt();
                h.add(temp);
                c[temp]++;
                if(h.size()>count){
                    count=h.size();
                }
            }
            //System.out.println(count);
            Arrays.sort(c);
            if(n==1) System.out.println("0");
            else if((n-count) == 0) System.out.println("1");
            else if(c[n]>=(n-count+1)) System.out.println((n-count+1) < (n/2) ? (n-count+1) : (n/2) );
            else System.out.println(c[n]<n/2 ? c[n] : (n/2));
        }
    }
}


/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here

		Scanner s=new Scanner(System.in);

		int t=s.nextInt();

		while(t>0)
		{
		    int n=s. nextInt();
		    HashMap<Integer,Integer> map=new HashMap<>();

		    int a[]=new int[n];
		    for(int i=0;i<n;i++)
		    {
		        a[i]=s.nextInt();
		        if(map.containsKey(a[i]))
		        {
		            map.put(a[i],map.get(a[i])+1);
		        }
		        else{
		            map.put(a[i],1);
		        }
		    }
		    int ans1=0,ans2=0,val=0;
		    for(int i=0;i<n;i++)
		    {
		       if(map.get(a[i])>ans1)
		       {
		           val=a[i];
		       ans1=map.get(a[i]);
		       }

		    }
		    if(map.containsKey(val))
		    map.remove(val);

		     for(int i=0;i<n;i++)
		    {
		        if(map.containsKey(a[i]))
		        {
		         if(map.get(a[i])<=ans1)
		         {
		           ans2++;
		           map.remove(a[i]);
		         }
		        }

		    }

		    if(ans1>=1&&ans2==1)
		    {
		        if(ans1==1)
		        System.out.println("1");
		        else
		        System.out.println("2");
		    }
		    else if(ans1>=1&&ans2==0)
		    {
		        System.out.println("0");
		    }
		    else if(ans1==0&&ans2!=0)
		    {
		        if(ans2==1)
		        System.out.println("1");
		        else
		        System.out.println("2");
		    }

		    else{
		        System.out.println(Math.min(ans1,ans2));
		    }

		    t--;
		}

	}
}


/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here

		Scanner s=new Scanner(System.in);

		int t=s.nextInt();

		while(t>0)
		{
		    int n=s. nextInt();
		    HashMap<Integer,Integer> map=new HashMap<>();

		    int a[]=new int[n];
		    for(int i=0;i<n;i++)
		    {
		        a[i]=s.nextInt();
		        if(map.containsKey(a[i]))
		        {
		            map.put(a[i],map.get(a[i])+1);
		        }
		        else{
		            map.put(a[i],1);
		        }
		    }
		    int ans1=0,ans2=0,val=0;
		    for(int i=0;i<n;i++)
		    {
		       if(map.get(a[i])>ans1)
		       {
		           val=a[i];
		       ans1=map.get(a[i]);
		       }

		    }
		    if(map.containsKey(val))
		    map.remove(val);

		     for(int i=0;i<n;i++)
		    {
		        if(map.containsKey(a[i]))
		        {
		         if(map.get(a[i])<=ans1)
		         {
		           ans2++;
		           map.remove(a[i]);
		         }
		        }

		    }

		    if(ans1>=1&&ans2==1)
		    {
		        if(ans1==1)
		        System.out.println("1");
		        else
		        System.out.println("2");
		    }
		    else if(ans1>=1&&ans2==0)
		    {
		        System.out.println("0");
		    }
		    else if(ans1==0&&ans2!=0)
		    {
		        if(ans2==1)
		        System.out.println("1");
		        else
		        System.out.println("2");
		    }

		    else{
		        System.out.println(Math.max(Math.min(ans1,ans2),Math.min(ans1-1,ans2+1)));
		    }

		    t--;
		}

	}
}


/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here

		Scanner s=new Scanner(System.in);

		int t=s.nextInt();

		while(t>0)
		{
		    int n=s. nextInt();
		    HashMap<Integer,Integer> map=new HashMap<>();

		    int a[]=new int[n];
		    for(int i=0;i<n;i++)
		    {
		        a[i]=s.nextInt();
		        if(map.containsKey(a[i]))
		        {
		            map.put(a[i],map.get(a[i])+1);
		        }
		        else{
		            map.put(a[i],1);
		        }
		    }
		    int ans1=0,ans2=0,val=0;
		    for(int i=0;i<n;i++)
		    {
		       if(map.get(a[i])>ans1)
		       {
		           val=a[i];
		       ans1=map.get(a[i]);
		       }

		    }
		    ans2=map.size();

		        System.out.println(Math.max(Math.min(ans1-1,ans2),Math.min(ans1,ans2-1)));

		    t--;
		}

	}
}


/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here

		Scanner s=new Scanner(System.in);

		int t=s.nextInt();

		while(t>0)
		{
		    int n=s. nextInt();
		    HashMap<Integer,Integer> map=new HashMap<>();

		    int a[]=new int[n];
		    for(int i=0;i<n;i++)
		    {
		        a[i]=s.nextInt();
		        if(map.containsKey(a[i]))
		        {
		            map.put(a[i],map.get(a[i])+1);
		        }
		        else{
		            map.put(a[i],1);
		        }
		    }
		    int ans1=0,ans2=0,val=0;
		    for(int i=0;i<n;i++)
		    {
		       if(map.get(a[i])>ans1)
		       {
		           val=a[i];
		       ans1=map.get(a[i]);
		       }

		    }
		    if(map.containsKey(val))
		    map.remove(val);

		     for(int i=0;i<n;i++)
		    {
		        if(map.containsKey(a[i]))
		        {
		         if(map.get(a[i])<=ans1)
		         {
		           ans2++;
		           map.remove(a[i]);
		         }
		        }

		    }
		     if(ans1>=1&&ans2==0)
		    {
		        System.out.println("0");
		        t--;
		        continue;
		    }
		    if(ans1>ans2)
		    {
		        ans1--;
		        ans2++;
		    }

		    else{
		        System.out.println(Math.min(ans1,ans2));
		    }

		    t--;
		}

	}
}


/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here

		Scanner s=new Scanner(System.in);

		int t=s.nextInt();

		while(t>0)
		{
		    int n=s. nextInt();
		    HashMap<Integer,Integer> map=new HashMap<>();

		    int a[]=new int[n];
		    for(int i=0;i<n;i++)
		    {
		        a[i]=s.nextInt();
		        if(map.containsKey(a[i]))
		        {
		            map.put(a[i],map.get(a[i])+1);
		        }
		        else{
		            map.put(a[i],1);
		        }
		    }
		    int ans1=0,ans2=0,val=0;
		    for(int i=0;i<n;i++)
		    {
		       if(map.get(a[i])>ans1)
		       {
		           val=a[i];
		       ans1=map.get(a[i]);
		       }

		    }
		    if(map.containsKey(val))
		    map.remove(val);

		     for(int i=0;i<n;i++)
		    {
		        if(map.containsKey(a[i]))
		        {
		         if(map.get(a[i])<=ans1)
		         {
		           ans2++;
		           map.remove(a[i]);
		         }
		        }

		    }
		     if(ans1>=1&&ans2==0)
		    {
		        System.out.println("0");
		        t--;
		        continue;
		    }
		    if(ans1>ans2)
		    {
		        ans1--;
		        ans2++;
		    }

		        System.out.println(Math.min(ans1,ans2));

		    t--;
		}

	}
}


/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here

		Scanner s=new Scanner(System.in);

		int t=s.nextInt();

		while(t>0)
		{
		    int n=s. nextInt();
		    HashMap<Integer,Integer> map=new HashMap<>();

		    int a[]=new int[n];
		    for(int i=0;i<n;i++)
		    {
		        a[i]=s.nextInt();
		        if(map.containsKey(a[i]))
		        {
		            map.put(a[i],map.get(a[i])+1);
		        }
		        else{
		            map.put(a[i],1);
		        }
		    }
		    int ans1=0,ans2=0,val=0;
		    for(int i=0;i<n;i++)
		    {
		       if(map.get(a[i])>ans1)
		       {
		           val=a[i];
		       ans1=map.get(a[i]);
		       }

		    }
		    if(map.containsKey(val))
		    map.remove(val);

		     for(int i=0;i<n;i++)
		    {
		        if(map.containsKey(a[i]))
		        {
		         if(map.get(a[i])<=ans1)
		         {
		           ans2++;
		           map.remove(a[i]);
		         }
		        }

		    }
		     if(ans1>=1&&ans2==0)
		    {
		        System.out.println("0");
		        t--;
		        continue;
		    }
		    if(ans1>ans2)
		    {
		        ans1--;
		        ans2++;
		    }

		    if(ans1>=1&&ans2==1)
		    {
		        if(ans1==1)
		        System.out.println("1");
		        else
		        System.out.println("2");
		    }

		    else{
		        System.out.println(Math.min(ans1,ans2));
		    }

		    t--;
		}

	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.InputMismatchException;
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
    public static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }

    static long gcd(long a, long b){
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }
    static long lcm(long a, long b)  {
        return (a*b)/gcd(a, b);
    }
    public static void sortbyColumn(int arr[][], int col)
    {

        Arrays.sort(arr, new Comparator<int[]>() {

          @Override

          public int compare(final int[] entry1,
                             final int[] entry2) {

            if (entry1[col] > entry2[col])
                return 1;
            else
                return -1;
          }
        });
    }
    static long func(long a[],long size,int s){
        long max1=a[s];
        long maxc=a[s];
        for(int i=s+1;i<size;i++){
            maxc=Math.max(a[i],maxc+a[i]);
            max1=Math.max(maxc,max1);
        }
        return max1;
    }
    public static class Pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<Pair<U, V>> {
        public U x;
        public V y;

        public Pair(U x, V y) {
            this.x = x;
            this.y = y;
        }

        public int hashCode() {
            return (x == null ? 0 : x.hashCode() * 31) + (y == null ? 0 : y.hashCode());
        }

        public boolean equals(Object o) {
            if (this == o)
                return true;
            if (o == null || getClass() != o.getClass())
                return false;
            Pair<U, V> p = (Pair<U, V>) o;
            return (x == null ? p.x == null : x.equals(p.x)) && (y == null ? p.y == null : y.equals(p.y));
        }

        public int compareTo(Pair<U, V> b) {
            int cmpU = x.compareTo(b.x);
            return cmpU != 0 ? cmpU : y.compareTo(b.y);
        }

        public String toString() {
            return String.format("(%s, %s)", x.toString(), y.toString());
        }

    }
    static LinkedList<Integer> li[]=new LinkedList[100001];
    static int ans1=0,ans2=0,max1=-1;
    static int dist[]=new int[100001];
    static int visited[]=new int[100001];
    //static int arr[];
    static ArrayList<Integer> adj[]=new ArrayList[100001];
    static void bfs(int n,int m){
        //visited[x]=1;
        //visit[j]++;
        dist[n]=0;
        visited[n]=1;
        Queue<Integer> q=new LinkedList<>();
        q.add(n);
        while(!q.isEmpty()){
            int x=q.poll();
            for(int i=0;i<adj[x].size();i++){
                if(visited[adj[x].get(i)]==0){
                    q.add(adj[x].get(i));
                    visited[adj[x].get(i)]=1;
                    dist[adj[x].get(i)]=dist[x]+1;
                }
                if(adj[x].get(i)==m)
                {
                    return;
                }
            }
        }
        // for(int i=0;i<adj[x].size();i++){
        //     if(visited[adj[x].get(i)]==0){
        //         //check[j]++;
        //         ans1++;
        //         dfs(adj[x].get(i));
        //     }
        // }
    }
    // static void dfs(int x){
    //     visit[x]=1;
    //     ans1++;
    //     for(int i=0;i<li[x].size();i++){
    //         if(visit[li[x].get(i)]==0){
    //             dfs(li[x].get(i));
    //         }
    //     }
    // }
    public static void main(String args[]){
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter w = new PrintWriter(outputStream);
        int t=in.nextInt();
        int i,j,k,l;
        for(i=0;i<t;i++){
            int n=in.nextInt(),flag=0;
            int arr[]=new int[n];
            int freq[]=new int[n+1];
            int freo=0;
            for(j=0;j<n;j++){
                arr[j]=in.nextInt();
                freq[arr[j]]++;
            }
            Arrays.sort(freq);

            int max=freq[n];
            for(j=0;j<n;j++){
                if(freq[j]==1){
                    freo++;
                }else if(freq[j]>1&&freq[j]!=max){
                    freo++;
                }
            }
            int ans=0;
            if(max>n/2){
                max--;
                freo++;
                ans=Math.min(n/2,freo);
            }else{
                ans=Math.min(max,freo);
            }
            w.println(ans);

        }
        w.close();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.InputMismatchException;
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
    public static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }

    static long gcd(long a, long b){
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }
    static long lcm(long a, long b)  {
        return (a*b)/gcd(a, b);
    }
    public static void sortbyColumn(int arr[][], int col)
    {

        Arrays.sort(arr, new Comparator<int[]>() {

          @Override

          public int compare(final int[] entry1,
                             final int[] entry2) {

            if (entry1[col] > entry2[col])
                return 1;
            else
                return -1;
          }
        });
    }
    static long func(long a[],long size,int s){
        long max1=a[s];
        long maxc=a[s];
        for(int i=s+1;i<size;i++){
            maxc=Math.max(a[i],maxc+a[i]);
            max1=Math.max(maxc,max1);
        }
        return max1;
    }
    public static class Pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<Pair<U, V>> {
        public U x;
        public V y;

        public Pair(U x, V y) {
            this.x = x;
            this.y = y;
        }

        public int hashCode() {
            return (x == null ? 0 : x.hashCode() * 31) + (y == null ? 0 : y.hashCode());
        }

        public boolean equals(Object o) {
            if (this == o)
                return true;
            if (o == null || getClass() != o.getClass())
                return false;
            Pair<U, V> p = (Pair<U, V>) o;
            return (x == null ? p.x == null : x.equals(p.x)) && (y == null ? p.y == null : y.equals(p.y));
        }

        public int compareTo(Pair<U, V> b) {
            int cmpU = x.compareTo(b.x);
            return cmpU != 0 ? cmpU : y.compareTo(b.y);
        }

        public String toString() {
            return String.format("(%s, %s)", x.toString(), y.toString());
        }

    }
    static LinkedList<Integer> li[]=new LinkedList[100001];
    static int ans1=0,ans2=0,max1=-1;
    static int dist[]=new int[100001];
    static int visited[]=new int[100001];
    //static int arr[];
    static ArrayList<Integer> adj[]=new ArrayList[100001];
    static void bfs(int n,int m){
        //visited[x]=1;
        //visit[j]++;
        dist[n]=0;
        visited[n]=1;
        Queue<Integer> q=new LinkedList<>();
        q.add(n);
        while(!q.isEmpty()){
            int x=q.poll();
            for(int i=0;i<adj[x].size();i++){
                if(visited[adj[x].get(i)]==0){
                    q.add(adj[x].get(i));
                    visited[adj[x].get(i)]=1;
                    dist[adj[x].get(i)]=dist[x]+1;
                }
                if(adj[x].get(i)==m)
                {
                    return;
                }
            }
        }
        // for(int i=0;i<adj[x].size();i++){
        //     if(visited[adj[x].get(i)]==0){
        //         //check[j]++;
        //         ans1++;
        //         dfs(adj[x].get(i));
        //     }
        // }
    }
    // static void dfs(int x){
    //     visit[x]=1;
    //     ans1++;
    //     for(int i=0;i<li[x].size();i++){
    //         if(visit[li[x].get(i)]==0){
    //             dfs(li[x].get(i));
    //         }
    //     }
    // }
    public static void main(String args[]){
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter w = new PrintWriter(outputStream);
        int t=in.nextInt();
        int i,j,k,l;
        for(i=0;i<t;i++){
            int n=in.nextInt(),flag=0;
            int arr[]=new int[n];
            int freq[]=new int[n+1];
            int freo=0;
            for(j=0;j<n;j++){
                arr[j]=in.nextInt();
                freq[arr[j]]++;
            }
            Arrays.sort(freq);

            int max=freq[n];
            for(j=0;j<n+1;j++){
                if(freq[j]>=1){
                    freo++;
                }
            }
            int ans=0;
            if(max>n/2){
                max--;
                freo++;
                ans=Math.min(n/2,freo);
            }else{
                ans=Math.min(max,freo-1);
            }
            w.println(ans);

        }
        w.close();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.InputMismatchException;
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
    public static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }

    static long gcd(long a, long b){
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }
    static long lcm(long a, long b)  {
        return (a*b)/gcd(a, b);
    }
    public static void sortbyColumn(int arr[][], int col)
    {

        Arrays.sort(arr, new Comparator<int[]>() {

          @Override

          public int compare(final int[] entry1,
                             final int[] entry2) {

            if (entry1[col] > entry2[col])
                return 1;
            else
                return -1;
          }
        });
    }
    static long func(long a[],long size,int s){
        long max1=a[s];
        long maxc=a[s];
        for(int i=s+1;i<size;i++){
            maxc=Math.max(a[i],maxc+a[i]);
            max1=Math.max(maxc,max1);
        }
        return max1;
    }
    public static class Pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<Pair<U, V>> {
        public U x;
        public V y;

        public Pair(U x, V y) {
            this.x = x;
            this.y = y;
        }

        public int hashCode() {
            return (x == null ? 0 : x.hashCode() * 31) + (y == null ? 0 : y.hashCode());
        }

        public boolean equals(Object o) {
            if (this == o)
                return true;
            if (o == null || getClass() != o.getClass())
                return false;
            Pair<U, V> p = (Pair<U, V>) o;
            return (x == null ? p.x == null : x.equals(p.x)) && (y == null ? p.y == null : y.equals(p.y));
        }

        public int compareTo(Pair<U, V> b) {
            int cmpU = x.compareTo(b.x);
            return cmpU != 0 ? cmpU : y.compareTo(b.y);
        }

        public String toString() {
            return String.format("(%s, %s)", x.toString(), y.toString());
        }

    }
    static LinkedList<Integer> li[]=new LinkedList[100001];
    static int ans1=0,ans2=0,max1=-1;
    static int dist[]=new int[100001];
    static int visited[]=new int[100001];
    //static int arr[];
    static ArrayList<Integer> adj[]=new ArrayList[100001];
    static void bfs(int n,int m){
        //visited[x]=1;
        //visit[j]++;
        dist[n]=0;
        visited[n]=1;
        Queue<Integer> q=new LinkedList<>();
        q.add(n);
        while(!q.isEmpty()){
            int x=q.poll();
            for(int i=0;i<adj[x].size();i++){
                if(visited[adj[x].get(i)]==0){
                    q.add(adj[x].get(i));
                    visited[adj[x].get(i)]=1;
                    dist[adj[x].get(i)]=dist[x]+1;
                }
                if(adj[x].get(i)==m)
                {
                    return;
                }
            }
        }
        // for(int i=0;i<adj[x].size();i++){
        //     if(visited[adj[x].get(i)]==0){
        //         //check[j]++;
        //         ans1++;
        //         dfs(adj[x].get(i));
        //     }
        // }
    }
    // static void dfs(int x){
    //     visit[x]=1;
    //     ans1++;
    //     for(int i=0;i<li[x].size();i++){
    //         if(visit[li[x].get(i)]==0){
    //             dfs(li[x].get(i));
    //         }
    //     }
    // }
    public static void main(String args[]){
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter w = new PrintWriter(outputStream);
        int t=in.nextInt();
        int i,j,k,l;
        for(i=0;i<t;i++){
            int n=in.nextInt(),flag=0;
            int arr[]=new int[n];
            int freq[]=new int[n+1];
            int freo=0;
            for(j=0;j<n;j++){
                arr[j]=in.nextInt();
                freq[arr[j]]++;
            }
            Arrays.sort(freq);

            int max=freq[n];
            for(j=0;j<n+1;j++){
                if(freq[j]==1){
                    freo++;
                }else if(freq[j]>1&&j!=n){
                    freo++;
                }
            }
            int ans=0;
            if(max>n/2){
                max--;
                freo++;
                ans=Math.min(n/2,freo);
            }
            else if(max==n/2){
                ans=Math.max(Math.min(max-1,freo+1),Math.min(max,freo));
            }
            else{
                ans=Math.min(max,freo);
            }
            w.println(ans);

        }
        w.close();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.InputMismatchException;
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
    public static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }

    static long gcd(long a, long b){
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }
    static long lcm(long a, long b)  {
        return (a*b)/gcd(a, b);
    }
    public static void sortbyColumn(int arr[][], int col)
    {

        Arrays.sort(arr, new Comparator<int[]>() {

          @Override

          public int compare(final int[] entry1,
                             final int[] entry2) {

            if (entry1[col] > entry2[col])
                return 1;
            else
                return -1;
          }
        });
    }
    static long func(long a[],long size,int s){
        long max1=a[s];
        long maxc=a[s];
        for(int i=s+1;i<size;i++){
            maxc=Math.max(a[i],maxc+a[i]);
            max1=Math.max(maxc,max1);
        }
        return max1;
    }
    public static class Pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<Pair<U, V>> {
        public U x;
        public V y;

        public Pair(U x, V y) {
            this.x = x;
            this.y = y;
        }

        public int hashCode() {
            return (x == null ? 0 : x.hashCode() * 31) + (y == null ? 0 : y.hashCode());
        }

        public boolean equals(Object o) {
            if (this == o)
                return true;
            if (o == null || getClass() != o.getClass())
                return false;
            Pair<U, V> p = (Pair<U, V>) o;
            return (x == null ? p.x == null : x.equals(p.x)) && (y == null ? p.y == null : y.equals(p.y));
        }

        public int compareTo(Pair<U, V> b) {
            int cmpU = x.compareTo(b.x);
            return cmpU != 0 ? cmpU : y.compareTo(b.y);
        }

        public String toString() {
            return String.format("(%s, %s)", x.toString(), y.toString());
        }

    }
    static LinkedList<Integer> li[]=new LinkedList[100001];
    static int ans1=0,ans2=0,max1=-1;
    static int dist[]=new int[100001];
    static int visited[]=new int[100001];
    //static int arr[];
    static ArrayList<Integer> adj[]=new ArrayList[100001];
    static void bfs(int n,int m){
        //visited[x]=1;
        //visit[j]++;
        dist[n]=0;
        visited[n]=1;
        Queue<Integer> q=new LinkedList<>();
        q.add(n);
        while(!q.isEmpty()){
            int x=q.poll();
            for(int i=0;i<adj[x].size();i++){
                if(visited[adj[x].get(i)]==0){
                    q.add(adj[x].get(i));
                    visited[adj[x].get(i)]=1;
                    dist[adj[x].get(i)]=dist[x]+1;
                }
                if(adj[x].get(i)==m)
                {
                    return;
                }
            }
        }
        // for(int i=0;i<adj[x].size();i++){
        //     if(visited[adj[x].get(i)]==0){
        //         //check[j]++;
        //         ans1++;
        //         dfs(adj[x].get(i));
        //     }
        // }
    }
    // static void dfs(int x){
    //     visit[x]=1;
    //     ans1++;
    //     for(int i=0;i<li[x].size();i++){
    //         if(visit[li[x].get(i)]==0){
    //             dfs(li[x].get(i));
    //         }
    //     }
    // }
    public static void main(String args[]){
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter w = new PrintWriter(outputStream);
        int t=in.nextInt();
        int i,j,k,l;
        for(i=0;i<t;i++){
            int n=in.nextInt(),flag=0;
            int arr[]=new int[n];
            int freq[]=new int[n+1];
            int freo=0;
            for(j=0;j<n;j++){
                arr[j]=in.nextInt();
                freq[arr[j]]++;
            }
            Arrays.sort(freq);
            if(n<2){
                w.println(0);
                continue;
            }
            int max=freq[n];
            for(j=0;j<n+1;j++){
                if(freq[j]==1){
                    freo++;
                }else if(freq[j]>1&&j!=n){
                    freo++;
                }
            }
            int ans=0;
            if(max<=freo){
                ans=max;
            }else{
                if(max>=(freo+2)){
                    freo++;
                }
                ans=freo;
            }
            w.println(ans);
        }
        w.close();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.InputMismatchException;
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
    public static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }

    static long gcd(long a, long b){
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }
    static long lcm(long a, long b)  {
        return (a*b)/gcd(a, b);
    }
    public static void sortbyColumn(int arr[][], int col)
    {

        Arrays.sort(arr, new Comparator<int[]>() {

          @Override

          public int compare(final int[] entry1,
                             final int[] entry2) {

            if (entry1[col] > entry2[col])
                return 1;
            else
                return -1;
          }
        });
    }
    static long func(long a[],long size,int s){
        long max1=a[s];
        long maxc=a[s];
        for(int i=s+1;i<size;i++){
            maxc=Math.max(a[i],maxc+a[i]);
            max1=Math.max(maxc,max1);
        }
        return max1;
    }
    public static class Pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<Pair<U, V>> {
        public U x;
        public V y;

        public Pair(U x, V y) {
            this.x = x;
            this.y = y;
        }

        public int hashCode() {
            return (x == null ? 0 : x.hashCode() * 31) + (y == null ? 0 : y.hashCode());
        }

        public boolean equals(Object o) {
            if (this == o)
                return true;
            if (o == null || getClass() != o.getClass())
                return false;
            Pair<U, V> p = (Pair<U, V>) o;
            return (x == null ? p.x == null : x.equals(p.x)) && (y == null ? p.y == null : y.equals(p.y));
        }

        public int compareTo(Pair<U, V> b) {
            int cmpU = x.compareTo(b.x);
            return cmpU != 0 ? cmpU : y.compareTo(b.y);
        }

        public String toString() {
            return String.format("(%s, %s)", x.toString(), y.toString());
        }

    }
    static LinkedList<Integer> li[]=new LinkedList[100001];
    static int ans1=0,ans2=0,max1=-1;
    static int dist[]=new int[100001];
    static int visited[]=new int[100001];
    //static int arr[];
    static ArrayList<Integer> adj[]=new ArrayList[100001];
    static void bfs(int n,int m){
        //visited[x]=1;
        //visit[j]++;
        dist[n]=0;
        visited[n]=1;
        Queue<Integer> q=new LinkedList<>();
        q.add(n);
        while(!q.isEmpty()){
            int x=q.poll();
            for(int i=0;i<adj[x].size();i++){
                if(visited[adj[x].get(i)]==0){
                    q.add(adj[x].get(i));
                    visited[adj[x].get(i)]=1;
                    dist[adj[x].get(i)]=dist[x]+1;
                }
                if(adj[x].get(i)==m)
                {
                    return;
                }
            }
        }
        // for(int i=0;i<adj[x].size();i++){
        //     if(visited[adj[x].get(i)]==0){
        //         //check[j]++;
        //         ans1++;
        //         dfs(adj[x].get(i));
        //     }
        // }
    }
    // static void dfs(int x){
    //     visit[x]=1;
    //     ans1++;
    //     for(int i=0;i<li[x].size();i++){
    //         if(visit[li[x].get(i)]==0){
    //             dfs(li[x].get(i));
    //         }
    //     }
    // }
    public static void main(String args[]){
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter w = new PrintWriter(outputStream);
        int t=in.nextInt();
        int i,j,k,l;
        for(i=0;i<t;i++){
            int n=in.nextInt(),flag=0;
            int arr[]=new int[n];
            int freq[]=new int[n+1];
            int freo=0;
            for(j=0;j<n;j++){
                arr[j]=in.nextInt();
                freq[arr[j]]++;
            }
            Arrays.sort(freq);

            int max=freq[n];
            for(j=0;j<n+1;j++){
                if(freq[j]==1){
                    freo++;
                }else if(freq[j]>1&&j!=n){
                    freo++;
                }
            }
            int ans=0;
            if(max>=n/2){
                max--;
                freo++;
                ans=Math.min(max,freo);
            }else{
                ans=Math.min(max,freo);
            }
            w.println(ans);

        }
        w.close();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.InputMismatchException;
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
    public static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }

    static long gcd(long a, long b){
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }
    static long lcm(long a, long b)  {
        return (a*b)/gcd(a, b);
    }
    public static void sortbyColumn(int arr[][], int col)
    {

        Arrays.sort(arr, new Comparator<int[]>() {

          @Override

          public int compare(final int[] entry1,
                             final int[] entry2) {

            if (entry1[col] > entry2[col])
                return 1;
            else
                return -1;
          }
        });
    }
    static long func(long a[],long size,int s){
        long max1=a[s];
        long maxc=a[s];
        for(int i=s+1;i<size;i++){
            maxc=Math.max(a[i],maxc+a[i]);
            max1=Math.max(maxc,max1);
        }
        return max1;
    }
    public static class Pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<Pair<U, V>> {
        public U x;
        public V y;

        public Pair(U x, V y) {
            this.x = x;
            this.y = y;
        }

        public int hashCode() {
            return (x == null ? 0 : x.hashCode() * 31) + (y == null ? 0 : y.hashCode());
        }

        public boolean equals(Object o) {
            if (this == o)
                return true;
            if (o == null || getClass() != o.getClass())
                return false;
            Pair<U, V> p = (Pair<U, V>) o;
            return (x == null ? p.x == null : x.equals(p.x)) && (y == null ? p.y == null : y.equals(p.y));
        }

        public int compareTo(Pair<U, V> b) {
            int cmpU = x.compareTo(b.x);
            return cmpU != 0 ? cmpU : y.compareTo(b.y);
        }

        public String toString() {
            return String.format("(%s, %s)", x.toString(), y.toString());
        }

    }
    static LinkedList<Integer> li[]=new LinkedList[100001];
    static int ans1=0,ans2=0,max1=-1;
    static int dist[]=new int[100001];
    static int visited[]=new int[100001];
    //static int arr[];
    static ArrayList<Integer> adj[]=new ArrayList[100001];
    static void bfs(int n,int m){
        //visited[x]=1;
        //visit[j]++;
        dist[n]=0;
        visited[n]=1;
        Queue<Integer> q=new LinkedList<>();
        q.add(n);
        while(!q.isEmpty()){
            int x=q.poll();
            for(int i=0;i<adj[x].size();i++){
                if(visited[adj[x].get(i)]==0){
                    q.add(adj[x].get(i));
                    visited[adj[x].get(i)]=1;
                    dist[adj[x].get(i)]=dist[x]+1;
                }
                if(adj[x].get(i)==m)
                {
                    return;
                }
            }
        }
        // for(int i=0;i<adj[x].size();i++){
        //     if(visited[adj[x].get(i)]==0){
        //         //check[j]++;
        //         ans1++;
        //         dfs(adj[x].get(i));
        //     }
        // }
    }
    // static void dfs(int x){
    //     visit[x]=1;
    //     ans1++;
    //     for(int i=0;i<li[x].size();i++){
    //         if(visit[li[x].get(i)]==0){
    //             dfs(li[x].get(i));
    //         }
    //     }
    // }
    public static void main(String args[]){
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter w = new PrintWriter(outputStream);
        int t=in.nextInt();
        int i,j,k,l;
        for(i=0;i<t;i++){
            int n=in.nextInt(),flag=0;
            int arr[]=new int[n];
            int freq[]=new int[n+1];
            int freo=0;
            for(j=0;j<n;j++){
                arr[j]=in.nextInt();
                freq[arr[j]]++;
            }
            Arrays.sort(freq);

            int max=freq[n];
            for(j=0;j<n+1;j++){
                if(freq[j]>=1){
                    freo++;
                }
            }
            int ans=0;
            if(max>n/2){
                max--;
                freo++;
                ans=Math.min(n/2,freo);
            }else{
                ans=Math.min(max,freo);
            }
            w.println(ans);

        }
        w.close();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.InputMismatchException;
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
    public static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }

    static long gcd(long a, long b){
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }
    static long lcm(long a, long b)  {
        return (a*b)/gcd(a, b);
    }
    public static void sortbyColumn(int arr[][], int col)
    {

        Arrays.sort(arr, new Comparator<int[]>() {

          @Override

          public int compare(final int[] entry1,
                             final int[] entry2) {

            if (entry1[col] > entry2[col])
                return 1;
            else
                return -1;
          }
        });
    }
    static long func(long a[],long size,int s){
        long max1=a[s];
        long maxc=a[s];
        for(int i=s+1;i<size;i++){
            maxc=Math.max(a[i],maxc+a[i]);
            max1=Math.max(maxc,max1);
        }
        return max1;
    }
    public static class Pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<Pair<U, V>> {
        public U x;
        public V y;

        public Pair(U x, V y) {
            this.x = x;
            this.y = y;
        }

        public int hashCode() {
            return (x == null ? 0 : x.hashCode() * 31) + (y == null ? 0 : y.hashCode());
        }

        public boolean equals(Object o) {
            if (this == o)
                return true;
            if (o == null || getClass() != o.getClass())
                return false;
            Pair<U, V> p = (Pair<U, V>) o;
            return (x == null ? p.x == null : x.equals(p.x)) && (y == null ? p.y == null : y.equals(p.y));
        }

        public int compareTo(Pair<U, V> b) {
            int cmpU = x.compareTo(b.x);
            return cmpU != 0 ? cmpU : y.compareTo(b.y);
        }

        public String toString() {
            return String.format("(%s, %s)", x.toString(), y.toString());
        }

    }
    static LinkedList<Integer> li[]=new LinkedList[100001];
    static int ans1=0,ans2=0,max1=-1;
    static int dist[]=new int[100001];
    static int visited[]=new int[100001];
    //static int arr[];
    static ArrayList<Integer> adj[]=new ArrayList[100001];
    static void bfs(int n,int m){
        //visited[x]=1;
        //visit[j]++;
        dist[n]=0;
        visited[n]=1;
        Queue<Integer> q=new LinkedList<>();
        q.add(n);
        while(!q.isEmpty()){
            int x=q.poll();
            for(int i=0;i<adj[x].size();i++){
                if(visited[adj[x].get(i)]==0){
                    q.add(adj[x].get(i));
                    visited[adj[x].get(i)]=1;
                    dist[adj[x].get(i)]=dist[x]+1;
                }
                if(adj[x].get(i)==m)
                {
                    return;
                }
            }
        }
        // for(int i=0;i<adj[x].size();i++){
        //     if(visited[adj[x].get(i)]==0){
        //         //check[j]++;
        //         ans1++;
        //         dfs(adj[x].get(i));
        //     }
        // }
    }
    // static void dfs(int x){
    //     visit[x]=1;
    //     ans1++;
    //     for(int i=0;i<li[x].size();i++){
    //         if(visit[li[x].get(i)]==0){
    //             dfs(li[x].get(i));
    //         }
    //     }
    // }
    public static void main(String args[]){
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter w = new PrintWriter(outputStream);
        int t=in.nextInt();
        int i,j,k,l;
        for(i=0;i<t;i++){
            int n=in.nextInt(),flag=0;
            int arr[]=new int[n];
            int freq[]=new int[n+1];
            int freo=0;
            for(j=0;j<n;j++){
                arr[j]=in.nextInt();
                freq[arr[j]]++;
            }
            Arrays.sort(freq);

            int max=freq[n];
            for(j=0;j<n+1;j++){
                if(freq[j]==1){
                    freo++;
                }else if(freq[j]>1&&j!=n){
                    freo++;
                }
            }
            int ans=0;
            if(max>=n/2){
                max--;
                freo++;
                ans=Math.min(n/2-1,freo);
            }else{
                ans=Math.min(max,freo);
            }
            w.println(ans);

        }
        w.close();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.InputMismatchException;
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
    public static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }

    static long gcd(long a, long b){
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }
    static long lcm(long a, long b)  {
        return (a*b)/gcd(a, b);
    }
    public static void sortbyColumn(int arr[][], int col)
    {

        Arrays.sort(arr, new Comparator<int[]>() {

          @Override

          public int compare(final int[] entry1,
                             final int[] entry2) {

            if (entry1[col] > entry2[col])
                return 1;
            else
                return -1;
          }
        });
    }
    static long func(long a[],long size,int s){
        long max1=a[s];
        long maxc=a[s];
        for(int i=s+1;i<size;i++){
            maxc=Math.max(a[i],maxc+a[i]);
            max1=Math.max(maxc,max1);
        }
        return max1;
    }
    public static class Pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<Pair<U, V>> {
        public U x;
        public V y;

        public Pair(U x, V y) {
            this.x = x;
            this.y = y;
        }

        public int hashCode() {
            return (x == null ? 0 : x.hashCode() * 31) + (y == null ? 0 : y.hashCode());
        }

        public boolean equals(Object o) {
            if (this == o)
                return true;
            if (o == null || getClass() != o.getClass())
                return false;
            Pair<U, V> p = (Pair<U, V>) o;
            return (x == null ? p.x == null : x.equals(p.x)) && (y == null ? p.y == null : y.equals(p.y));
        }

        public int compareTo(Pair<U, V> b) {
            int cmpU = x.compareTo(b.x);
            return cmpU != 0 ? cmpU : y.compareTo(b.y);
        }

        public String toString() {
            return String.format("(%s, %s)", x.toString(), y.toString());
        }

    }
    static LinkedList<Integer> li[]=new LinkedList[100001];
    static int ans1=0,ans2=0,max1=-1;
    static int dist[]=new int[100001];
    static int visited[]=new int[100001];
    //static int arr[];
    static ArrayList<Integer> adj[]=new ArrayList[100001];
    static void bfs(int n,int m){
        //visited[x]=1;
        //visit[j]++;
        dist[n]=0;
        visited[n]=1;
        Queue<Integer> q=new LinkedList<>();
        q.add(n);
        while(!q.isEmpty()){
            int x=q.poll();
            for(int i=0;i<adj[x].size();i++){
                if(visited[adj[x].get(i)]==0){
                    q.add(adj[x].get(i));
                    visited[adj[x].get(i)]=1;
                    dist[adj[x].get(i)]=dist[x]+1;
                }
                if(adj[x].get(i)==m)
                {
                    return;
                }
            }
        }
        // for(int i=0;i<adj[x].size();i++){
        //     if(visited[adj[x].get(i)]==0){
        //         //check[j]++;
        //         ans1++;
        //         dfs(adj[x].get(i));
        //     }
        // }
    }
    // static void dfs(int x){
    //     visit[x]=1;
    //     ans1++;
    //     for(int i=0;i<li[x].size();i++){
    //         if(visit[li[x].get(i)]==0){
    //             dfs(li[x].get(i));
    //         }
    //     }
    // }
    public static void main(String args[]){
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter w = new PrintWriter(outputStream);
        int t=in.nextInt();
        int i,j,k,l;
        for(i=0;i<t;i++){
            int n=in.nextInt(),flag=0;
            int arr[]=new int[n];
            int freq[]=new int[n+1];
            int freo=0;
            for(j=0;j<n;j++){
                arr[j]=in.nextInt();
                freq[arr[j]]++;
            }
            Arrays.sort(freq);

            int max=freq[n];
            for(j=0;j<n+1;j++){
                if(freq[j]==1){
                    freo++;
                }else if(freq[j]>1&&j!=n){
                    freo++;
                }
            }
            int ans=0;
            if(max>n/2){
                max--;
                freo++;
                ans=Math.min(n/2,freo);
            }else{
                ans=Math.min(max,freo);
            }
            w.println(ans);

        }
        w.close();
    }

}


package codeForces;

import java.util.HashMap;
import java.util.Scanner;

public class TwoTeamsComposing {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s = new Scanner(System.in);
		int t = s.nextInt();

		while(t != 0) {
			t--;

			int[] arr = new int[s.nextInt()];
			if(arr.length == 0) {
				System.out.println(0);
				continue;
			}
			HashMap<Integer, Integer> map = new HashMap<>();

			for(int i=0; i<arr.length; i++) {
				arr[i] = s.nextInt();
				if(map.containsKey(arr[i])) {
					map.put(arr[i], 1+map.get(arr[i]));
				}
				else	map.put(arr[i], 1);
			}

			int count1 = 0;
			int count2 = 0;

			for(int key : map.keySet()) {
				count1++;
				count2 = Math.max(count2, map.get(key));
			}

			if(count1 == count2)	System.out.println(count1-1);

			else	System.out.println(Math.min(count1, count2));
		}
	}

}


package codeForces;

import java.util.HashMap;
import java.util.Scanner;

public class TwoTeamsComposing {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s = new Scanner(System.in);
		int t = s.nextInt();
		int[] output = new int[t];
		int j=0;
		while(t != 0) {
			t--;

			int[] arr = new int[s.nextInt()];
			if(arr.length == 0) {
				output[j] = 0;
				continue;
			}
			HashMap<Integer, Integer> map = new HashMap<>();

			for(int i=0; i<arr.length; i++) {
				arr[i] = s.nextInt();
				if(map.containsKey(arr[i])) {
					map.put(arr[i], 1+map.get(arr[i]));
				}
				else	map.put(arr[i], 1);
			}

			int count1 = 0;
			int count2 = 0;

			for(int key : map.keySet()) {
				count1++;
				count2 = Math.max(count2, map.get(key));
			}

			if(count1 == count2)	output[j] = count1-1;

			else	output[j] = Math.min(count1, count2);
			j++;
		}

		for(int i=0; i<output.length; i++) {
			System.out.println(output[i]);
		}
	}

}


package codeForces;

import java.util.HashMap;
import java.util.Scanner;

public class TwoTeamsComposing {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s = new Scanner(System.in);
		int t = s.nextInt();

		while(t != 0) {
			t--;

			int[] arr = new int[s.nextInt()];
			HashMap<Integer, Integer> map = new HashMap<>();

			for(int i=0; i<arr.length; i++) {
				arr[i] = s.nextInt();
				if(map.containsKey(arr[i])) {
					map.put(arr[i], 1+map.get(arr[i]));
				}
				else	map.put(arr[i], 1);
			}

			int count1 = 0;
			int count2 = 0;

			for(int key : map.keySet()) {
				count1++;
				count2 = Math.max(count2, map.get(key));
			}

			if(count1 == count2)	System.out.println(count1-1);

			else	System.out.println(Math.min(count1, count2));
		}
	}

}


import java.util.HashMap;
import java.util.Scanner;

public class TwoTeamsComposing {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s = new Scanner(System.in);
		int t = s.nextInt();
		int[] output = new int[t];
		int j=0;
		while(t != 0) {
			t--;

			int[] arr = new int[s.nextInt()];
			if(arr.length == 0) {
				output[j] = 0;
				continue;
			}
			HashMap<Integer, Integer> map = new HashMap<>();

			for(int i=0; i<arr.length; i++) {
				arr[i] = s.nextInt();
				if(map.containsKey(arr[i])) {
					map.put(arr[i], 1+map.get(arr[i]));
				}
				else	map.put(arr[i], 1);
			}

			int count1 = 0;
			int count2 = 0;

			for(int key : map.keySet()) {
				count1++;
				count2 = Math.max(count2, map.get(key));
			}

			if(count1 == count2)	output[j] = count1-1;

			else	output[j] = Math.min(count1, count2);
			j++;
		}

		for(int i=0; i<output.length; i++) {
			System.out.println(output[i]);
		}
	}

}


import java.io.*;
import java.util.*;

public class C{
    public static void main(String[] args) {
        FastReader fs=new FastReader();
        PrintWriter out=new PrintWriter(System.out);
        int t=1;
        t=fs.nextInt();
        for(int i=1;i<=t;i++) {
        	C m=new C();
            m.solve(i,out,fs);
        }
        out.close();
    }

    public void solve(int test,PrintWriter out,FastReader fs){
        int n=fs.nextInt();
        int f[]=new int[(int)1e6];
        int unique=0,max=0;
        for(int i=0;i<n;i++){
            int num=fs.nextInt();
            f[num]++;
            if(f[num]==1){
                unique++;
            }
            max=Integer.max(max,f[num]);
        }
        int ans=Integer.min(unique,max);
        if(unique==max)ans--;
        out.println(ans);
    }
}
class FastReader{
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st=new StringTokenizer("");
    String next(){
        while(!st.hasMoreTokens()){
            try {
                st=new StringTokenizer(br.readLine());
            } catch (IOException e) {
				e.printStackTrace();
			}
        }
        return st.nextToken();
    }
    int nextInt(){
        return Integer.parseInt(next());
    }
    long nextLong(){
        return Long.parseLong(next());
    }
    int[] nextIntArray(int n){
        int a[]=new int[n];
        for(int i=0;i<n;i++)a[i]=nextInt();
        return a;
    }
    long[] nextLongArray(int n){
        long a[]=new long[n];
        for(int i=0;i<n;i++)a[i]=nextInt();
        return a;
    }
    char[] nextCharArray(){
        char a[]=next().toCharArray();
        return a;
    }
}


import java.io.*;
import java.util.*;

public class C{
    public static void main(String[] args) {
        FastReader fs=new FastReader();
        PrintWriter out=new PrintWriter(System.out);
        int t=1;
        t=fs.nextInt();
        for(int i=1;i<=t;i++) {
        	C m=new C();
            m.solve(i,out,fs);
        }
        out.close();
    }

    public void solve(int test,PrintWriter out,FastReader fs){
        int n=fs.nextInt();
        int a[]=fs.nextIntArray(n);
        int f[]=new int[(int)1e6];
        for(int i=0;i<n;i++){
            f[a[i]]++;
        }
        int unique=0,max=0;
        for(int i=0;i<1e6;i++){
            if(f[i]>0){
                unique++;
                max=Integer.max(max,f[i]);
            }
        }
        int ans=Integer.min(unique,max);
        if(unique==max)ans--;
        out.println(ans);
    }
}
class FastReader{
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st=new StringTokenizer("");
    String next(){
        while(!st.hasMoreTokens()){
            try {
                st=new StringTokenizer(br.readLine());
            } catch (IOException e) {
				e.printStackTrace();
			}
        }
        return st.nextToken();
    }
    int nextInt(){
        return Integer.parseInt(next());
    }
    long nextLong(){
        return Long.parseLong(next());
    }
    int[] nextIntArray(int n){
        int a[]=new int[n];
        for(int i=0;i<n;i++)a[i]=nextInt();
        return a;
    }
    long[] nextLongArray(int n){
        long a[]=new long[n];
        for(int i=0;i<n;i++)a[i]=nextInt();
        return a;
    }
    char[] nextCharArray(){
        char a[]=next().toCharArray();
        return a;
    }
}


import java.io.*;
import java.util.*;

public class C{
    public static void main(String[] args) {
        FastReader fs=new FastReader();
        PrintWriter out=new PrintWriter(System.out);
        int t=1;
        t=fs.nextInt();
        for(int i=1;i<=t;i++) {
        	C m=new C();
            m.solve(i,out,fs);
        }
        out.close();
    }

    public void solve(int test,PrintWriter out,FastReader fs){
        int n=fs.nextInt();
        int a[]=fs.nextIntArray(n);
        int f[]=new int[(int)1e6];
        int unique=0,max=0;
        for(int i=0;i<n;i++){
            f[a[i]]++;
            if(f[a[i]]==1){
                unique++;
            }
            max=Integer.max(max,f[a[i]]);
        }
        int ans=Integer.min(unique,max);
        if(unique==max)ans--;
        out.println(ans);
    }
}
class FastReader{
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st=new StringTokenizer("");
    String next(){
        while(!st.hasMoreTokens()){
            try {
                st=new StringTokenizer(br.readLine());
            } catch (IOException e) {
				e.printStackTrace();
			}
        }
        return st.nextToken();
    }
    int nextInt(){
        return Integer.parseInt(next());
    }
    long nextLong(){
        return Long.parseLong(next());
    }
    int[] nextIntArray(int n){
        int a[]=new int[n];
        for(int i=0;i<n;i++)a[i]=nextInt();
        return a;
    }
    long[] nextLongArray(int n){
        long a[]=new long[n];
        for(int i=0;i<n;i++)a[i]=nextInt();
        return a;
    }
    char[] nextCharArray(){
        char a[]=next().toCharArray();
        return a;
    }
}


import java.io.*;
import java.util.*;

public class C{
    public static void main(String[] args) {
        FastReader fs=new FastReader();
        PrintWriter out=new PrintWriter(System.out);
        int t=1;
        t=fs.nextInt();
        for(int i=1;i<=t;i++) {
        	C m=new C();
            m.solve(i,out,fs);
        }
        out.close();
    }

    public void solve(int test,PrintWriter out,FastReader fs){
        int n=fs.nextInt();
        int f[]=new int[n+1];
        int unique=0,max=0;
        for(int i=0;i<n;i++){
            int num=fs.nextInt();
            f[num]++;
            if(f[num]==1){
                unique++;
            }
            max=Integer.max(max,f[num]);
        }
        int ans=Integer.min(unique,max);
        if(unique==max)ans--;
        out.println(ans);
    }
}
class FastReader{
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st=new StringTokenizer("");
    String next(){
        while(!st.hasMoreTokens()){
            try {
                st=new StringTokenizer(br.readLine());
            } catch (IOException e) {
				e.printStackTrace();
			}
        }
        return st.nextToken();
    }
    int nextInt(){
        return Integer.parseInt(next());
    }
    long nextLong(){
        return Long.parseLong(next());
    }
    int[] nextIntArray(int n){
        int a[]=new int[n];
        for(int i=0;i<n;i++)a[i]=nextInt();
        return a;
    }
    long[] nextLongArray(int n){
        long a[]=new long[n];
        for(int i=0;i<n;i++)a[i]=nextInt();
        return a;
    }
    char[] nextCharArray(){
        char a[]=next().toCharArray();
        return a;
    }
}


import java.util.*;
import java.io.*;
public class b{

	public static void main(String [] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int t=Integer.parseInt(br.readLine().trim());

		while(t-->0){

			int n=Integer.parseInt(br.readLine().trim());
			String [] data=br.readLine().trim().split(" ");
			int [] arr=new int[n];
			int mm=Integer.MIN_VALUE;

			for(int i=0;i<n;i++){
				arr[i]=Integer.parseInt(data[i]);
				mm=Math.max(mm,arr[i]);
			}

			int [] map=new int[mm+1];
			for(int i=0;i<n;i++){
				map[arr[i]]++;
			}

			int max=0;
			int max_element=-1;
			for(int i=0;i<=mm;i++){
				if(map[i]>max){
					max=map[i];
					max_element=i;
				}
			}

			boolean [] b=new boolean [mm+1];
			b[max_element]=true;
			int cnt=0;
			for(int i=0;i<n && max>0;i++){
				if(!b[arr[i]] && max>0){
					b[arr[i]]=true;
					cnt++;
					max--;
				}
			}
			if(max>=2){
				cnt++;
			}
			System.out.println(cnt);

		}

	}
}


import java.util.*;
import java.io.*;
public class a{
    public static void main(String [] args) throws IOException{
      Scanner sc=new Scanner(System.in);
      BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
      int t=Integer.parseInt(br.readLine().trim());
      while(t-->0){
          int [] freq=new int[200001];
          int n=Integer.parseInt(br.readLine().trim());
          String [] data=br.readLine().trim().split(" ");
          int [] a=new int[n];
          int mm=-1;
          for(int i=0;i<n;i++){
              a[i]=Integer.parseInt(data[i]);
              mm=Math.max(a[i],mm);
              freq[a[i]]++;
          }

          int distinct=0;
          int max=-1;
          for(int i=1;i<=mm;i++){
              if(freq[i]>0){
                  distinct++;
                  max=Math.max(max,freq[i]);
              }
          }

          if(max<distinct){
              System.out.println(max);
          }
          else if(max>distinct){
              System.out.println(distinct);
          }
          else{
              System.out.println(distinct-1);
          }

        }
    }
}


import java.util.*;
import java.io.*;
public class b{
	static int MAX_SIZE=200001;
	public static void main(String [] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int t=Integer.parseInt(br.readLine().trim());
		while(t-->0){
			int n=Integer.parseInt(br.readLine().trim());
			String [] data=br.readLine().trim().split(" ");
			int [] arr=new int[n];
			int [] map=new int[MAX_SIZE];
			Arrays.fill(map,0);
			int max=0;
			int max_element=-1;
			for(int i=0;i<n;i++){
				arr[i]=Integer.parseInt(data[i]);
				++map[arr[i]];
				if(map[arr[i]]>max){
					max=map[arr[i]];
					max_element=arr[i];
				}
			}

			boolean [] b=new boolean [MAX_SIZE];
			Arrays.fill(b,false);
			b[max_element]=true;
			int cnt=0;
			for(int i=0;i<n;i++){
				if(!b[arr[i]] && max>0){
					b[arr[i]]=true;
					cnt++;
					max--;
				}
			}
			if(max>=2){
				cnt++;
			}
			System.out.println(cnt);

		}

	}
}


import java.util.*;
import java.io.*;
public class a{
    static int [] freq;
    public static void main(String [] args){
      Scanner sc=new Scanner(System.in);
      int t=sc.nextInt();
      while(t-->0){
          freq=new int[200001];
          int n=sc.nextInt();
          int [] a=new int[n];
          int mm=-1;
          for(int i=0;i<n;i++){
              a[i]=sc.nextInt();
              mm=Math.max(a[i],mm);
              freq[a[i]]++;
          }
          int distinct=0;
          int max=-1;
          for(int i=1;i<=mm;i++){
              if(freq[i]>0){
                  distinct++;
                  max=Math.max(max,freq[i]);
              }
          }

          if(max<distinct){
              System.out.println(max);
          }
          else if(max>distinct){
              System.out.println(distinct);
          }
          else{
              System.out.println(distinct-1);
          }

        }
    }
}


import java.util.*;
import java.io.*;
public class b{
	static int MAX_SIZE=200001;
	public static void main(String [] args){
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		while(t-->0){
			int n=sc.nextInt();
			int [] arr=new int[n];
			int [] map=new int[MAX_SIZE];
			Arrays.fill(map,0);
			for(int i=0;i<n;i++){
				arr[i]=sc.nextInt();
				++map[arr[i]];
			}
			int max=0;
			int max_element=-1;
			for(int i=0;i<MAX_SIZE;i++){
				if(max<map[i]){
					max=map[i];
					max_element=i;
				}
			}
			boolean [] b=new boolean [MAX_SIZE];
			Arrays.fill(b,false);
			b[max_element]=true;
			int cnt=0;
			for(int i=0;i<n;i++){
				if(!b[arr[i]] && max>0){
					b[arr[i]]=true;
					cnt++;
					max--;
				}
			}
			if(max>=2){
				cnt++;
			}

			System.out.println(cnt);

		}

	}
}


import java.util.*;
import java.io.*;
public class a{
    static int [] freq;
    public static void main(String [] args){
      Scanner sc=new Scanner(System.in);
      int t=sc.nextInt();
      while(t-->0){
          freq=new int[200001];
          int n=sc.nextInt();
          int [] a=new int[n];
          for(int i=0;i<n;i++){
              a[i]=sc.nextInt();
              freq[a[i]]++;
          }
          int distinct=0;
          int max=-1;
          for(int i=0;i<freq.length;i++){
              if(freq[i]>0){
                  distinct++;
                  max=Math.max(max,freq[i]);
              }
          }
        //   System.out.println(distinct+" "+max);

          if(max<distinct){
              System.out.println(max);
          }
          else if(max>distinct){
              System.out.println(distinct);
          }
          else{
              System.out.println(distinct-1);
          }

        }
    }
}


/******************************************************************************

                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/
import java.util.*;
public class Main
{
	public static void main(String[] args) {
		Scanner s=new Scanner(System.in);
		int t=s.nextInt();
		for(int i=0;i<t;i++)
		{
		    int n=s.nextInt();
		    if (n==0)
		    {System.out.println(0);
		    continue;}
		    int ar[]=new int[n];
		    for(int p=0;p<n;p++)
		    {
		        ar[p]=s.nextInt();
		    }

		   Map<Integer,Integer> num =new HashMap<Integer,Integer>();
		   for(int p=0;p<n;p++)
		   {    if(num.containsKey(ar[p]))
		           num.replace(ar[p],num.get(ar[p])+1);
		           else
		           num.put(ar[p],1);

		   }
		//   System.out.println(num.get(1));
		   int max=Collections.max(num.values());
		 int b=num.size();
		 if(max>b)
		 {
		     b++;
		 }

		 if(max==b)
		 b--;
		 if(max==0&&b!=0&&n!=1)

		{
		    System.out.println(1);
		    continue;
		}
		 if(max<b)
		 System.out.println(max);
		 else System.out.println(b);

		}
	}
}


/******************************************************************************

                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/
import java.util.*;
public class Main
{
	public static void main(String[] args) {
		Scanner s=new Scanner(System.in);
		int t=s.nextInt();
		for(int i=0;i<t;i++)
		{
		    int n=s.nextInt();
		    if (n==0)
		    {System.out.println(0);
		    continue;}
		    int ar[]=new int[n];
		    for(int p=0;p<n;p++)
		    {
		        ar[p]=s.nextInt();
		    }

		   Map<Integer,Integer> num =new HashMap<Integer,Integer>();
		   for(int p=0;p<n;p++)
		   {    if(num.containsKey(ar[p]))
		           num.replace(ar[p],num.get(ar[p])+1);
		           else
		           num.put(ar[p],1);

		   }
		//   System.out.println(num.get(1));
		   int max=Collections.max(num.values());
		 int b=num.size();
		 if(max>b)
		 {
		     b++;
		 }

		 if(max==b)
		 b--;
		 if(max==1&&b!=0&&n!=1)

		{
		    System.out.println(1);
		    continue;
		}
		 if(max<b)
		 System.out.println(max);
		 else System.out.println(b);

		}
	}
}