#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int t;
  cin >> t;
  vector<int> vt(t);
  for (int i = 0; i < t; i++) {
    int n;
    cin >> n;
    map<int, int> m;
    int distinct = 0;
    int maxOcc = 0;
    for (int j = 0; j < n; j++) {
      int num;
      cin >> num;
      if (m.find(num) != m.end()) {
        m[num]++;
      } else {
        m[num] = 1;
        distinct++;
      }
      maxOcc = max(maxOcc, m[num]);
    }
    if (maxOcc - 1 > distinct) {
      vt[i] = distinct;
    } else if (maxOcc - 1 == distinct) {
      vt[i] = distinct;
    } else {
      if (distinct - maxOcc + 1 == 1) {
        vt[i] = maxOcc - 1;
      } else {
        vt[i] = maxOcc;
      }
    }
  }
  for (int i : vt) cout << i << "\n";
}
