Getting wrong answer even tho logic seems to be same

My code looks like it has the same logic as one of the submission which got all test cases approved. here’s the submitted code i am talking about
working code link
am i missing something here? please help me figure it out

my code:

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

int main() {
    int t;cin>>t;
    while(t--)
    {
        int n, req_wins, rem, index = 0;
        string s, ans;
        
        cin>>n;
        cin>>s;
        
        req_wins = n/2 + 1;
        rem = n;
        while(req_wins < rem && req_wins)
        {
            ans += "P";
            if(s[n-rem] == 'R')
                req_wins--;
            rem--;
        }
        while(req_wins)
        {
            switch(s[n-rem])
            {
                case 'R':
                    ans += "P";
                    break;
                case 'P':
                    ans += "S";
                    break;
                case 'S':
                    ans += "R";
                    break;
            }
            
            rem--;
            req_wins--;
        }
        

        cout<<ans<<endl;
    }
}