#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  set<int> s;
  map<int, int> mp;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    mp[x]++;
    s.insert(x);
  }
  int si = int(s.size()) - 1;
  int ans = 0;
  for (auto it : mp) {
    int curr = min(it.second, si);
    if (it.second > curr + 1) curr++;
    ans = max(ans, curr);
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int t = 1;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
