Problem: 2049B - pspspsps
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
// بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيمِ

// In the name of Allah.

/*

    \        /      /\     ----------    /\       |\    |

     \      /      /  \        |        /  \      | \   |

      \    /      /----\       |       /----\     |  \  |

       \  /      /      \      |      /      \    |   \ |

        \/      /        \     |     /        \   |    \|

        

⠀⠀⠀⠀⠀⢀⣾⠿⢷⣤⣄⣀⣀⡀⢀⣀⣠⣤⣤⣴⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣤⣤⣄⣀⡀⠀⣀⣀⣠⣤⡾⠿⣷⡀⠀⠀⠀⠀⠀

⠀⠀⠀⠀⠀⣸⡏⣿⣦⡈⠉⠛⠻⢿⣿⡿⠛⢉⣡⣴⣶⣿⡿⠟⠁⠈⠻⢿⣿⣷⣦⣌⡉⠛⢿⣿⡿⠟⠛⠉⠁⣠⣶⠸⣧⠀⠀⠀⠀⠀

⠀⠀⠀⠀⠀⣿⠀⣿⣿⣿⣦⡀⠀⢈⠏⠀⣴⣿⠟⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠛⣿⣧⠀⠹⡅⠀⠀⣴⣿⣿⣿⠀⣿⠀⠀⠀⠀⠀

⠀⠀⠀⠀⠀⣿⠀⢿⣿⣿⣿⣷⠀⠀⠀⣠⣿⠃⠀⠀⠀⠀⠀⢀⣠⣄⠀⠀⠀⠀⠀⠀⠘⢿⣄⠀⠈⠀⣼⣿⣿⣿⣿⠀⢿⡀⠀⠀⠀⠀

⠀⠀⠀⠀⠀⣿⠀⢸⣿⣿⣿⡿⢁⣴⡾⠛⢁⣠⣤⣶⣶⣶⣿⠿⠋⠙⠿⣿⣶⣶⣶⣤⣄⠈⠛⢷⣦⣸⣿⣿⣿⣿⣿⠄⣿⡇⠀⠀⠀⠀

⠀⠀⠀⠀⠀⢿⣷⣄⠹⡿⠋⠀⣸⡿⠃⣰⠿⠋⠉⠉⠉⠀⢀⡤⠀⠀⢤⡀⠀⠉⠉⠉⠙⠿⣆⠐⢿⣏⠈⠻⣿⡿⣃⣾⡿⠀⠀⠀⠀⠀

⠀⠀⠀⠀⠀⠈⣿⣿⣻⠁⢠⠾⠋⠀⠊⠁⠀⢀⣤⣤⣤⣴⣿⠀⠀⠀⠀⣿⣦⣤⣤⣤⡀⠀⠈⠑⠀⠙⠳⡄⠉⢹⣿⣿⡁⠀⠀⠀⠀⠀

⠀⠀⠀⠀⢠⣾⣿⣿⠁⠀⠁⠀⠀⠀⠀⠒⠚⠛⠋⠁⠀⠀⠈⢀⡀⠀⡀⠁⠀⠀⠈⠙⠛⠓⠒⠀⠀⠀⠀⠈⠀⠈⢿⣿⣿⡆⠀⠀⠀⠀

⠀⠀⠀⠀⣸⣿⣿⠇⠀⠀⠀⠀⠀⢀⣴⠞⠀⢀⣀⣠⣤⡶⠟⠉⠀⠀⠉⠻⢶⣤⣄⣀⡀⠀⠱⣦⡀⠀⠀⠀⠀⠀⠸⣿⣿⣇⠀⠀⠀⠀

⠀⠀⢀⣾⣿⠟⠁⠀⠀⣠⡖⢀⣴⡿⠋⠀⢠⡟⠋⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠙⢿⡄⠀⠘⢿⣶⡄⢲⣄⠀⠀⠈⠻⣿⣷⡀⠀⠀

⠀⢠⣿⣿⠋⠀⠀⣠⣾⡟⢠⣿⠏⠀⠀⠀⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠳⠀⠀⠀⠙⣿⡄⢻⣷⣄⠀⠀⠘⣿⣿⡄⠀

⢠⣿⣿⠁⠀⠀⢰⣿⣿⡇⢸⡟⠐⢿⣿⣷⣶⣦⣤⣾⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣷⣤⣴⣶⣾⣿⡿⠂⢹⡇⢸⣿⣯⠀⠀⠀⠈⢿⣿⡄

⣼⣿⡇⠀⠀⠀⢸⣿⣿⣧⠀⠃⠀⠀⠸⣧⡘⠋⣹⣿⣧⡀⠀⠀⠀⠀⠀⠀⢀⣾⣿⡏⠙⢃⣾⠇⠀⠀⠘⠀⣼⣿⣿⣇⠀⠀⠀⠸⣿⣷

⣿⣿⢠⠄⠀⠀⢸⣿⣿⣿⡷⠀⠀⠀⠀⠉⠛⠛⠛⢿⣿⣷⠀⠀⠀⠀⠀⠀⣾⣿⡿⠛⠛⠛⠉⠀⠀⠀⠀⢸⣿⣿⣿⡏⠀⠀⠀⡄⣿⣿

⣿⣿⣿⡄⠀⠀⠈⠿⣿⣿⣷⣤⣀⠀⠀⠀⠀⠀⢀⣾⠿⠋⠀⠀⠀⠀⠀⠀⠙⢿⣿⠀⠀⠀⠀⠀⠀⢀⣤⣾⣿⣿⡿⠃⠀⠀⠀⣿⣿⣿

⢸⣿⣿⡇⣤⠀⠀⠀⢻⣿⣿⣆⠀⠀⠀⠀⠀⠀⣼⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⣧⠀⠀⠀⠀⠀⠁⣠⣿⣿⡟⠀⠀⠀⣀⢸⣿⣿⡇

⠀⠋⢸⣿⣿⡆⠀⠀⠀⢻⣿⣿⡆⠀⠀⠀⠀⣸⡟⣠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣆⢻⣇⠀⠀⠀⠀⢠⣿⣿⡟⠀⠀⠀⢠⣿⣾⣧⠘⠀

⠀⠀⢸⣿⣿⣿⡀⣤⠀⠀⠹⣿⣿⢠⡄⠀⠀⡿⠀⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⠀⢿⠀⠀⢠⣆⣾⣿⠏⠀⠀⣠⠀⣾⣿⣿⡏⠀⠀

⠀⠀⠀⢻⣿⣿⣷⣿⣷⣄⠀⠉⣿⣿⣷⣄⠀⠁⢰⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣆⠈⠀⣠⣾⣿⣿⠋⠀⣠⣾⣿⣾⣿⢿⡟⠁⠀⠀

⠀⠀⠀⠀⠙⠘⢿⣿⣿⣿⣷⣄⡈⠉⠙⣿⣿⡆⢻⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡟⢸⣿⣿⠋⠉⢁⣠⣾⣿⣿⣿⡿⠃⠈⠀⠀⠀⠀

⠀⠀⠀⠀⠀⠀⠀⠙⠛⠎⢿⣿⣿⣶⣶⣿⡛⢧⠈⢷⡀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣾⠃⡼⠛⣿⣶⣶⣿⣿⡿⠁⠛⠋⠀⠀⠀⠀⠀⠀⠀

⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠉⠿⣿⣧⢤⣤⣈⠙⢿⣶⣶⣦⣤⣶⣶⡿⠛⣁⣠⡤⣼⣿⡿⠍⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀

⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⠐⢻⣿⡖⠶⠤⠄⠀⠀⠉⢻⡟⠉⠀⠀⠠⠤⢶⢲⣿⡟⠒⠄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀

⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠐⠊⢹⣿⣝⣓⡂⠀⣀⣀⣨⣇⣀⣀⡀⢐⣚⣫⣿⡟⠉⠒⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀

⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⢿⣿⣿⣿⡛⠋⠉⠛⠛⠉⠙⢛⣻⣿⣿⡿⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀

⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠙⠻⠿⣶⣦⣤⣶⠾⠟⠛⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀

*/

