Problem: This problem is actually a subproblem of problem G from the same contest.

There are n candies in a candy box. The type of the i-th candy is a_i (1 ≤ a_i ≤ n).

You have to prepare a gift using some of these candies with the following restriction: the numbers of candies of each type presented in a gift should be all distinct (i. e. for example, a gift having two candies of type 1 and two candies of type 2 is bad). 

It is possible that multiple types of candies are completely absent from the gift. It is also possible that not all candies of some types will be taken to a gift.

Your task is to find out the maximum possible size of the single gift you can prepare using the candies you have.

You have to answer q independent queries.

If you are Python programmer, consider using PyPy instead of Python when you submit your code.

Input

The first line of the input contains one integer q (1 ≤ q ≤ 2 ⋅ 10^5) — the number of queries. Each query is represented by two lines.

The first line of each query contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of candies.

The second line of each query contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n), where a_i is the type of the i-th candy in the box.

It is guaranteed that the sum of n over all queries does not exceed 2 ⋅ 10^5.

Output

For each query print one integer — the maximum possible size of the single gift you can compose using candies you got in this query with the restriction described in the problem statement.

Example

Input


3
8
1 4 8 4 5 6 3 8
16
2 1 3 3 4 3 4 4 1 3 2 2 2 4 1 1
9
2 2 4 4 4 7 7 7 7


Output


3
10
9

Note

In the first query, you can prepare a gift with two candies of type 8 and one candy of type 5, totalling to 3 candies.

Note that this is not the only possible solution — taking two candies of type 4 and one candy of type 6 is also valid.

Solution (in JAVA):

Solution:
	import java.io.*;
	import java.util.*;
	import java.math.*;
	
	 
	 public class Main	{
	   static class Pair implements Comparable<Pair>{
	   int a;
	   int b;
	   public Pair(){}
	   public Pair(int x,int y){a=x;b=y;}
	   public int compareTo(Pair p){
		 return Integer.compare(a, p.a);
	   }
//		   long a,b;
//		   public Pair(long x,long y){a=x;b=y;}
//		   public int compareTo(Pair p){
//				 return Long.compare(a, p.a);
//		   }
//		  
		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + a;
			result = prime * result + b;
		   
			return result;
		}
		@Override
		public boolean equals(Object obj) {
			Pair cur = (Pair)obj;
			if((a==cur.a && b==cur.b))return true;
			return false;
		}
	 }
	   static class ArrayUtils {
		public static Integer[] generateOrder(int size) {
			Integer[] order = new Integer[size];
			for (int i = 0; i < size; i++)
				order[i] = i;
			return order;
		}
	 
		public static Integer[] order(int size, Comparator<Integer> comparator) {
			Integer[] order = generateOrder(size);
			Arrays.sort(order, comparator);
			return order;
		}
	 
			}
	   static class cell implements Comparable<cell>{
		   int a,b;
		   long dis;
		   public cell(int x,int y,long z) {a=x;b=y;dis=z;}
		   public int compareTo(cell c) {
			   return Long.compare(dis,c.dis);
		   }
	   }
	static class TrieNode{
		TrieNode left;
		TrieNode right;
		int op;
		int data;
		public TrieNode() {}
	}
	  public static int gcd(int a,int b)
	  {
	    if(a<b)
	      return gcd(b,a);
	    if(b==0)
	      return a;
	    return gcd(b,a%b);
	    
	  }
	  static int lcm(int a,int b) {
		  return  a*b / gcd(a,b);
	  }
	  //static long ans = 0;
	  static long mod = (long)(1e9+7); //998244353;//
	   
	    public static void main(String[] args) throws Exception {
	       new Thread(null, null, "Anshum Gupta", 99999999) {
	            public void run() {
	                try {
	                    solve();
	                } catch(Exception e) {
	                    e.printStackTrace();
	                    System.exit(1);
	                }
	            }
	        }.start();
	    }
	
	static long pow(long x,long y){
	    if(y == 0)return 1;
	    if(y==1)return x;
	    long a = pow(x,y/2);
	    a = (a*a)%mod;
	    if(y%2==0){
	        return a;
	    }
	    return (a*x)%mod;
	}
	
	static long mxx;
	static int mxN = (int)(2e6+5);
	static int mxV = (int)(2e5);
	static long[]fact,inv_fact;
	static long my_inv(long a) {
		return pow(a,mod-2);
	}
	static long bin(int a,int b) {
		if(a < b || a<0 || b<0)return 0;
	    return ((fact[a]*inv_fact[a-b])%mod * inv_fact[b])%mod;
	}
		static ArrayList<ArrayList<Integer>>adj;
		static boolean[]vis;
	static void make_facts() {
	  fact=new long[mxN];
	  inv_fact = new long[mxN];
	  fact[0]=inv_fact[0]=1L;
	  for(int i=1;i<mxN;i++) {
		   fact[i] = (i*fact[i-1])%mod;
		   inv_fact[i] = my_inv(fact[i]);
	  }
	}
	
	 public static void solve() throws Exception {
	   // solve the problem here
	   MyScanner s = new MyScanner();
	        out = new PrintWriter(new BufferedOutputStream(System.out), true);
	        int tc = 1;//s.nextInt();
	        mxx = (long)(1e18+5);
	//	        make_facts(); 
	//	        int mod = (int)1e9+7;
	        while(tc-->0){
	        	int q = s.nextInt();
	        	while(q-- > 0) {
	        		int n = s.nextInt();
		        	int[]a=new int[n+1];
		        	Integer[]cnt =  new Integer[n+1];
		        	Arrays.fill(cnt, 0);
		        	for(int i=1;i<=n;i++) {
		        		a[i] = s.nextInt();
		        		cnt[a[i]]++;
		        	}
		        	Arrays.parallelSort(cnt);
		        	long ans = 0, prev = n+1;
		        	for(int i=n;i>=1;i--) {
		        		if(cnt[i] < prev) {
		        			ans += cnt[i];
		        			prev = cnt[i];
		        		}
		        		else {
		        			ans += Math.max(0, Math.min(prev - 1, cnt[i]));
		        			prev = Math.max(0, Math.min(prev - 1, cnt[i]));
		        		}
		        		
		        	}
		        	out.println(ans);
	        	}
	        	
	        	
	        }
	        	
	           
	        out.flush();
	}
	 
	     
	 
	 
	 
	    //-----------PrintWriter for faster output---------------------------------
	    public static PrintWriter out;
	 
	    //-----------MyScanner class for faster input----------
	    public static class MyScanner {
	        BufferedReader br;
	        StringTokenizer st;
	 
	        public MyScanner() {
	            br = new BufferedReader(new InputStreamReader(System.in));
	        }
	 
	        String next() {
	            while (st == null || !st.hasMoreElements()) {
	                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()); }
	        double nextDouble() { return Double.parseDouble(next()); }
	         
	        String nextLine(){
	            String str = "";
	            try {
	                str = br.readLine();
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            return str;
	        }
	    }
	    //--------------------------------------------------------
	}