#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a;
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      a.push_back(x);
    }
    sort(a.begin(), a.end());
    a.push_back(-100);
    vector<int> counter;
    int count = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] != a[i + 1]) {
        count++;
        counter.push_back(count);
        count = 0;
      } else {
        count++;
      }
    }
    sort(counter.begin(), counter.end(), greater<int>());
    int n_distinct = counter.size();
    int n_max = counter[0];
    int candidate1 = min(n_max, n_distinct - 1);
    int candidate2 = min(n_max - 1, n_distinct);
    cout << max(candidate2, candidate1) << endl;
  }
}
