#include <bits/stdc++.h>
using namespace std;
int t, n, tmp, maks;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> t;
  while (t--) {
    cin >> n;
    set<int> s;
    map<int, int> m;
    vector<int> v;
    for (int i = 0; i < n; i++) {
      cin >> tmp;
      s.insert(tmp);
      if (m.count(tmp) == 0) {
        m[tmp] = 1;
        v.push_back(tmp);
      } else {
        m[tmp] = m[tmp] + 1;
      }
    }
    maks = INT_MIN;
    for (int i = 0; i < v.size(); i++) {
      if (m[v[i]] > maks) {
        maks = m[v[i]];
      }
    }
    int len = s.size();
    cout << max(min(len - 1, maks), min(maks - 1, len)) << "\n";
  }
  return 0;
}
