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:
//Author: Patel Rag
//Java version "1.8.0_211"
import java.util.*;
import java.io.*;

public class Main
{
  static class Reader
  {
    private byte[] buffer = new byte[1024];
    private int index;
    private InputStream in;
    private int total;
    public Reader()
    {
        in = System.in;
    }
    public int scan() throws IOException
    {
        if(total < 0)
        {
          throw new InputMismatchException();
        }
        if(index >= total)
        {
            index = 0;
            total = in.read(buffer);
            if(total <= 0)
            {
              return -1;
            }
        }
        return buffer[index++];
    }
    public int nextInt() throws IOException
    {
        int integer = 0;
        int n = scan();
        while(isWhiteSpace(n))
        {
          n = scan();
        }
        int neg = 1;
        if(n == '-')
        {
            neg = -1;
            n = scan();
        }
        while(!isWhiteSpace(n))
        {
            if(n >= '0' && n <= '9')
            {
                integer *= 10;
                integer += n - '0';
                n = scan();
            }
            else
            {
              throw new InputMismatchException();
            }
        }
        return neg*integer;
    }
    public long nextLong() throws IOException
    {
        int integer = 0;
        int n = scan();
        while(isWhiteSpace(n))
        {
          n = scan();
        }
        int neg = 1;
        if(n == '-')
        {
            neg = -1;
            n = scan();
        }
        while(!isWhiteSpace(n))
        {
            if(n >= '0' && n <= '9')
            {
                integer *= 10;
                integer += n - '0';
                n = scan();
            }
            else
            {
              throw new InputMismatchException();
            }
        }
        return neg*integer;
    }
    public double nextDouble() throws IOException
    {
        double doub = 0;
        int n = scan();
        while(isWhiteSpace(n))
        {
          n=scan();
        }
        int neg = 1;
        if(n == '-')
        {
            neg = -1;
            n = scan();
        }
        while(!isWhiteSpace(n) && n != '.')
        {
            if(n >= '0' && n <= '9')
            {
                doub*=10;
                doub+=n-'0';
                n = scan();
            }
            else
            {
              throw new InputMismatchException();
            }
        }
        if(n == '.')
        {
            n = scan();
            double temp = 1;
            while(!isWhiteSpace(n))
            {
                if(n >= '0' && n <= '9')
                {
                    temp/=10;
                    doub+=(n-'0')*temp;
                    n = scan();
                }
                else
                {
                  throw new InputMismatchException();
                }
            }
        }
        return doub*neg;
    }
    public String nextString() throws IOException
    {
        StringBuilder sb = new StringBuilder();
        int n = scan();
        while(isWhiteSpace(n))
        {
          n = scan();
        }
        while(!isWhiteSpace(n))
        {
            sb.append((char)n);
            n = scan();
        }
        return sb.toString();
    }
    private boolean isWhiteSpace(int n)
    {
        if(n == ' ' || n == '\n'|| n == '\r' || n == '\t'|| n == -1)
        return true;
        return false;
    }
  }
  static class FastReader
  {
    BufferedReader br;
    StringTokenizer st;

