#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, n, a, b, i, same, unique, ans;
  cin >> t;
  while (t--) {
    cin >> n;
    same = 0;
    unique = 0;
    unordered_map<long long, long long> m;
    for (i = 0; i < n; i++) {
      cin >> a;
      m[a]++;
      if (m[a] == 1) {
        unique++;
      }
      same = max(same, m[a]);
    }
    if (same < unique + 1) unique--;
    ans = min(same, unique);
    cout << ans << endl;
  }
  return 0;
}
