#include <bits/stdc++.h>
using namespace std;
long long sm(long long x) { return (x * (x + 1)) / 2; }
bool cp(long long i, long long j) { return i > j; }
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> v(n, 0);
    for (long long i = 0; i < n; i = i + 1) cin >> v[i];
    sort(v.begin(), v.end());
    long long x = 1, mx = 0, c = 1, p = v[0];
    vector<long long> a;
    for (long long i = 1; i < n; i = i + 1) {
      if (v[i] != p) {
        p = v[i];
        x++;
        a.push_back(c);
        mx = max(c, mx);
        c = 1;
      } else {
        c++;
      }
    }
    mx = max(c, mx);
    cout << max(min(x - 1, mx), min(x, mx - 1)) << endl;
    ;
  }
}
