#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  map<long long, long long> as;
  for (long long i = 0, i_len = (n); i < i_len; i++) {
    long long tmp;
    cin >> tmp;
    as[tmp]++;
  }
  set<pair<long long, long long>> rev;
  for (auto x : as) rev.insert(make_pair(x.second, x.first));
  long long low = 0, high = n + 1;
  while ((low + 1) < high) {
    long long mid = (low + high) / 2;
    pair<long long, long long> rv = *rev.rbegin();
    if (rv.first < mid) {
      high = mid;
      continue;
    }
    if (rv.first == mid) {
      if ((((long long)(rev).size()) - 1) < mid) {
        high = mid;
        continue;
      }
    } else {
      if (((long long)(rev).size()) < mid) {
        high = mid;
        continue;
      }
    }
    low = mid;
  }
  cout << low << "\n";
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long t;
  cin >> t;
  for (long long i = 0, i_len = (t); i < i_len; i++) solve();
  return 0;
}
