#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> v;
    for (int i = 0; i < (n); i++) {
      int p;
      cin >> p;
      v.push_back(p);
    }
    sort(v.begin(), v.end());
    int multi = -1, distinct = 0;
    int temp = 1;
    for (int i = 1; i < n; i++) {
      if (v[i] == v[i - 1])
        temp++;
      else {
        multi = max(multi, temp);
        temp = 1;
        distinct++;
      }
    }
    multi = max(multi, temp);
    distinct++;
    if (distinct == multi)
      cout << distinct - 1 << "\n";
    else
      cout << min(distinct, multi) << "\n";
  }
}
