#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using pcc = pair<char, char>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<ll>;
using vpii = vector<pii>;
using vc = vector<char>;
using vd = vector<double>;
int main(int argc, char *argv[]) {
  int testcase, cs = 1;
  scanf("%d%*c", &(testcase));
  while (testcase--) {
    int n, cnt[200100]{0}, ara[200100], i, j, ans;
    set<int> s;
    scanf("%d%*c", &(n));
    for (int i = (0); i < (n); i++) {
      scanf("%d%*c", &(ara[i]));
      s.insert(ara[i]);
      cnt[ara[i]]++;
    }
    ans = 0;
    {
      for (i = 1; i <= n; i++) {
        int x = s.size();
        if (cnt[i] > x) {
          ans = max(ans, x);
        } else if (cnt[i] == x)
          ans = max(ans, cnt[i] - 1);
        else {
          ans = max(ans, cnt[i]);
        }
      }
      printf("%d", (ans)), printf("\n");
    }
  }
  return 0;
}
