#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int testCase = 1;
  cin >> testCase;
  while (testCase--) {
    int n = 0, t = 0, _max = 1;
    cin >> n;
    vector<int> A(n);
    vector<pair<int, int>> B(n);
    for (int& a : A) cin >> a;
    sort(A.begin(), A.end());
    B[t].first = A[0], B[t].second = 1;
    for (int i = 1; i < n; ++i) {
      if (A[i] == A[i - 1])
        B[t].second++, _max = max(_max, B[t].second);
      else
        B[++t].first = A[i], B[t].second = 1;
    }
    if (_max == 1)
      cout << min(1, t) << '\n';
    else
      cout << max(min(t, _max), min(t + 1, _max - 1)) << '\n';
  }
  return 0;
}
