#include <bits/stdc++.h>
using namespace std;
int a[200002];
int main() {
  int q;
  cin >> q;
  while (q--) {
    map<int, int> m;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      m[a[i]] += 1;
    }
    int res = 0, mx = 0, mn = m.size();
    for (auto x : m) mx = max(mx, x.second);
    res = max(min(mx - 1, mn), min(mx, mn - 1));
    cout << res << "\n";
  }
  return 0;
}
