#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> a(n);
    for (long long i = 0; i < (long long)n; i++) cin >> a[i];
    if (n == 1) {
      cout << "0\n";
      continue;
    }
    int u = 1, s = 0, temp = 0;
    sort(a.begin(), a.end());
    for (long long i = 1; i < (long long)n; i++) {
      if (a[i] != a[i - 1]) {
        ++u;
        s = s > temp ? s : temp;
        temp = 0;
      } else
        temp = temp == 0 ? 2 : temp + 1;
    }
    s = s > temp ? s : temp;
    u = s > 0 ? u - 1 : u;
    if (u >= s) {
      if (s)
        cout << s << endl;
      else
        cout << "1\n";
    } else {
      if (s - u > 1)
        cout << u + 1 << endl;
      else
        cout << u << endl;
    }
  }
  return 0;
}
