Why is this code giving wrong answer?

why is this solution incorrect can someone tell?

include <bits/stdc++.h>
using namespace std;

void solve(){
int n;cin>>n;
vector a(n);for(int i=0;i<n;i++)cin>>a[i];

map<int,int> mp;
for(auto x : a)mp[x]++;

int ones=0,evens=0,three=0,grts3=0;
for(auto x : mp){
    if(x.second==1)ones++;
    if(x.second%2==0)evens++;
    if(x.second%2 && x.second==3)three++;
    if(x.second%2 && x.second>3)grts3++;
}

if(evens){
    cout<<ones+2+min(three+grts3,3)<<"\n";
}else{
    if(grts3){
        cout<<ones+2+min(three+grts3,3)<<"\n";
    }else{
        if(three)cout<<ones+3<<"\n";
        else cout<<ones<<"\n";
    }
}

}

int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);

int T;
cin >> T;

while (T--) {
    solve();
}

return 0;

}