#include <bits/stdc++.h>
using namespace std;
long long N = 200005;
const int MOD = 998244353;
void solve() {
  int t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long arr[n];
    for (int i = 0; i < n; i++) cin >> arr[i];
    map<long long, long long> freq;
    for (int i = 0; i < n; i++) {
      freq[arr[i]]++;
    }
    long long f1 = 0;
    for (auto it = freq.begin(); it != freq.end(); ++it) {
      f1 = max(it->second, f1);
    }
    long long cnt = freq.size() - 1;
    if (n == 1) {
      cout << "0" << endl;
    } else if (cnt + 1 < f1) {
      cout << cnt + 1 << endl;
    } else {
      cout << min(f1, cnt) << endl;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
