#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    unordered_map<int, int> mp;
    int maxi = -1;
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      mp[x]++;
      maxi = max(maxi, mp[x]);
    }
    int others = (int)mp.size() - 1;
    if (n == 1) {
      cout << "0\n";
    } else if (maxi == 1) {
      cout << "1\n";
    } else {
      int ans = 0;
      if (maxi <= others)
        ans = maxi;
      else {
        if (maxi > others + 1)
          ans = others + 1;
        else if (maxi == others + 1) {
          ans = others;
        }
      }
      cout << ans << "\n";
    }
  }
}
