#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> v, m;
    for (int i = 0; i < n; i++) {
      int c;
      cin >> c;
      v.push_back(c);
    }
    sort(v.begin(), v.end());
    int i = 1;
    for (int j = 0; j < n - 1; j++) {
      if (v[j] == v[j + 1]) {
        i++;
      } else {
        m.push_back(i);
        i = 1;
      }
    }
    m.push_back(i);
    sort(m.begin(), m.end());
    int k = m.size();
    {
      if (k > m[k - 1])
        cout << m[k - 1] << endl;
      else if (m[k - 1] > k)
        cout << k << endl;
      else if (k == m[k - 1])
        cout << k - 1 << endl;
    }
  }
}
