#include <bits/stdc++.h>
using namespace std;
int main() {
  long q;
  cin >> q;
  while (q--) {
    long n;
    cin >> n;
    map<long, long> m;
    set<long> s;
    for (long i = 0; i < n; i++) {
      long x;
      cin >> x;
      m[x]++;
    }
    for (auto it = m.begin(); it != m.end(); it++) {
      long x = it->second;
      while (s.find(x) != s.end() && x > 0) x--;
      s.insert(x);
    }
    long sum = 0;
    for (auto it = s.begin(); it != s.end(); it++) sum += (*it);
    cout << sum << endl;
  }
  return 0;
}
