#include <bits/stdc++.h>
using namespace std;
map<int, int> ma;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    ma.clear();
    for (int i = (1); i < (n + 1); i++) {
      int x;
      cin >> x;
      ma[x]++;
    }
    int minn = 0;
    for (auto i : ma) {
      minn = max(minn, i.second);
    }
    cout << max(min((int)ma.size() - 1, minn), min((int)ma.size(), minn - 1))
         << "\n";
  }
  return 0;
}
