#include <bits/stdc++.h>
using namespace std;
void cinn(int &number) {
  bool negative = false;
  register int c;
  number = 0;
  c = getchar();
  if (c == '-') {
    negative = true;
    c = getchar();
  }
  for (; (c > 47 && c < 58); c = getchar()) number = number * 10 + c - 48;
  if (negative) number *= -1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      mp[a[i]]++;
    }
    int d = mp.size();
    int u = 0;
    for (auto it = mp.begin(); it != mp.end(); it++) {
      u = max(u, it->second);
    }
    if (d == u) {
      cout << d - 1 << "\n";
      ;
    } else if (d > u) {
      cout << u << "\n";
      ;
    } else {
      cout << d << "\n";
      ;
    }
  }
  return 0;
}
