#include <bits/stdc++.h>
using namespace std;
void speed() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
}
void solve() {
  long long int n;
  cin >> n;
  long long int a[n];
  for (long long int i = 0; i < n; ++i) cin >> a[i];
  sort(a, a + n);
  long long int s = 0, d = 0;
  for (long long int i = 0; i < n - 1; ++i) {
    if (a[i] == a[i + 1]) {
      long long int t = 2, j = i + 1;
      while (j < n && a[j] == a[j + 1]) {
        ++j;
        ++t;
      }
      s = max(s, t);
      i = j - 1;
    } else
      ++d;
  }
  if (s == 0) {
    ++s;
    cout << min(s, d);
    return;
  }
  if ((s - d) >= 2) {
    --s;
    ++d;
  }
  cout << min(s, d);
}
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    solve();
    cout << endl;
  }
}
