#include <bits/stdc++.h>
using namespace std;
int min(int x, int y) {
  if (x >= y) return y;
  return x;
}
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> v;
    int x;
    for (int i = 0; i < n; i++) {
      cin >> x;
      v.push_back(x);
    }
    sort(v.begin(), v.end());
    int ss = 1;
    int mss = 1;
    int diff = 1;
    for (int i = 1; i < n; i++) {
      if (v[i] == v[i - 1]) {
        ss++;
      } else {
        if (ss > mss) {
          mss = ss;
        }
        ss = 1;
        diff++;
      }
    }
    if (ss > mss) {
      mss = ss;
    }
    diff--;
    if (mss <= diff + 1)
      cout << min(mss, diff) << "\n";
    else
      cout << diff + 1 << "\n";
  }
}
