#include <bits/stdc++.h>
using namespace std;
int a[200010];
int main() {
  int N;
  cin >> N;
  while (N--) {
    int n, i;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
      scanf("%d", &a[i]);
    }
    sort(a, a + n);
    int ssame = 1, sdiff = 1, t = a[0], Msame = 1, locsame = 0;
    for (i = 1; i < n; i++) {
      if (a[i] != t)
        sdiff++, ssame = 1;
      else {
        ssame++;
        if (ssame > Msame) Msame = ssame, locsame = i;
      }
      t = a[i];
    }
    int tt = min(n / 2, min(Msame, sdiff));
    if (locsame)
      for (i = 0; i < tt; i++) a[locsame - i] = 0;
    for (i = 0; i < n; i++)
      if (a[i]) {
        t = a[i];
        break;
      }
    int sdif2 = 1;
    for (i++; i < n; i++) {
      if (a[i] && a[i] != t) sdif2++;
      t = a[i];
    }
    printf("%d\n", min(n / 2, min(Msame, sdif2)));
  }
  return 0;
}
