#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    map<long long, long long> mp;
    long long n, i, maxdiff, maxsame;
    cin >> n;
    long long a[n];
    for (i = 0; i < n; i++) {
      cin >> a[i];
      mp[a[i]]++;
    }
    maxdiff = mp.size();
    for (auto it : mp) {
      if (it.second > mp[maxsame]) maxsame = it.first;
    }
    if (maxdiff > mp[maxsame]) {
      cout << min(mp[maxsame], maxdiff - 1);
    } else if (maxdiff == mp[maxsame]) {
      cout << maxdiff - 1;
    } else {
      cout << min(mp[maxsame] - 1, maxdiff);
    }
    cout << "\n";
  }
}
