#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    map<int, int> m;
    int mx = 0;
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
      m[a[i]]++;
      mx = max(m[a[i]], mx);
    }
    vector<int> first, second;
    bool f = 0;
    for (auto i : m) {
      if (i.second == mx && !f) {
        for (int j = 0; j < mx; ++j) second.push_back(i.first);
        f = 1;
        continue;
      }
      first.push_back(i.first);
    }
    if (second.size() > first.size()) {
      first.push_back(second[0]);
      second.pop_back();
    }
    cout << min(first.size(), second.size()) << '\n';
  }
  return 0;
}
