#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > A;
bool cmp(pair<int, int>& a, pair<int, int>& b) { return a.second < b.second; }
void sort(map<int, int>& M) {
  for (auto& it : M) {
    A.push_back(it);
  }
  sort(A.begin(), A.end(), cmp);
}
void solve() {
  int n;
  cin >> n;
  int arr[n];
  map<int, int> m;
  set<int> s;
  A.clear();
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    m[arr[i]]++;
    s.insert(arr[i]);
  }
  sort(m);
  for (auto it = A.rbegin(); it != A.rend(); it++) {
    int z = it->second;
    if (z == s.size()) {
      cout << z - 1 << "\n";
      return;
    } else if (z > s.size()) {
      cout << s.size() << "\n";
      return;
    } else {
      cout << z << "\n";
      return;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
