#include<bits/stdc++.h>

using namespace std;

int main() {
    int t;
    long int i, n,count=0;
    string s;
    
    cin>>t;
    
    while(t--){
        cin >> n;
        cin >> s;
        if(n==2)
        cout << "2" << endl;
        else if(n==3){
            if(s[0]==s[1]){
                cout <<"2"<<endl;
            }
            else{
                cout << "1" <<endl;
            }
        }
        else
        if(n%2!=0){
        for(i=(n-3)/2;i>=0;i--){
            while(s[i]==s[(n-1)/2])
                count++;
        }    
        cout << count*2+1<<endl;
        }
        else{
            for(i=n/2;i++;i<n){
                while(s[i]=s[n/2]){
                    count++;
               
            }
            cout << count*2<<endl;
        }
    }
    }
    
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: