#include <bits/stdc++.h>
using namespace std;
bool isPrime(int n) {
  if (n <= 1) {
    return false;
  }
  long long c[100];
  c[0] = 1;
  for (int i = 0; i < n; c[0] = -c[0], i++) {
    c[1 + i] = 1;
    for (int j = i; j > 0; j--) c[j] = c[j - 1] - c[j];
  }
  c[0]++, c[n]--;
  int i = n;
  while (i-- && c[i] % n == 0)
    ;
  return i < 0;
}
int GCD(int a, int b) {
  if (b == 0) return a;
  return GCD(b, a % b);
}
int MostCommonInt(vector<int> v) {
  int max = 0, mostvalue = v[0];
  for (int i = 0; i < v.size(); i++) {
    int co = (int)count(v.begin(), v.end(), v[i]);
    if (co > max) {
      max = co;
      mostvalue = v[i];
    }
  }
  return mostvalue;
}
void solve() {
  int n;
  cin >> n;
  map<int, int> MAP;
  for (int i = 0; i < n; i++) {
    int a = 0;
    cin >> a;
    MAP[a] += 1;
  }
  map<int, int>::iterator it = MAP.begin();
  vector<int> v;
  for (it = MAP.begin(); it != MAP.end(); it++) {
    int num = (*it).second;
    bool b = false;
    while (num > 0 && b == false) {
      if (count(v.begin(), v.end(), num) == 0) {
        v.push_back(num);
        b = true;
      } else {
        num -= 1;
      }
    }
  }
  long long sum = 0;
  for (int i = 0; i < v.size(); i++) {
    sum += v[i];
  }
  cout << sum << endl;
}
int main() {
  int T;
  cin >> T;
  for (int i = 0; i < T; i++) {
    solve();
  }
}
