#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int a[N];
void solve() {
  int n;
  cin >> n;
  map<int, int> m;
  set<int> s;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    s.insert(x);
    m[x]++;
    ans = max(ans, m[x]);
  }
  int k = s.size();
  if (k == ans)
    cout << ans - 1;
  else
    cout << min(ans, k);
}
int main() {
  int t;
  cin >> t;
  while (t--) solve(), cout << endl;
}
