Problem: 2049B - pspspsps
Language: c++17 

Solution 1 (runtime: 77 ms):
#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define pb push_back

#define int long long

#define sv(v) sort(v.begin(),v.end())

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

#define mp make_pair

const int N=1e7+10;

const int M=1e5+10;

//int pf[N];

long long binpow(long long a, long long b) {

    if(b==0)

        return 1;

    long long res = binpow(a,b/2);

    if(b%2)

        return res*res*a;

    else

        return res*res;

}

int mex(vector<int> &arr, int N){

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

    int mex = 0;

    for (int idx = 0; idx < N; idx++){

        if (arr[idx] == mex){

            mex += 1;

        }

    }

    return mex;

}

signed main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    int t;

    cin>>t;

    while(t--)

    {

        int n;cin>>n;

        string s;cin>>s;

        if(s[0]=='s') s[0]='.';

        if(s[n-1]=='p') s[n-1]='.';

        int flagp=0,flags=0;

        for(int i=0;i<n;i++){

            if(s[i]=='p') flagp=1;

            if(s[i]=='s') flags=1;

        }

        if(flagp && flags) cout<<"NO"<<endl;

        else cout<<"YES"<<endl;

    }

    return 0;

}



Solution 2 (runtime: 46 ms):
#include <bits/stdc++.h>
using namespace std;

/* clang-format off */

/* TYPES  */
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vll vector<long long>
#define mii map<int, int>
#define si set<int>
#define sc set<char>

/* FUNCTIONS */
#define f(a,n) for(long long int i=a;i<n;i++)
#define cf(i,s,e) for(long long int i=s;i<e;i++)
#define rf(e,s) for(long long int i=e-1;i>=s;i--)
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()


/* PRINTS */
template <class T>
void print_v(vector<T> &v) { cout << "{"; for (auto x : v) cout << x << ","; cout << "\b}"; }

/* UTILS */
#define M 1000000007
#define PI 3.1415926535897932384626433832795
#define read(type) readInt<type>()

ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b, a%b); }
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }

string to_upper(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a; }

string to_lower(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a; }

bool prime(ll a) { if (a==1) return 0; for (int i=2;i<=round(sqrt(a));++i) if (a%i==0) return 0; return 1; }

#define yy cout<<"Yes\n"
#define nn cout<<"No\n"

/* -question intuitions:
- dp --compute next result from the previous result of the sequence
        -- you have a choice at each step and each choice can lead to answer

- binary search -- can sort the array or sort the answer--- find minimum or maximum from the answer sample space ->binary search on answer n(long(n))
or upper/lower bound of something in a sorted sample namespac
 --- where anwer space is sorted and in fixed range

-heap -- find lowest or largest of a segment -- k is given example kth largest or smallest
if k+smallest -- kth smallest--maxheap
if k+largest --kth largest--  minheap
complexity-- nlog(k)
*/


#define inputv(arr,n) {for(int i=0;i<n;i++)cin>>arr[i];}
#define printv(a) {for(auto u:a) cout<<u<<" "; cout<<endl;}
void solve(){
    ll n;
    cin>>n;
    
    string s;
    cin>>s;


    if(n==1) {
        yy;
        return;
    }        
    if(s[0]=='s') s[0] = '.';
    if(s[n-1] == 'p') s[n-1] = '.';


    char ch = ' ';
    for(auto it: s){
        if(it!='.'){
            if(ch == ' '){
                ch = it;
            }else{
                if(ch != it) {
                    nn;
                    return
                ;
                }
            }
        }
    }

    yy;



}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t; cin>>t;
    while(t--){

    solve();
       




    }
    return 0;
}