#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 100;
const long long mod = 998244353;
int a[maxn], vis[maxn];
int main() {
  ios::sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    int n, Max = 0, num = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) vis[i] = 0;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      if (!vis[a[i]]) num++;
      vis[a[i]]++;
      Max = max(Max, vis[a[i]]);
    }
    cout << max(min(Max, num - 1), min(num, Max - 1)) << endl;
  }
}
