#include <bits/stdc++.h>
using namespace std;
void fun() {
  int n, i, x;
  cin >> n;
  int A[1000000] = {0};
  int k = n;
  while (k > 0) {
    cin >> x;
    A[x]++;
    k--;
  }
  int mx = 0, fr = 0;
  for (int i = 1; i <= n; i++) {
    if (A[i] > mx) mx = A[i];
  }
  for (int i = 1; i <= n; i++) {
    if (A[i] > 0) fr++;
  }
  fr--;
  if (fr > mx)
    cout << mx;
  else if ((mx - fr) > 1)
    cout << fr + 1;
  else
    cout << fr;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  cin >> t;
  while (t--) {
    fun();
    cout << "\n";
  }
}
