#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int a[n];
    map<long long int, long long int> make_pair;
    long long int maxi = INT_MIN;
    for (long long int i = 0; i < n; i++) {
      cin >> a[i];
      make_pair[a[i]]++;
      maxi = max(maxi, make_pair[a[i]]);
    }
    if (n == 1) {
      cout << 0 << "\n";
    } else {
      long long int unique = make_pair.size() - 1;
      if (unique > maxi) {
        cout << maxi << "\n";
      } else if (unique < maxi) {
        if ((maxi - unique) <= 1) {
          cout << unique << "\n";
        } else {
          cout << unique + 1 << "\n";
        }
      } else {
        cout << unique << "\n";
      }
    }
  }
}
