#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int vis[n + 2];
    memset(vis, 0, sizeof(vis));
    set<int> same;
    set<int> diff;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
      cin >> v[i];
      vis[v[i]]++;
    }
    for (int i = 1; i <= n; i++) {
      if (vis[i] >= 1) diff.insert(i);
      if (vis[i] >= 1) same.insert(vis[i]);
    }
    int d = 0, s = 0;
    d = diff.size();
    int ans = 0;
    set<int>::reverse_iterator it;
    int flag = 0;
    for (it = same.rbegin(); it != same.rend(); it++) {
      int p = *it;
      int r = p;
      if (r > d) {
        ans = max(ans, d);
      }
      if (d > r) ans = max(ans, r);
      if (d == r) {
        ans = max(ans, r - 1);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