#include <bits/stdc++.h>

// #pragma GCC optimize("Ofast") 

// #pragma GCC target("avx,avx2,fma")

using namespace std;

using ll = long long;

using ld = long double;

using V = vector<ll>;

using VP = vector<pair<ll,ll>>;

using VS = vector<string>;

using PII = pair<ll,ll>;

#define superfast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(NULL);

#define FOR(i,a)for(ll i = 0; i < ll(a); i++)

#define FOR2(i,a,b) for(ll i = a; i < ll(b); i++)

#define FOR3(i,a) for(ll i = a-1; i >=0; i--)

#define FOR4(i,a,b) for(ll i = b-1; i >=a; i--)

#define FORO(i,a) for(ll i = 0; i < ll(a.size()); i++)

#define FORM(i,a) for(ll i = ll(a.size())-1; i >=0; i--)

#define FORK(i,a,b) for(ll i = a; i <b; i++)

#define llc(a) ll a; cin>>a;

#define sc(a) string a; cin>>a;

#define chc(a) char a; cin>>a;

#define pb              push_back

#define MIN(v) *min_element(v.begin(),v.end())

#define MAX(v) *max_element(v.begin(),v.end())

#define fi              first

#define se              second

#define endl            "\n"

#define ub(a,m) upper_bound(a.begin(),a.end(),m)-a.begin()

