#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[200007] = {};
    int freq[200007] = {};
    int max_element = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      max_element = max(max_element, a[i]);
      freq[a[i]]++;
    }
    int maxf = 0;
    int cnt = 0;
    for (int i = 0; i <= max_element; i++) {
      if (freq[i] != 0) cnt++;
      maxf = max(freq[i], maxf);
    }
    cnt--;
    int ans = 0;
    if (cnt == maxf) {
      ans = maxf;
    } else if (cnt > maxf) {
      ans = maxf;
    } else if (cnt < maxf) {
      int dif = maxf - cnt;
      if (dif == 1)
        ans = cnt;
      else
        ans = cnt + 1;
    }
    cout << ans << endl;
  }
  return 0;
}
