#include <bits/stdc++.h>
using namespace std;
int main() {
  map<int, int> v;
  int q;
  cin >> q;
  vector<int> ans;
  for (int i = 0; i < q; i++) {
    int n;
    cin >> n;
    v.clear();
    for (int j = 0; j < n; j++) {
      int x;
      cin >> x;
      auto p = v.begin();
      if ((p = v.find(x)) == v.end()) {
        v.insert(make_pair(x, 1));
      } else {
        p->second++;
      }
    }
    vector<int> m;
    m.clear();
    for (auto p = v.begin(); p != v.end(); p++) {
      m.push_back(p->second);
    }
    sort(m.begin(), m.end());
    int s = m[m.size() - 1];
    for (int j = m.size() - 2; j >= 0; j--) {
      while (m[j] > 0 && m[j] >= m[j + 1]) {
        m[j]--;
      }
      s += m[j];
    }
    ans.push_back(s);
  }
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
