#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t t;
  int newx;
  cin >> t;
  while (t--) {
    int64_t n;
    cin >> n;
    if (n == 1) {
      cin >> newx;
      cout << "0"
           << "\n";
    } else {
      multiset<int64_t> x;
      vector<int64_t> x1;
      int64_t m;
      for (int64_t i = 0; i < n; i++) {
        cin >> m;
        x.insert(m);
        x1.push_back(m);
      }
      int64_t un = 0;
      int64_t sa = 0;
      int64_t countt = 0;
      for (int64_t i = 0; i < n; i++) {
        countt = x.count(x1[i]);
        sa = max(sa, countt);
        if (x.count(x1[i]) >= 1) {
          un++;
          x.erase(x1[i]);
        }
      }
      if (sa == un)
        cout << sa - 1 << "\n";
      else if (sa < un)
        cout << sa << "\n";
      else
        cout << un << "\n";
    }
  }
  return 0;
}
