#include <bits/stdc++.h>
using namespace std;
long long int T = 1, inf = 10000000000;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> T;
  while (T--) {
    long long int n, sz = 3, ans = 0, blag = 0, u, mn, ev = 0, mx, mini, i, v,
                     q, p, j, k, w, h, l, m, x, y, od = 0, total = 0, cc = 0,
                     pp = 0, flag = 0, klag = 0, sum = 0;
    string s, s3, s1 = "YES", s2 = "NO";
    bool ok = 0;
    cin >> n;
    vector<long long int> a;
    vector<pair<long long int, long long int>> b;
    for (i = 1; i <= n; i += 1) {
      b.push_back({0, i});
    }
    for (i = 0; i <= n - 1; i += 1) {
      cin >> x;
      a.push_back(x);
      b[x - 1].first++;
    }
    sort(b.rbegin(), b.rend());
    for (i = 1; i <= n - 1; i += 1) {
      if (b[i].first == 0) {
        cc = i - 1;
        break;
      }
      if (i == n - 1 && b[i].first != 0) {
        cc = i;
      }
    }
    if (b[0].first == cc)
      cout << cc << "\n";
    else if (b[0].first > cc)
      cout << min(b[0].first - 1, cc + 1) << "\n";
    else
      cout << b[0].first << "\n";
  }
  return 0;
}
