Help me in solving MINRPC problem

My issue

please anyone check my code
as it shown only one test case as pass

My code

#include <iostream>
#include<bits/stdc++.h>

using namespace std;

int main() {
	// your code goes here
	int t;cin>>t;
	while(t--){ 
	    
	    int n;cin>>n;
	    string A;cin>>A;
	    
	    vector<char> ans(n,'P');
	    int ct =0;
	    int a= n/2 + 1;
	    for(int i=0; i<n && ct<=((n+2)/2); i++){
	        
	        if(A[i]=='R'){
	            ct++;
	        }
	    }
	    
	    for(int i=n-1; i>0 && ct<((n+2)/2); i--){
	       
	        
	        if(A[i] == 'S' && ct<((n+2)/2)){
	            ans[i]='R';
	            ct++;
	        }
	        
	         if(A[i]=='P'  && ct<((n+2)/2)){
	            ans[i]='S';
	            ct++;
	        }
	    }
	   //  for(int i=0; i<n && ct<((n+2)/2); i++){
	   //     if(A[i]=='P'){
	   //         ans[i]='S';
	   //         ct++;
	   //     }
	   // }
	    for(auto it:ans)cout<<it;
	    cout<<endl;
	    
	}
    //cout<<(-9)%19;
	return 0;
}

Problem Link: Rock-Paper-Scissors Practice Coding Problem - CodeChef

@abhaym96
here , plzz refer the following c++ code for debugging

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

int main() {
	int t;
	cin >> t;
	while(t--){
	    int n;
	    cin >> n;
	    string s;
	    cin >> s;
	    string ans;
	    int winreq = n/2;
	    winreq++;
	    
	    int pad = n - winreq;
	    
	    int index = 0;
	    while(pad > 0 && index < s.size()){
	        ans.push_back('P');
	        if(s[index] != 'R'){
	            pad--;
	        }
	        index++;
	    }
	    
	    for(;index<s.size();index++){
	        if(s[index] == 'R'){
	            ans.push_back('P');
	        }
	        else if(s[index] == 'S'){
	            ans.push_back('R');
	        }
	        else{
	            ans.push_back('S');
	        }
	    }
	    
	    cout << ans << endl;
	}
    return 0;
}