Help me in solving BLAST3 problem

My issue

what’s the problem in my code

My code

#include <iostream>
#include<map>
#include<algorithm>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	    int n;
	    string s;
	    cin>>n;
	    cin>>s;
	    int count=1;
	    int test=0;
	    map<char,int>m;
	    string st=s;
	    reverse(st.begin(),st.end());
	    if(s==st)
	    cout<<"yes"<<endl;
	    else{
	    sort(s.begin(),s.end());
	    
	    for(int i=0;i<n-1;i++){
	        if(s[i]==s[i+1]){
	            count++;
	        }
	        else{
	            m[s[i]]=count;
	            if(count%2!=0)
	            test++;
	            count=1;
	        }
	    }
	    if(s[n-1]!=s[n-2]){
	        m[s[n-1]]=1;
	        test++;
	    }
	    
	    if(n%2!=0){
	        if(test<=4)
	        cout<<"yes"<<endl;
	        else
	        cout<<"no"<<endl;
	    }
	    else{
	        if(test<=3)
	        cout<<"yes"<<endl;
	        else
	        cout<<"no"<<endl;
	    }
	    }
	    
	}
	return 0;
}

Problem Link: BLAST3 Problem - CodeChef

@abishekmadhav
can u explain your logic what were u thinking