#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  scanf("%lld", &t);
  while (t--) {
    long long n;
    scanf("%lld", &n);
    long long a[n + 5];
    map<long long, long long> make_pair;
    long long mx = 0, cnt = 0;
    for (long long i = 0; i < n; i++) {
      scanf("%lld", &a[i]);
      make_pair[a[i]]++;
      mx = max(mx, make_pair[a[i]]);
      if (make_pair[a[i]] == 1) {
        cnt++;
      }
    }
    if (cnt == mx) {
      cout << cnt - 1 << "\n";
      continue;
    } else if (cnt < mx) {
      cout << cnt << "\n";
      continue;
    } else if (cnt > mx) {
      cout << mx << "\n";
      continue;
    }
  }
}
