#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    map<int, int> m;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      m[a[i]]++;
    }
    multiset<int> s;
    map<int, int>::iterator it = m.begin();
    for (; it != m.end(); it++) {
      s.insert((it->second));
    }
    int f = 0, f1 = 0;
    multiset<int>::iterator itr = (--(s.end()));
    int x = s.size();
    int y = (*itr);
    while (1) {
      if (x - 1 >= (y)) {
        f1 = 1;
        cout << y << "\n";
        break;
      }
      if (f == 0 && x - 1 < y) {
        x++;
        y--;
        f = 1;
      } else if (f == 1 && x - 1 < y) {
        y--;
      }
      if (y == 0) break;
    }
    if (f1 == 0) cout << y << "\n";
  }
}
