#include <bits/stdc++.h>
using namespace std;
char _;
typedef priority_queue<pair<long long, long long>,
                       vector<pair<long long, long long>>,
                       greater<pair<long long, long long>>>
    PQ;
long long gcf(long long a, long long b) { return b == 0 ? a : gcf(b, a % b); }
long long lcm(long long a, long long b) { return a * b / gcf(a, b); }
long long fpow(long long b, long long exp, long long mod) {
  if (exp == 0) return 1;
  long long t = fpow(b, exp / 2, mod);
  if (exp & 1) return t * t % mod * b % mod;
  return t * t % mod;
}
long long divmod(long long i, long long j, long long mod) {
  i %= mod, j %= mod;
  return i * fpow(j, mod - 2, mod) % mod;
}
int arr[200009];
int temp[200009];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int c = 0;
    for (int i = 0; i < n; i++) {
      int a;
      cin >> a;
      temp[i] = a;
      if (arr[a] == 0) {
        c++;
      }
      arr[a]++;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      int x = temp[i];
      ans = max(ans, min(c, arr[x] - 1));
      ans = max(ans, min(c - 1, arr[x]));
      arr[x] = 0;
    }
    cout << ans << "\n";
  }
}
