#include <bits/stdc++.h>
using namespace std;
int main() {
  int testcases;
  cin >> testcases;
  while (testcases--) {
    int n;
    cin >> n;
    int distinct = 0;
    int repeated = 0;
    unordered_map<int, int> values;
    for (int i = 0; i < n; i++) {
      int input;
      cin >> input;
      if (values[input] == 0) {
        distinct++;
      }
      values[input]++;
      repeated = max(repeated, values[input]);
    }
    int answer = min(distinct, repeated);
    if (distinct == repeated) {
      answer -= 1;
    }
    cout << answer << endl;
    values.clear();
  }
  return 0;
}
