#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, x;
    cin >> n;
    set<long long> s;
    map<long long, long long> mp;
    long long mini = 0;
    for (long long i = 0; i < n; i++) {
      cin >> x;
      mp[x]++;
      s.insert(x);
      if (mp[x] > mini) mini = mp[x];
    }
    long long y = s.size();
    if (n == 1)
      cout << "0";
    else {
      if (y == mini)
        cout << y - 1;
      else
        cout << min(mini, y);
    }
    cout << endl;
  }
}
