#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, dis = 0, maxn = 0;
    cin >> n;
    int a[n + 1], con[n + 1];
    bool s[n + 1];
    for (int i = 0; i < n + 1; i += 1) {
      con[i] = 0;
    }
    for (int i = 0; i < n; i += 1) {
      cin >> a[i];
      if (!con[a[i]]) {
        dis++;
      }
      con[a[i]]++;
      if (maxn < con[a[i]]) maxn = con[a[i]];
    }
    if (maxn > dis)
      cout << dis << "\n";
    else if (maxn == dis)
      cout << maxn - 1 << "\n";
    else
      cout << maxn << "\n";
  }
}