#define lb(a,m) lower_bound(a.begin(),a.end(),m)-a.begin()

#define yes             cout<<"YES\n";

#define no             cout<<"NO\n";

#define baseh             cout<<"\n";

#define out(x)             cout<<x<<'\n';

#define out2(x)             cout<<x<<' ';

#define out3(x)             cout<<x<<'/';

#define in(x)             cin>>x;

#define all(x)       (x).begin(),(x).end()

#define md(a, b)        (a%b + b)%b

const ll inf   =        LLONG_MAX-1;

const ll ninf  =        LLONG_MIN+1;

constexpr ld PI = 2*asinl(1.0);

template<typename T>

void SORT(T & A){

    sort(A.begin(),A.end());

}



template<typename T>

void SORTO(T & A){

    sort(A.rbegin(),A.rend());

}



template<typename T>

void CIN(T& a,ll n = -1){

 (n == -1) ? n = a.size() : n += 0;

    FOR(i,n) cin>>a[i];

}

template<typename T>

void COUT(T & a,ll n = -1){

(n == -1) ? n = a.size() : n += 0;

    FOR(i,n){

        cout<<a[i]<<' ';

    }

    cout<<endl;

}

template<typename T>

void EMPTY(T & a,ll t = 0){

    FOR(i,a.size()) a[i] = t;

}

template<typename T>

ll SUM(T a ,ll l = 0,ll r = -1){

 (r == -1) ? r = a.size() : r += 0;

    ll s = 0;

    FOR2(i,l,r) s += a[i];

    return s;

}

template<typename T>

ll FIND(T a,ll b){

    FOR(i,a.size()){

        if(a[i] == b) return i;

    }

    return -1;

}

ll GOUS(ll start,ll end,ll amount){

    return((start + end)*amount)/2;

}

bool ISPRIME(ll n){

  if(n<2)return false;

  for(int i=2;i<=sqrt(n);i++){

    if(n%i==0 && i!=0 && n!=i){

      return false;

    }

  }

  return true;

}

ll GCD(ll a,ll b){

    if(b==0){

      return a;

    }

    return GCD(b,a%b);

}

ll LCM(int a,int b){ return(a / GCD(a,b)) * b; }



bool ISDIGIT(char f){

  return(f>='0'&&f<='9');

}



string ADDBIN(string a, string b){

  string result = "";

  ll temp = 0;

  ll size_a = a.size() - 1;

  ll size_b = b.size() - 1;

  while (size_a >= 0 || size_b >= 0 || temp == 1) {

    temp += ((size_a >= 0) ? a[size_a] - '0' : 0);

    temp += ((size_b >= 0) ? b[size_b] - '0' : 0);

    result = char(temp % 2 + '0') + result;

    temp /= 2;

    size_a--;

    size_b--;

  }

  return result;

}





