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 javax.swing.plaf.synth.SynthSeparatorUI;
public class Problem3 {
	static Scanner sc=new Scanner(System.in);
	static PrintWriter out=new PrintWriter(System.out);
	public static void main(String[] args) throws IOException, InterruptedException {
	int q=sc.nextInt();
	while(q-->0) {
	int n=sc.nextInt();
	int a[]=new int[n];
	for (int i = 0; i < a.length; i++) {
		a[i]=sc.nextInt();
	}
	int count[]=new int[n+1];
	for (int i = 0; i <n; i++) {
		count[a[i]]++;
	}
	HashSet<Integer> set=new HashSet<>();
	TreeSet<Integer> tset=new TreeSet<>();
	int sum=0;
	for (int i = 0; i < count.length; i++) {
		if(!set.contains(count[i])) {
			set.add(count[i]);
			sum+=count[i];
		
		}
		else {
		int temp=count[i];
		while(set.contains(temp)&&temp>0) {
			temp--;
		}
		set.add(temp);
		sum+=temp;
		}
		
	
	}
	System.out.println(sum
			);
	}
	}
	private static boolean check(int k, int mid, int a, int b,int n) {
		long normal=n-mid;
		long cost1=1l*normal*1l*b*1l;
		long cost2=1l*mid*1l*a*1l;
		if(cost1+cost2>=k)
		return false;
		else
			return true;
	}
	static long pow(long a, int n,int mod)
	{
		long res = 1;
		while(n != 0)
		{
			if((n & 1) == 1)
				res = (res*(a%mod))%mod;
			a *= (a%mod);
			a=a%mod;
			n >>= 1;			
		}
		return res;
	}
	static TreeSet<Integer> primes;
	static int[] isComposite;

	static void sieve(int N)	// O(N log log N) 
	{
		isComposite = new int[N+1];					
		isComposite[0] = isComposite[1] = 1;			// 0 indicates a prime number
		primes = new TreeSet<Integer>();

		for (int i = 2; i <= N; ++i) 					//can loop till i*i <= N if primes array is not needed O(N log log sqrt(N)) 
			if (isComposite[i] == 0) 					//can loop in 2 and odd integers for slightly better performance
			{
				primes.add(i);
				if(1l * i * i <= N)
					for (int j = i * i; j <= N; j += i)	// j = i * 2 will not affect performance too much, may alter in modified sieve
						isComposite[j] = 1;
			}   
	}
	static int INF=(int) 1E9;
	static class Pair{
		int x;
		int y;
		public Pair(int x,int y) {
			this.x=x;
			this.y=y;
		}
		
	}
	public static int[] schuffle(int a[]) {
		for (int i = 0; i < a.length; i++) {
			int x=(int)(Math.random()*a.length);
		int temp=a[x];
		a[x]=a[i];
		a[i]=temp;
		}
		return a;
	}
	static long gcd(long min,long a) {
		if(a==0) {
			return min;
		}
		return gcd(a,min%a);
	}
static int 	factprime(int n,int p) {
	int pow=0;
	for(int i=p ; i<=n ; i=i*p) {
		pow+=n/i;
	}
	return pow;
}
static long power(long x, long y) 
{ 
    long temp; 
    if( y == 0) 
        return 1; 
       
    temp = power(x, y/2); 
    if (y%2 == 0) 
        return ((temp%10)*(temp)%10)%10; 
    else
        return ((x%10)*(temp%10)*(temp%10))%10;
}  
	static ArrayList<Integer> adj[];
static Stack<Integer> st=new Stack<>();
static  boolean visited[];
static void dfs(int i){
	visited[i]=true;
	st.add(i);
	for(int x:adj[i]) {
		if(!visited[x])
			dfs(x);
	}
}


	static  class Scanner {
	StringTokenizer st;
	BufferedReader br;

	public Scanner(InputStream s) {
		br = new BufferedReader(new InputStreamReader(s));
	}

	public String next() throws IOException {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	public int[] nextIntArr(int n) throws IOException {
		int[] arr = new int[n];
		for (int i = 0; i < n; i++)
			arr[i] = nextInt();
		return arr;
	}

	public long[] nextLongArr(int n) throws IOException {
		long[] arr = new long[n];
		for (int i = 0; i < n; i++)
			arr[i] = nextLong();
		return arr;
	}

	public long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	public String nextLine() throws IOException {
		return br.readLine();
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	public boolean ready() throws IOException {
		return br.ready();
	}
	public void waitForInput() throws InterruptedException {Thread.sleep(2300);}
}



static class SegmentTree {
	int N; // number of elements in my array after the padding
	int [] array, sTree, lazy; 
	SegmentTree(int []inp){
		N = inp.length - 1;
		array = inp;
		sTree =  new int[N<<1];
		lazy =  new int[N<<1];
		build(1, 1, N);
	}
	void build(int node, int b, int e) {
		if(b == e) {
			//node = b + N - 1
			// update(idx , value)
			// sTree[idx + N - 1] += value
			sTree[node] = array[b];
		}
		else {
			int nodeLeft = node << 1;
			int nodeRight = (node << 1)+1;
			int mid = (b + e) >> 1;
			build(nodeLeft, b , mid);
			build(nodeRight, mid + 1, e);
			sTree[node] = sTree[nodeLeft] + sTree[nodeRight];
		}
	}
	void propagate(int node, int b, int e) {
		int leftChild = node << 1;
		int rightChild = node<<1|1;
		lazy[leftChild] += lazy[node];
		lazy[rightChild] += lazy[node];
		int mid = (b + e)>>1;
		if(lazy[node]%2!=0) {
		sTree[leftChild] = (mid - b + 1)-sTree[leftChild];
		sTree[rightChild] =(e - mid)-sTree[rightChild];
		}
		lazy[node] = 0;
	}
	// add value v for element in position idx in my input array
	//O(log(N))
	void update_point(int idx, int v) {
		int node = idx + N - 1;
		sTree[node] += v;
		while(node > 1) {
			node >>= 1;
			sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
		}
	}
	// O(log(N))
	int query(int i, int j) {
		return query(1, 1, N, i, j); 
	}
	int query(int node, int b, int e, int i, int j) {
		
		
		if(i > e || j < b)
			return 0;
		if(b >= i && e <= j)
			return sTree[node];
		int mid = (b + e) >> 1;
		propagate(node, b, e);
        int q1 = query(node << 1, b, mid, i , j);
		int q2 = query(node<<1|1, mid + 1, e, i, j);
		return q1 + q2;
		
		
	}
	void update_range(int i, int j) { //O(log(N))
		update_range(1, 1, N, i, j); 
	}
	void update_range(int node, int b, int e, int i, int j) {
		if(i > e || j < b)
			return;
		if(b >= i && e <= j) {
			sTree[node] = (e - b + 1)-sTree[node];
			lazy[node]+=1;
		}
		else {
			int mid = (b + e) >> 1;
			propagate(node, b, e);
			update_range(node<<1, b , mid, i, j);
			update_range(node<<1|1, mid+1, e, i, j);
			sTree[node] = sTree[node<<1] + sTree[node<<1|1];
		}
	}
}
}