#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
int cnt[N];
bool cmp(int a, int b) { return a > b; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int num = 0;
    for (int i = 0; i < n + 10; i++) cnt[i] = 0;
    int a;
    int maxn = 0;
    for (int i = 0; i < n; i++) {
      cin >> a;
      if (cnt[a] == 0) num++;
      cnt[a]++;
      maxn = max(maxn, cnt[a]);
    }
    if (maxn <= n / 2) {
      if (num > maxn)
        cout << maxn << endl;
      else if (num == maxn)
        cout << num - 1 << endl;
      else
        cout << num << endl;
    } else
      cout << min(n / 2, num) << endl;
  }
  return 0;
}