ld EVAL(string s){

  string ma;

  FORO(i,s){

    if(s[i]!=' '){

      ma+=s[i];

    }

  }

  V adad;

  vector<char> amal;

  FORO(i,ma){

    if(ma[i]=='('){

      ld iter=0;

      iter++;

      string e="";

      i++;

      while(true){

        if(ma[i]==')'){

          iter--;

          if(iter==0){

            adad.pb(EVAL(e));

            break;

          }

        }

        if(ma[i]=='(')iter++;

        e+=ma[i];

        i++;

      }

    }

    else if(ISDIGIT(ma[i])){

      string r="";

      r+=ma[i];

      while(ISDIGIT(ma[i+1])){

        r+=ma[i+1];

        i++;

      }

      adad.pb(stoi(r));

    }

    else{

      amal.pb(ma[i]);

    }

  }

  FORO(i,amal){

    if(amal[i]=='/'){

      if(adad[i+1]==0){

        return ninf;

      }

      adad[i]=adad[i]/adad[i+1];

      adad.erase(adad.begin()+i+1);

      amal.erase(amal.begin()+i);

      i--;

    }

    else if(amal[i]=='*'){

      adad[i]=adad[i]*adad[i+1];

      adad.erase(adad.begin()+i+1);

      amal.erase(amal.begin()+i);

      i--;

    }

  }

  if(adad.size()==1){

    return adad[0];

  }

  ld javab=adad[0];

  FORO(i,amal){

    if(amal[i]=='+'){

      javab+=adad[i+1];

    }

    else{

      javab-=adad[i+1];

    }

  }



  return javab;

}



string BIN_TO(ll n, ll m) {  

    if (n == 0) return "";  

    if (n%m < 10)  

        return BIN_TO(n/m,m)+(char)('0'+n%m);  

    else  

        return BIN_TO(n/m,m)+(char)('A'+(n%m-10));  

}



ll POWM(ll n,ll k,ll MOD){

    if(k == 0)

        return 1;

    ll half = POWM(n,k / 2,MOD);

    half =(half * half) % MOD;

    if(k % 2 != 0)

        half =(half * n) % MOD;

    return half;

}



ll POW(ll n,ll k){

    if(k == 0)

        return 1;

    ll half = POW(n,k / 2);

    half =(half * half);

    if(k % 2 != 0)

        half =(half * n);

    return half;

}



V DIVISIOR(ll n){

  V a;

  startn:

  FOR2(i,2,n+1){

    if(n%i==0){

      a.pb(i);

      n/=i;

      break;

    }

  }

  if(n!=1){

    goto startn;

  }

  return a;

}





const ll MOD=1e9+7;



ll FACT(ll n){

  ll ans=1;

  FOR2(i,2,n+1){

    ans*=i;

  }

  return ans;

}



ll CHOICE(int n, int k) {

    auto modPow = [](ll base, ll exp, ll mod) {

        ll result = 1;

        while (exp > 0) {

            if (exp % 2 == 1) {

                result = (result * base) % mod;

            }

            base = (base * base) % mod;

            exp /= 2;

        }

        return result;

    };

    auto factorial = [](ll num, ll mod) {

        ll result = 1;

        for (ll i = 2; i <= num; i++) {

            result = (result * i) % mod;

        }

        return result;

    };

    if (k < 0 || k > n) {

        return 0;

    }

    ll numerator = factorial(n, MOD);

    ll denominator = (factorial(k, MOD) * factorial(n - k, MOD)) % MOD;

    return (numerator * modPow(denominator, MOD - 2, MOD)) % MOD;

}



ll LOG(ll a,ll b){

  return log(a)/log(b);

}



bool ISSORTED(V a){

  FORO(i,a){

    if(i>0&&a[i]<a[i-1])return false;

  }

  return true;

}



bool MORBAKAMEL(ll num){

    if(num < 0) return false;

    ll root = static_cast<ll>(sqrt(num));

    return num == root * root;

}



string TO_UPPER(string a){ FORO(i,a) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a; }

string TO_LOWER(string a){ FORO(i,a) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a; }



string TO_BIN(ll x,ll y){

  string ans;

  while(x>0){

    ans=to_string(x%y)+ans;

    x/=y;

  }

  return ans;

}



void SOLVE(){

  llc(n);

  sc(s);

  V sha,pha;

  FORO(i,s){

    if(s[i]=='s'){

      sha.pb(i);

    }

    else if(s[i]=='p'){

      pha.pb(i);

    }

  }

  if(pha.empty()||sha.empty()){

    yes;

    return;

  }

  if(pha[0]<sha.back()){

    no;

    return;

  }

  if(s[n-1]!='p'&&s[0]!='s'){

    no;

    return;

  }

  yes;

}



int main(){

  // freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

  superfast;

  llc(t);

  while(t--)

    SOLVE();

  cerr <<endl<< "Time elapsed: "<<1.0 * clock() / CLOCKS_PER_SEC<<" s.\n";

}







//use pop_back bejai erase