#include <bits/stdc++.h>
using namespace std;
int t, n;
int a[200000];
int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    int same = 0, dis = 0;
    int i = 0;
    while (i < n) {
      int j = i + 1;
      while (j < n && a[j] == a[i]) j++;
      same = max(same, j - i);
      dis++;
      i = j;
    }
    cout << max(min(same - 1, dis), min(same, dis - 1)) << "\n";
  }
  return 0;
}
