#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int& i : v) cin >> i;
    vector<int> oc(n + 1, 0);
    for (int i : v) oc[i]++;
    int ma = 0, val;
    for (int i = 1; i <= n; i++)
      if (oc[i] > ma) ma = oc[i], val = i;
    int d = 0;
    for (int i = 1; i <= n; i++)
      if (i != val and oc[i]) d++;
    int ans = 0;
    for (int i = 1; i <= ma; i++) {
      int outro = d;
      if (i < ma) outro++;
      ans = max(ans, min(i, outro));
    }
    cout << ans << '\n';
  }
  exit(0);
}
