#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t{0}, n{0}, temp{0};
  cin >> t;
  while (t--) {
    long long diff_frequencies{0};
    long long extra_player{0};
    cin >> n;
    map<long long, long long> frequencies;
    for (long long i{0}; i < n; ++i) {
      cin >> temp;
      frequencies[temp]++;
      if (frequencies[temp] == 1) {
        diff_frequencies++;
      }
    }
    long long highest_skill{0};
    long long its_frequecy{0};
    for (auto i : frequencies) {
      if (i.second > its_frequecy) {
        its_frequecy = i.second;
        highest_skill = i.first;
      }
    }
    if (its_frequecy > n / 2) {
      its_frequecy = n / 2;
      extra_player = 1;
    }
    diff_frequencies--;
    if (extra_player == 1) {
      diff_frequencies++;
      if (diff_frequencies > its_frequecy) {
        cout << its_frequecy;
      } else {
        cout << diff_frequencies;
      }
    } else {
      if (diff_frequencies >= its_frequecy) {
        cout << its_frequecy;
      } else {
        its_frequecy--;
        diff_frequencies++;
        if (diff_frequencies > its_frequecy) {
          cout << its_frequecy;
        } else {
          cout << diff_frequencies;
        }
      }
    }
    if (t > 0) cout << "\n";
  }
  return 0;
}
