#include <bits/stdc++.h>
using namespace std;
int a[200003];
int resh() {
  int n, amax = 0, z = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) a[i] = 0;
  for (int i = 0; i < n; i++) {
    int t;
    scanf("%d", &t);
    if (a[t] == 0) z++;
    a[t]++;
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] > amax) amax = a[i];
  }
  if (z == 1 && n == 1) return 0;
  if (z == 1) return 1;
  if (amax < z) return amax;
  if (amax > z) return z;
  if (amax == z) return z - 1;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) cout << resh() << "\n";
  return 0;
}
