#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long t, n, x, max_val, l, r;
set<long long> s;
vector<long long> v;
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  cin >> t;
  while (t--) {
    cin >> n;
    map<long long, long long> mp;
    for (int i = 0; i < n; i++)
      cin >> x, s.insert(x), mp[x]++, max_val = max(max_val, mp[x]);
    int ans = max(min((long long)s.size() - 1, max_val),
                  min((long long)s.size(), max_val - 1));
    cout << ans << endl;
    max_val = 0;
    s.clear();
  }
}
