#include <bits/stdc++.h>
using namespace std;
int t, n, x;
map<int, int> mp;
int main() {
  {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> x;
      mp[x]++;
    }
    int cnt = 0, k = 0;
    for (int i = 1; i <= n; i++) {
      if (mp[i]) {
        cnt++;
      }
      k = max(mp[i], k);
    }
    if (cnt > k) {
      cout << k << endl;
    } else {
      cout << min(k - 1, cnt) << endl;
    }
    mp.clear();
  }
  return 0;
}
