#include <bits/stdc++.h>
using namespace std;
long long int sum(long long int x) {
  long long int s = 0;
  while (x > 0) {
    s += x % 10;
    x = x / 10;
  }
  return s;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    map<int, int> mp;
    set<int> st;
    while (n--) {
      int x;
      cin >> x;
      st.insert(x);
      mp[x]++;
    }
    int dist = st.size();
    map<int, int>::iterator it;
    it = max_element((mp).begin(), (mp).end());
    int max = 0;
    for (it = mp.begin(); it != mp.end(); it++) {
      if (it->second >= max) max = it->second;
    }
    int ans;
    if (max > dist)
      ans = dist;
    else if (dist > max)
      ans = max;
    else
      ans = max - 1;
    cout << ans << "\n";
  }
}
