#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
void test() {
  long long n;
  cin >> n;
  long long a[n];
  map<long long, long long> m;
  vector<long long> v;
  for (long long i = 0; i < n; i++) cin >> a[i], m[a[i]]++;
  map<long long, long long>::iterator ir;
  for (ir = m.begin(); ir != m.end(); ir++) v.push_back(ir->second);
  sort(v.begin(), v.end());
  long long k = v.size() - 1;
  if (k == 0)
    cout << v[0] << endl;
  else {
    long long sum = v[k];
    for (long long i = k - 1; i >= 0; i--) {
      if (v[i] >= v[i + 1]) {
        v[i] = v[i + 1] - 1;
        sum += max(0ll, v[i]);
      } else
        sum += max(0ll, v[i]);
    }
    cout << sum << endl;
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) {
    test();
  }
  return 0;
}
