#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    map<int, int> v;
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      v[x]++;
    }
    vector<int> a;
    for (auto x : v) a.push_back(x.second);
    sort(a.begin(), a.end(), greater<int>());
    int c = 0;
    for (int i = 0; i < (int)a.size(); i++) {
      if (i == 0)
        c += a[i];
      else if (a[i - 1] == 0)
        break;
      else {
        if (a[i] < a[i - 1]) {
          c += a[i];
        } else {
          c += (a[i - 1] - 1);
          a[i] = a[i - 1] - 1;
        }
      }
    }
    cout << c << endl;
  }
  return 0;
}
