#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  int t, n, i;
  cin >> t;
  while (t--) {
    cin >> n;
    int a[n];
    map<int, int> m;
    for (i = 0; i < n; i++) {
      cin >> a[i];
      m[a[i]]++;
    }
    sort(a, a + n);
    int ans = 0;
    if (n == 1)
      ans = 0;
    else {
      int min = INT_MIN, k;
      for (auto itr = m.begin(); itr != m.end(); itr++) {
        if (min < itr->second) {
          min = itr->second;
          k = itr->first;
        }
      }
      if (min == 1) {
        ans = 1;
      } else if ((min - 1) == m.size()) {
        ans = min - 1;
      } else if ((min) == m.size()) {
        ans = min - 1;
      } else if (min < (m.size())) {
        ans = min;
      } else if (min > (m.size())) {
        ans = m.size();
      }
    }
    cout << ans << endl;
  }
  return 0;
}
