#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 1, mod = 1e9 + 7, inf = 2e9;
int n, a[N];
void solve() {
  cin >> n;
  map<int, int> cnt;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  int ans = 0;
  for (auto x : cnt) {
    int v = x.first, c = x.second;
    ans =
        max(ans, max(min((int)cnt.size() - 1, c), min((int)cnt.size(), c - 1)));
  }
  cout << ans << '\n';
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
