#include <bits/stdc++.h>
using namespace std;
int64_t mini(int64_t a, int64_t b) {
  if (a < b)
    return a;
  else
    return b;
}
int64_t maxi(int64_t a, int64_t b) {
  if (a > b) return a;
  return b;
}
signed main(void) {
  int64_t t;
  cin >> t;
  while (t--) {
    int64_t n, a, b;
    cin >> n;
    map<int64_t, int64_t> mp;
    int64_t x;
    for (int64_t i = 0; i < n; i++) {
      cin >> x;
      mp[x]++;
    }
    int64_t size = mp.size();
    int64_t ans = 0;
    for (auto m : mp) {
      int64_t poss = maxi(mini(m.second, size - 1), mini(m.second - 1, size));
      if (ans < poss) ans = poss;
    }
    cout << ans << endl;
  }
}
