#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, j, k, m, n, a, b, c, q, t, r, sum, num, ans, ind;
  cin >> t;
  while (t--) {
    cin >> n;
    map<long long, long long> mp;
    for (long long(i) = (0); (i) < (n); ++(i)) {
      cin >> k;
      mp[k]++;
    }
    if (n == 1) {
      cout << "0\n";
      continue;
    }
    sum = 0;
    long long ii = 0;
    for (auto it = mp.begin(); it != mp.end(); it++) {
      if (it->second == 1)
        sum++;
      else
        ii++;
    }
    ans = 0;
    for (auto it = mp.begin(); it != mp.end(); it++) {
      if (it->second > 1) {
        if (it->second <= ii + sum - 1) {
          ans = max(ans, it->second);
        } else {
          ans = max(ans, min(ii + 1 + sum - 1, it->second - 1));
        }
      }
    }
    if (ans == 0) ans++;
    cout << ans << "\n";
  }
}
