#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, i, n, j, distinct, same, maxsame, p;
  cin >> t;
  for (i = 0; i < t; i++) {
    cin >> n;
    int *lst = (int *)malloc(n * sizeof(int));
    for (j = 0; j < n; j++) cin >> lst[j];
    sort(lst, lst + n);
    maxsame = 1;
    distinct = 1;
    p = lst[0];
    j = 1;
    same = 1;
    while (j < n) {
      if (lst[j] == p) {
        same++;
        j++;
      } else {
        p = lst[j];
        same = 1;
        distinct++;
        j++;
      }
      if (same > maxsame) maxsame = same;
    }
    if (maxsame > distinct)
      cout << distinct << endl;
    else if (distinct > maxsame)
      cout << maxsame << endl;
    else
      cout << maxsame - 1 << endl;
    free(lst);
  }
  return 0;
}