    public FastReader()
    {
      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;
    }
    void close() throws IOException
    {
      br.close();
    }
  }
  static class Print
  {
      private final BufferedWriter bw;
      public Print()
      {
          this.bw = new BufferedWriter(new OutputStreamWriter(System.out));
      }
      public void print(Object object)throws IOException
      {
          bw.append(""+object);
      }
      public void println(Object object)throws IOException
      {
          print(object);
          bw.append("\n");
      }
      public void close()throws IOException
      {
          bw.close();
      }
  }
  static long modExp(long x, long n, long mod)    //Modular exponentiation
  {
    long result = 1;
    while(n > 0)
    {
        if(n % 2 == 1)
            result = (result%mod * x%mod)%mod;
        x = (x%mod * x%mod)%mod;
        n=n/2;
    }
    return result;
  }
  static long gcd(long a, long b)
  {
    if(a==0) return b;
    return gcd(b%a,a);
  }
  static String swap(String a,int i, int j)
  {
    char temp;
    char[] s1 = a.toCharArray();
    temp = s1[i];
    s1[i] = s1[j];
    s1[j] = temp;
    return String.valueOf(s1);
  }
  static int sumDigi(int a)
  {
    int res = 0;
    while(a!=0)
    {
      res = res + a%10;
      a = a/10;
    }
    return res;
  }
  public static void main(String[] args)
  throws IOException
  {
    Reader fr = new Reader();
    Print log = new Print();
    int q = fr.nextInt();
    for(int Q = 0; Q < q; Q++)
    {
      int n = fr.nextInt();
      ArrayList<Long> cnt = new ArrayList<>();
      HashMap<Long,Integer> map = new HashMap<>();
      for(int i = 0; i < n; i++)
      {
        Long v = fr.nextLong();
        if(!map.containsKey(v))
        {
          map.put(v,cnt.size());
          cnt.add((long)0);
        }
        int ind = map.get(v);
        cnt.set(ind,cnt.get(ind) + 1);
      }
      cnt.sort(null);
      Collections.reverse(cnt);
      long ans = 0;
      HashSet<Long> set = new HashSet<>();
      int i = 0;
      while(i < cnt.size())
      {
        long v = cnt.get(i);
        int j = i;
        int ofs = 0;
        while(j < cnt.size() && cnt.get(j) == v && cnt.get(j) > ofs)
        {
          long u = cnt.get(j) - ofs;
          if(!set.contains(u))
          {
            ans = ans + u;
            set.add(u);
            j++;
          }
          ofs++;
        }
        while(j < cnt.size() && cnt.get(j) == v)
        {
          j++;
        }
        i = j;
      }
      log.println(ans);
    }

    log.close();
  }
}
class Pair<U, V>  // Pair class
{
    public final U first;       // first field of a Pair
    public final V second;      // second field of a Pair

    private Pair(U first, V second)
    {
      this.first = first;
      this.second = second;
    }

    @Override
    public boolean equals(Object o)
    {
      if (this == o) return true;

      if (o == null || getClass() != o.getClass()) return false;

      Pair<?, ?> pair = (Pair<?, ?>) o;

      if (!first.equals(pair.first)) return false;
      return second.equals(pair.second);
    }

    @Override
    public int hashCode()
    {
      return 31 * first.hashCode() + second.hashCode();
    }

    public static <U, V> Pair <U, V> of(U a, V b)
    {
      return new Pair<>(a, b);
    }
}
class myComp implements Comparator<Pair>
{
  public int compare(Pair a,Pair b)
  {
    if((Integer)a.second > (Integer)b.second) return -1;
    if((Integer)a.second < (Integer)b.second) return 1;
    if((Integer)a.first > (Integer)b.first) return 1;
    return -1;
  }
}
class BIT       //Binary Indexed Tree
{
  public long[] m_array;

  public BIT(long[] dat)
  {
    m_array = new long[dat.length + 1];
    Arrays.fill(m_array,0);
    for(int i = 0; i < dat.length; i++)
    {
      m_array[i + 1] = dat[i];
    }
    for(int i = 1; i < m_array.length; i++)
    {
      int j = i + (i & -i);
      if(j < m_array.length)
      {
        m_array[j] = m_array[j] + m_array[i];
      }
    }
  }

  public final long prefix_query(int i)
  {
    long result = 0;
    for(++i; i > 0; i = i - (i & -i))
    {
      result = result + m_array[i];
    }
    return result;
  }

  public final long range_query(int fro, int to)
  {
    if(fro == 0)
    {
      return prefix_query(to);
    }
    else
    {
      return (prefix_query(to) - prefix_query(fro - 1));
    }
  }

  public void update(int i, long add)
  {
    for(++i; i < m_array.length; i = i + (i & -i))
    {
      m_array[i] = m_array[i] + add;
    }
  }
}