#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[N], cntt[N];
int vis[N], num;
int n;
void clear() {
  for (int i = 1; i <= n; ++i) {
    cntt[a[i]] = 0;
    vis[a[i]] = 0;
    num = 0;
  }
}
int main() {
  ios::sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    int maxcnt = 0;
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
      ++cntt[a[i]];
      if (cntt[a[i]] > maxcnt) {
        maxcnt = cntt[a[i]];
      }
      if (!vis[a[i]]) {
        vis[a[i]] = 1;
        ++num;
      }
    }
    if (n == 1) {
      cout << 0 << endl;
      clear();
      continue;
    }
    int ans;
    if (num > maxcnt) {
      ans = maxcnt;
    } else if (num == maxcnt) {
      ans = num - 1;
    } else {
      ans = num;
    }
    cout << ans << endl;
    clear();
  }
}
