#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 i, n, x;
    cin >> n;
    vector<int> a(n);
    for (i = 0; i < n; ++i) {
      cin >> x;
      ++a[x - 1];
    }
    sort(a.begin(), a.end(), greater<int>());
    for (i = 0; i < n; ++i) {
      if (a[i] == 0) break;
    }
    if (a[0] == i)
      cout << i - 1 << "\n";
    else
      cout << min(i, a[0]) << "\n";
  }
}
