#include <bits/stdc++.h>
using namespace std;
long long n, q, k, a, b, s[200005];
int main() {
  cin >> q;
  while (q--) {
    long long sum = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> a;
      s[a]++;
    }
    sort(s + 1, s + 1 + n);
    sum = s[n];
    for (int i = n - 1; i >= 1; i--) {
      if (s[i] < s[i + 1])
        sum += s[i];
      else {
        s[i] = s[i + 1] - 1;
        if (s[i] > 0) sum += s[i];
      }
    }
    for (int i = 1; i <= n; i++) s[i] = 0;
    cout << sum << endl;
  }
  return 0;
}
