#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007, MAX = 2000000007, MAXN = 100005;
int f[2 * MAXN], a[2 * MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 0; i <= n; i++) f[i] = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      f[a[i]]++;
    }
    int distinct = 0, maxval = 0;
    for (int i = 1; i <= n; i++) {
      if (f[i] > 0) {
        distinct++;
        maxval = max(maxval, f[i]);
      }
    }
    cout << max(min(distinct, maxval - 1), min(distinct - 1, maxval)) << '\n';
  }
  return 0;
}
