#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, p, i, ans = INT_MIN;
    cin >> n;
    map<long long, long long> m;
    set<long long> s;
    long long a[n];
    for (i = 0; i < n; i++) {
      cin >> a[i];
      m[a[i]]++;
      ans = max(ans, m[a[i]]);
    }
    for (i = 0; i < n; i++) s.insert(a[i]);
    long long mx = s.size();
    p = max(min(ans, mx - 1), min(ans - 1, mx));
    cout << p << "\n";
  }
}
