#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  long long q;
  cin >> q;
  vector<long long> ans;
  while (q--) {
    long long n;
    cin >> n;
    long long a, b[n + 1];
    memset(b, 0, sizeof(b));
    for (int i = 0; i < n; i++) {
      cin >> a;
      b[a]++;
    }
    multiset<long long> s;
    for (int i = 1; i <= n; i++) {
      if (b[i]) s.insert(b[i]);
    }
    long long c = s.size() - 1, d = *(--s.end());
    if (d <= c) {
      ans.push_back(d);
    } else {
      ans.push_back(min(c + 1, d - 1));
    }
  }
  for (auto& i : ans) cout << i << endl;
  return 0;
}
