#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n, mx = 0;
    cin >> n;
    long long a[n];
    map<long long, long long> M;
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
      M[a[i]]++;
      mx = max(mx, M[a[i]]);
    }
    cout << min(n / 2, max(min(mx, (long long)M.size() - 1),
                           min(mx - 1, (long long)M.size())))
         << "\n";
  }
  return 0;
}
