#include <bits/stdc++.h>
using namespace std;
void mego() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  mego();
  long long a, b = 0, c = 0, d, n, t;
  cin >> t;
  while (t--) {
    cin >> n;
    map<int, int> ma;
    while (n--) {
      cin >> a;
      ma[a]++;
    }
    int sz = ma.size(), mx = 0;
    for (auto it : ma) {
      if (it.second > sz - 1)
        mx = max(mx, min(sz, it.second - 1));
      else
        mx = max(mx, min(sz - 1, it.second));
    }
    cout << mx << "\n";
  }
  return 0;
}
