#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  int64_t t = 1, n, i, j;
  cin >> t;
  while (t--) {
    cin >> n;
    int64_t a[n];
    int64_t mxval = -1;
    int64_t mxcount = 0;
    map<int64_t, int64_t> mp;
    for (i = 0; i < n; i++) {
      cin >> a[i];
      mp[a[i]]++;
      if (mp[a[i]] > mxcount) {
        mxcount = mp[a[i]];
        mxval = a[i];
      }
    }
    int64_t largestcount = mxcount;
    int64_t remsetsize = mp.size() - 1;
    cout << max(min(remsetsize, largestcount),
                min(remsetsize + 1, largestcount - 1))
         << "\n";
  }
  return 0;
}
