#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      mp[a[i]]++;
    }
    int mx = 0, p = 0;
    for (auto it = mp.begin(); it != mp.end(); it++) {
      mx = max(mx, it->second);
      p++;
    }
    cout << max(min(mx, p - 1), min(mx - 1, p)) << endl;
  }
  return 0;
}
