#include <bits/stdc++.h>
using namespace std;
inline void print(int n) {
  if (n == 0) {
    putchar('0');
    putchar('\n');
  } else if (n == -1) {
    putchar('-');
    putchar('1');
    putchar('\n');
  } else {
    char buf[11];
    buf[10] = '\n';
    int i = 9;
    while (n) {
      buf[i--] = n % 10 + '0';
      n /= 10;
    }
    while (buf[i] != '\n') putchar(buf[++i]);
  }
}
int read() {
  int cc = getc(stdin);
  for (; cc < '0' || cc > '9';) cc = getc(stdin);
  int ret = 0;
  for (; cc >= '0' && cc <= '9';) {
    ret = ret * 10 + cc - '0';
    cc = getc(stdin);
  }
  return ret;
}
long long power(long long num, long long g) {
  if (g == 0) return 1;
  if (g % 2 == 1) return (num * power((num * num), g / 2));
  return power((num * num), g / 2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n], c[n], d[n + 1];
    for (int i = 0; i < n; i++) cin >> a[i] >> c[i];
    int b[n + 1];
    memset(b, 0, sizeof(b));
    for (int i = 0; i < n; i++) b[a[i]]++;
    sort(b, b + n + 1);
    int ans = 0;
    int maximum = n;
    for (int i = n; i > 0; i--) {
      if (maximum <= 0) break;
      if (maximum < b[i]) {
        ans += maximum;
        maximum--;
      } else {
        ans += b[i];
        maximum = b[i] - 1;
      }
    }
    cout << ans << " ";
    memset(b, 0, sizeof(b));
    memset(d, 0, sizeof(d));
    for (int i = 0; i < n; i++) {
      b[a[i]]++;
      d[a[i]] += c[i];
    }
    priority_queue<int> pq;
    maximum = n;
    ans = 0;
    pair<int, int> pa[n + 1];
    for (int i = 0; i < n + 1; i++) pa[i] = make_pair(b[i], d[i]);
    sort(pa, pa + n + 1);
    for (int i = 0; i < n + 1; i++) b[i] = pa[i].first;
    for (int i = 0; i < n + 1; i++) d[i] = pa[i].second;
    for (int i = n; i > 0; i--) {
      if (maximum <= 0) continue;
      if (b[i] == 0 && pq.empty()) continue;
      if (pq.empty()) maximum = min(maximum, b[i]);
      while (maximum <= b[i]) {
        pq.push(d[i]);
        i--;
      }
      i++;
      if (!pq.empty()) {
        ans += min(maximum, pq.top());
        pq.pop();
      }
      maximum--;
    }
    cout << ans << endl;
  }
  return 0;
}

### Prompt

Develop a solution in Cpp to the problem described below:

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.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline void print(int n) {
  if (n == 0) {
    putchar('0');
    putchar('\n');
  } else if (n == -1) {
    putchar('-');
    putchar('1');
    putchar('\n');
  } else {
    char buf[11];
    buf[10] = '\n';
    int i = 9;
    while (n) {
      buf[i--] = n % 10 + '0';
      n /= 10;
    }
    while (buf[i] != '\n') putchar(buf[++i]);
  }
}
int read() {
  int cc = getc(stdin);
  for (; cc < '0' || cc > '9';) cc = getc(stdin);
  int ret = 0;
  for (; cc >= '0' && cc <= '9';) {
    ret = ret * 10 + cc - '0';
    cc = getc(stdin);
  }
  return ret;
}
long long power(long long num, long long g) {
  if (g == 0) return 1;
  if (g % 2 == 1) return (num * power((num * num), g / 2));
  return power((num * num), g / 2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n], c[n], d[n + 1];
    for (int i = 0; i < n; i++) cin >> a[i] >> c[i];
    int b[n + 1];
    memset(b, 0, sizeof(b));
    for (int i = 0; i < n; i++) b[a[i]]++;
    sort(b, b + n + 1);
    int ans = 0;
    int maximum = n;
    for (int i = n; i > 0; i--) {
      if (maximum <= 0) break;
      if (maximum < b[i]) {
        ans += maximum;
        maximum--;
      } else {
        ans += b[i];
        maximum = b[i] - 1;
      }
    }
    cout << ans << " ";
    memset(b, 0, sizeof(b));
    memset(d, 0, sizeof(d));
    for (int i = 0; i < n; i++) {
      b[a[i]]++;
      d[a[i]] += c[i];
    }
    priority_queue<int> pq;
    maximum = n;
    ans = 0;
    pair<int, int> pa[n + 1];
    for (int i = 0; i < n + 1; i++) pa[i] = make_pair(b[i], d[i]);
    sort(pa, pa + n + 1);
    for (int i = 0; i < n + 1; i++) b[i] = pa[i].first;
    for (int i = 0; i < n + 1; i++) d[i] = pa[i].second;
    for (int i = n; i > 0; i--) {
      if (maximum <= 0) continue;
      if (b[i] == 0 && pq.empty()) continue;
      if (pq.empty()) maximum = min(maximum, b[i]);
      while (maximum <= b[i]) {
        pq.push(d[i]);
        i--;
      }
      i++;
      if (!pq.empty()) {
        ans += min(maximum, pq.top());
        pq.pop();
      }
      maximum--;
    }
    cout << ans << endl;
  }
  return 0;
}

```