#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    int arr[200001] = {0};
    int y = -1, x = 0, i, m;
    cin >> n;
    for (i = 0; i < n; i++) {
      cin >> m;
      arr[m]++;
      if (arr[m] == 1) x++;
      y = max(arr[m], y);
    }
    cout << max(min(x, y - 1), min(x - 1, y)) << endl;
  }
}
