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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.AbstractCollection;
import java.util.PriorityQueue;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Comparator;
import java.util.TreeSet;
import java.io.InputStream;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author NMouad21
 */
public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    GCandyBoxHardVersion solver = new GCandyBoxHardVersion();
    solver.solve(1, in, out);
    out.close();
  }

  static class GCandyBoxHardVersion {

    public void solve(int testNumber, InputReader in, PrintWriter out) {
      int q = in.nextInt();
      while (q-- > 0) {
        int n = in.nextInt();
        int[][] cnt = new int[n + 1][2];
        for (int i = 0; i < n; i++) {
          int a = in.nextInt();
          int f = in.nextInt();
          ++cnt[a][0];
          if (f == 1) {
            ++cnt[a][1];
          }
        }
        Arrays.sort(cnt, Comparator.comparingInt(x -> x[0]));
        ArrayUtils.reverse(cnt);

        int ans = 0, last = Integer.MAX_VALUE / 2;
        TreeSet<Integer> used = new TreeSet<>();
        for (int[] tCnt : cnt) {
          int a = tCnt[0];
          if (a == 0 || last == 0) {
            break;
          }
          last = Math.max(0, Math.min(last - 1, a));
          ans += last;
          if (last != 0) {
            used.add(last);
          }
        }

        PriorityQueue<int[]> cntpq = new PriorityQueue<>(Comparator.comparingInt(x -> -x[1]));
        for (int[] tCnt : cnt) {
          if (tCnt[0] > 0) {
            cntpq.add(tCnt);
          }
        }

        int ansf = 0;
        while (!cntpq.isEmpty() && !used.isEmpty()) {
          int[] tCnt = cntpq.poll();
          int a = tCnt[0];
          int f = tCnt[1];

          Integer target = used.floor(a);
          if (target != null) {
            if (target >= f) {
              ansf += f;
            } else {
              ansf += target;
            }
            used.remove(target);
          }
        }

        out.println(ans + " " + ansf);
      }
    }

  }

  static class ArrayUtils {

    public static <T> void reverse(T[] arr) {
      for (int i = 0; i < arr.length / 2; i++) {
        T temp = arr[i];
        arr[i] = arr[arr.length - i - 1];
        arr[arr.length - i - 1] = temp;
      }
    }

  }

  static class InputReader {

    private InputStream stream;
    private static final int DEFAULT_BUFFER_SIZE = 1 << 16;
    private static final int EOF = -1;
    private byte[] buf = new byte[DEFAULT_BUFFER_SIZE];
    private int curChar;
    private int numChars;

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

    public int read() {
      if (this.numChars == EOF) {
        throw new UnknownError();
      } else {
        if (this.curChar >= this.numChars) {
          this.curChar = 0;

          try {
            this.numChars = this.stream.read(this.buf);
          } catch (IOException ex) {
            throw new InputMismatchException();
          }

          if (this.numChars <= 0) {
            return EOF;
          }
        }

        return this.buf[this.curChar++];
      }
    }

    public int nextInt() {
      int c;
      for (c = this.read(); isSpaceChar(c); c = this.read()) {
      }

      byte sgn = 1;
      if (c == 45) {
        sgn = -1;
        c = this.read();
      }

      int res = 0;

      while (c >= 48 && c <= 57) {
        res *= 10;
        res += c - 48;
        c = this.read();
        if (isSpaceChar(c)) {
          return res * sgn;
        }
      }

      throw new InputMismatchException();
    }

    public static boolean isSpaceChar(int c) {
      return c == 32 || c == 10 || c == 13 || c == 9 || c == EOF;
    }

  }
}