#include <bits/stdc++.h>

using namespace std;

#define int long long

using pii = pair<int,int>;

signed main(void)

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int T = 1;

    cin >> T;

    while(T--)

    {

        int n;

        cin >> n;

        string s;

        cin >> s;

        string ans = "YES";

        int countp = 0, counts = 0;

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

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

                countp++;

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

                counts++;

            if((countp>0 and (s[i]=='s'))||(counts>1 && countp>1))

                ans = "NO";

        }

        if(((counts>0 && countp>0) && s[0] == '.' && s[n-1]=='.')||

        ((counts>1 && countp>0) && s[n-1]=='.')||

        ((countp>1 && counts>0) && s[0]=='.'))

            ans = "NO";

        cout<<ans<<endl;

    }

}

#include <bits/stdc++.h>

using namespace std;

#define int long long

using pii = pair<int,int>;

signed main(void)

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int T = 1;

    cin >> T;

    while(T--)

    {

        int n;

        cin >> n;

        string s;

        cin >> s;

        string ans = "YES";

        bool pflag = false;

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

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

                pflag = true;

            if(pflag and (s[i]=='s'||s[i]=='.'))

                ans = "NO";

        }

        cout<<ans<<endl;

    }

}

Answer: 1


#include<bits/stdc++.h>

using namespace std;

void solve(void)

{

	int n;cin>>n;

	string s;cin>>s;

	int snum=0,pnum=0;

	bool pj=1;int posp,poss;

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

	{

		if(pj&&s[i]=='p')

		{

			posp=i;

			pj=0;

		}

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

		{

			snum++;

			poss=i;

		}

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

			pnum++;

	}

	if(snum!=0&&pnum!=0&&posp<poss)

	{

		cout<<"NO\n";

		return ;

	}

	if(snum>1&&pnum>1)

	{

		cout<<"NO\n";

		return;

	}

	if(snum==1&&pnum==1&&(s[0]=='s'||s[n-1]=='p'))

	{

		cout<<"YES\n";

		return;

	}

	if(snum==1&&pnum!=0&&s[0]!='s')

	{

		cout<<"NO\n";

		return;

	}

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

	{

		cout<<"NO\n";

		return;

	}

//	cout<<posp<<" "<<poss<<endl;

	cout<<"YES\n";

}

signed main(void)

{

	ios::sync_with_stdio(0);

	cin.tie(0);cout.tie(0);

	int t;cin>>t;

	while(t--)

	{

		solve();

	}

}

#include<bits/stdc++.h>

using namespace std;

void solve(void)

{

	int n;cin>>n;

	string s;cin>>s;

	int snum=0,pnum=0;

	bool pj=1;int posp,poss;

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

	{

		if(pj&&s[i]=='p')

		{

			posp=i;

			pj=0;

		}

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

		{

			snum++;

			poss=i;

		}

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

			pnum++;

	}

	if(snum!=0&&pnum!=0&&posp<poss)

	{

		cout<<"NO\n";

		return ;

	}

	if(snum>1&&pnum>1)

	{

		cout<<"NO\n";

		return;

	}

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

	{

		cout<<"NO\n";

		return;

	}

//	cout<<posp<<" "<<poss<<endl;

	cout<<"YES\n";

}

signed main(void)

{

	ios::sync_with_stdio(0);

	cin.tie(0);cout.tie(0);

	int t;cin>>t;

	while(t--)

	{

		solve();

	}

}

Answer: 1


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

// using namespace std;

// int main(){

//     int t;

//     cin>>t;

//     while (t--){

//         int n;

//         cin>>n;

//         vector<int> v;

//         map<int,int> mp;

//         int x,y;

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

//             cin>>x>>y;

//             mp[x] = y;

//             v.push_back(y);

//         }

//         sort(v.begin(),v.end());

//         long total = 0;

//         for(auto &j : mp){

//             auto p = lower_bound(v.begin(),v.end(),j.second);

//             total+=p-v.begin();

//             v.erase(p);

//         }

//         cout<<total<<endl;

//     }

//     return 0;

// }

#include <bits/stdc++.h>

using namespace std;

int main(){

	int t;

	cin>>t;

	while (t--)

	{

		int n;

		string s;

		cin>>n>>s;

		bool is_poss=true,is_p=false,is_s=false;

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

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

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

			if(s[i]=='p') is_p = true;

			if(s[i]=='s') is_s = true;

		}

		if(is_s && is_p == true){

			cout<<"NO"<<endl;

		}else{

			cout<<"YES"<<endl;

		}

	}

}

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

// using namespace std;

// int main(){

//     int t;

//     cin>>t;

//     while (t--){

//         int n;

//         cin>>n;

//         vector<int> v;

//         map<int,int> mp;

//         int x,y;

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

//             cin>>x>>y;

//             mp[x] = y;

//             v.push_back(y);

//         }

//         sort(v.begin(),v.end());

//         long total = 0;

//         for(auto &j : mp){

//             auto p = lower_bound(v.begin(),v.end(),j.second);

//             total+=p-v.begin();

//             v.erase(p);

//         }

//         cout<<total<<endl;

//     }

//     return 0;

// }

#include <bits/stdc++.h>

using namespace std;

int main(){

	int t;

	cin>>t;

	while (t--)

	{

		int n;

		string s;

		cin>>n>>s;

		bool is_poss=true,is_p=false,is_s=false;

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

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

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

			if(s[i]=='p') is_p = true;

			if(s[i]=='s') is_s = true;

		}

		if(is_s && is_p){

			cout<<"NO"<<endl;

		}else{

			cout<<"YES"<<endl;

		}

	}

}

Answer: 1


#include <iostream>

#include <string>

#include <unordered_map>

#define inout std::ios::sync_with_stdio(false); std::cin.tie(nullptr);

using ll = long long;

void solve()

{

    int n;

    std::cin >> n;

    std::string str;

    std::cin >> str;

    // sp.... -> possible

    // ....sp -> possible

    // ps impossible in any case

    // basically p should be leading and only one p is allowed

    std::unordered_map<char, int> map;

    for (char e : str) map[e]++;

    bool p = false, s = false, oneP = false, oneS = false;

    for (const auto& [first, second] : map)

    {

        if (first == 'p' && second > 1) p = true;

        if (first == 's' && second > 1) s = true;

        if (first == 's' && second == 1) oneS = true;

        if (first == 'p' && second == 1) oneP = true;

    }

    if ((p && s) || (oneS && p)) {std::cout << "NO\n"; return;}

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

    p = false; s = false;

    for (char e : str)

    {

        if (e == 'p') p = true;

        if (e == 's') s = true;

    }

    (p && s) ? std::cout << "NO\n" : std::cout << "YES\n";

}

int main()

{

    inout;

    int t = 1;

    std::cin >> t;

    while (t--) solve();

}

#include <iostream>

#include <string>

#include <unordered_map>

#define inout std::ios::sync_with_stdio(false); std::cin.tie(nullptr);

using ll = long long;

void solve()

{

    int n;

    std::cin >> n;

    std::string str;

    std::cin >> str;

    // sp.... -> possible

    // ....sp -> possible

    // ps impossible in any case

    // basically p should be leading and only one p is allowed

    bool p = false, s = false;

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

    for (char e : str)

    {

        if (e == 'p') p = true;

        if (e == 's') s = true;

    }

    (p && s) ? std::cout << "NO\n" : std::cout << "YES\n";

}

int main()

{

    inout;

    int t = 1;

    std::cin >> t;

    while (t--) solve();

}

Answer: 2


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace std;

#define int long long

#define rep(i, x, n) for (int i = x; i < n; i++)

#define rrep(i, x, n) for (int i = n; i >= x; i--)

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

#define fi first

#define se second

#define endl "\n"

#define pb push_back

#define pii pair<int, int>

#define vi vector<int>

#define vii vector<pair<int,int>>

#define vvi vector<vector<int>>

#define inf (int)1e18

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

typedef __gnu_pbds::tree<int, __gnu_pbds::null_type, less<int>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set;

const int M=1e9+7;

// Binary Exponentiation

int binExp(int a, int b) { int x = 1; while (b) { if (b & 1) x = (x * 1ll * a) % M; a = (a * 1ll * a) % M; b >>= 1; } return x; }

void Solve()

{

    int n,m,k,q;

    string s;

    cin>>n>>s;

    int prevp=0;

    rep(i,0,n){

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

        else if(s[i]=='s' && prevp){

            cout<<"NO\n";

            return;

        }

    }

    rep(i,1,n-2){

        if(s[i]=='s' && s[i+1]=='p'){

            cout<<"NO\n";

            return;

        }

    }

    cout<<"YES\n";

}

int32_t main()

{

    auto begin = std::chrono::high_resolution_clock::now();

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    int t = 1;

    // freopen("in",  "r", stdin);

    // freopen("out", "w", stdout);

    cin >> t;

    while(t--)

    {

        //cout << "Case #" << i << ": ";

        Solve();

    }

    auto end = std::chrono::high_resolution_clock::now();

    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);

    // cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";

    return 0;

}

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace std;

#define int long long

#define rep(i, x, n) for (int i = x; i < n; i++)

#define rrep(i, x, n) for (int i = n; i >= x; i--)

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

#define fi first

#define se second

#define endl "\n"

#define pb push_back

#define pii pair<int, int>

#define vi vector<int>

#define vii vector<pair<int,int>>

#define vvi vector<vector<int>>

#define inf (int)1e18

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

typedef __gnu_pbds::tree<int, __gnu_pbds::null_type, less<int>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set;

const int M=1e9+7;

// Binary Exponentiation

int binExp(int a, int b) { int x = 1; while (b) { if (b & 1) x = (x * 1ll * a) % M; a = (a * 1ll * a) % M; b >>= 1; } return x; }

void Solve()

{

    int n,m,k,q;

    string s;

    cin>>n>>s;

    int prevp=0,prevs=0;

    rep(i,0,n){

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

            if(prevp==0) prevp=i+1;

        }

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

            prevs=i+1;

            if(prevp){

                cout<<"NO\n";

                return;

            }

        }

    }

    if(!prevs || !prevp) cout<<"YES\n";

    else if(prevs==1 || prevp==n) cout<<"YES\n";

    else cout<<"NO\n";

}

int32_t main()

{

    auto begin = std::chrono::high_resolution_clock::now();

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    int t = 1;

    // freopen("in",  "r", stdin);

    // freopen("out", "w", stdout);

    cin >> t;

    while(t--)

    {

        //cout << "Case #" << i << ": ";

        Solve();

    }

    auto end = std::chrono::high_resolution_clock::now();

    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);

    // cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";

    return 0;

}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

int n;

string s;

void solve() {

    cin >> n >> s;

    int l = n - 1, r = 0;

    while(l >= 0 && s[l] != 's') l--;

    while(r < n && s[r] != 'p') r++;

    if(l > r) {

        cout << "No" << '\n';

        return;

    }

    if(l < 1 || n - r < 2) {

        cout << "Yes" << '\n';

    } else {

        // cout << l << ' ' << r << '\n';

        cout << "No" << '\n';

    }

}

int main() {

    int t;  cin >> t;

    while(t--) {

        solve();

    }

    return 0;

}

/*

sspp

4312

*/

#include <bits/stdc++.h>

using namespace std;

int n;

string s;

void solve() {

    cin >> n >> s;

    bool f1 = false, f2 = false;

    for(char c : s) {

        if(c == 'p') f1 = true;

        else if(c == 's') f2 = true;

    }

    if(!f1 || !f2) {

        cout << "Yes" << "\n";

        return;

    }

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

        cout << "Yes" << "\n";

    }

    else cout << "No" << "\n";

}

int main() {

    int t;  cin >> t;

    while(t--) {

        solve();

    }

    return 0;

}

Answer: 1


#include <bits/stdc++.h>

using namespace std;

int main(){

    int t;

    cin >> t;

    while(t--){

        int n;

        cin >> n;

        string h;

        cin >> h;

        int i = 0;

        int j = n - 1;

        if(h[0] == h[n - 1]){

            i++;

            j--;

            goto abc;

        }

        if(h[0] == 's' || h[0] == '.'){

            i++;

        }

        if(h[n - 1] == 'p' || h[n - 1] == '.'){

            j--;

        }

        abc : //skip statement

        bool flag1 = 0;

        bool flag2 = 0;

        for(int p = i; p <= j; p++){

            if(h[p] == '.') continue;

            if(h[p] == 's') flag1 = 1;

            if(h[p] == 'p') flag2 = 1;

        }

        if(flag1 && flag2){

            cout << "NO" << endl;

        } else {

            cout << "YES" << endl;

        }

    }

}

#include <bits/stdc++.h>

using namespace std;

int main(){

    int t;

    cin >> t;

    while(t--){

        int n;

        cin >> n;

        string h;

        cin >> h;

        int i = 0;

        int j = n - 1;

        if(h[0] == 's' || h[0] == '.'){

            i++;

        }

        if(h[n - 1] == 'p' || h[n - 1] == '.'){

            j--;

        }

        bool flag1 = 0;

        bool flag2 = 0;

        for(int p = i; p <= j; p++){

            if(h[p] == '.') continue;

            if(h[p] == 's') flag1 = 1;

            if(h[p] == 'p') flag2 = 1;

        }

        if(flag1 && flag2){

            cout << "NO" << endl;

        } else {

            cout << "YES" << endl;

        }

    }

}

Answer: 2


            /***>  @author : a_e_kasem  <***/

//                        ﷽

//                  { وَأَنْ لَيْسَ لِلْإِنْسَانِ إِلَّا مَا سَعَى }

//                           {***}

//         فَالجُهدُ يُثمِرُ إنْ تَضافَرَ صَفوُهُ، والعَزمُ يَرفعُ صَرحَ كُلِّ بُنيانِ

//

//                    وَما نَيلُ المَطالِبِ بِالتَمَنّي

//                     وَلَكِن تُؤخَذُ الدُنيا غِلابا

//                           ***

//                   وَما اِستَعصى عَلى قَومٍ مَنالٌ

//                      إِذا الإِقدامُ كانَ لَهُم رِكا

//

#include <bits/stdc++.h>

using namespace std;

#define int                 long long

#define ld                  long double

#define ull                 unsigned long long

#define w(x)                int x; cin >> x; while(x--)

#define vi                  vector<int>

#define vvi                 vector<vector<int> >

#define fi                  first

#define se                  second

#define pii                 pair<int, int>

#define vpii                vector<pair<int, int> >

#define FOR(i, a, b)        for (int(i) = (a); (i) <= (b); ++(i))

#define RFOR(i, a, b)       for (int(i) = (a)-1; (i) >= (b); --(i))

#define FORALL(i, a)        for (auto& (i) : (a))

#define printall(a)         for (auto& (i) : (a)) cout << i << ' '

#define cinall(a)           for (auto& (i) : (a)) cin >> i

#define cin_1all(a, n)      for (int (i) = 1; (i) <= (n) ; i++) cin >> a[i]

#define rsort(a)            sort((a).rbegin(), (a).rend())

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

#define pqmn                priority_queue<int, vector<int>, greater<int> >

#define mx_all(c)           *max_element((c).begin(), (c).end())

#define mn_all(c)           *min_element((c).begin(), (c).end())

#define FIO                 ios::sync_with_stdio(false); cin.tie(nullptr);

#define in                  freopen("input.txt", "r", stdin);

#define el                  cout << "\n"

#define no                  cout << "No" << endl

#define yes                 cout << "Yes" << endl

#define NO                  cout << "NO" << endl

#define YES                 cout << "YES" << endl

const int INF = (long long)2e9;

const int MOD = (long long) 7+1e9;

const ld  PI  = 3.1415926535897932384626;

void FASTIO();

void solve();

int32_t main() {

    FASTIO();

    w(t)

    {

        solve();

    }

    // solve();

}

/*===================================================================//

       ██╗  ██╗     █████╗     ███████╗    ███████╗    ███╗   ███╗

       ██║ ██╔╝    ██╔══██╗    ██╔════╝    ██╔════╝    ████╗ ████║

       █████╔╝     ███████║    ███████╗    █████╗      ██╔████╔██║

       ██╔═██╗     ██╔══██║    ╚════██║    ██╔══╝      ██║╚██╔╝██║

       ██║  ██╗    ██║  ██║    ███████║    ███████╗    ██║ ╚═╝ ██║

       ╚═╝  ╚═╝    ╚═╝  ╚═╝    ╚══════╝    ╚══════╝    ╚═╝     ╚═╝

//====================================================================*/

void FASTIO()

{

    FIO

#ifndef ONLINE_JUDGE

    freopen("input.txt", "r", stdin);

    freopen("error.txt", "w", stderr);

#endif

}

int ctoi(char c) {

    return (c - '0');

}

int sum_of_digits(int n) {

    string s = to_string(n);

    return s.size();

}

void solve() {

    int n; cin >> n;

    vector<char> a(n);

    int p = 0, s = 0;

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

    {

        cin >> a[i];

        if (a[i] == 'p') p++;

        if (a[i] == 's') s++;

    }

    if (!s || !p) YES;

    else if (p == 1 && a.back() == 'p') YES;

    else if (s == 1 && a.front() == 's') YES;

    else NO;

}

            /***>  @author : a_e_kasem  <***/

//                        ﷽

//                  { وَأَنْ لَيْسَ لِلْإِنْسَانِ إِلَّا مَا سَعَى }

//                           {***}

//         فَالجُهدُ يُثمِرُ إنْ تَضافَرَ صَفوُهُ، والعَزمُ يَرفعُ صَرحَ كُلِّ بُنيانِ

//

//                    وَما نَيلُ المَطالِبِ بِالتَمَنّي

//                     وَلَكِن تُؤخَذُ الدُنيا غِلابا

//                           ***

//                   وَما اِستَعصى عَلى قَومٍ مَنالٌ

//                      إِذا الإِقدامُ كانَ لَهُم رِكا

//

#include <bits/stdc++.h>

using namespace std;

#define int                 long long

#define ld                  long double

#define ull                 unsigned long long

#define w(x)                int x; cin >> x; while(x--)

#define vi                  vector<int>

#define vvi                 vector<vector<int> >

#define fi                  first

#define se                  second

#define pii                 pair<int, int>

#define vpii                vector<pair<int, int> >

#define FOR(i, a, b)        for (int(i) = (a); (i) <= (b); ++(i))

#define RFOR(i, a, b)       for (int(i) = (a)-1; (i) >= (b); --(i))

#define FORALL(i, a)        for (auto& (i) : (a))

#define printall(a)         for (auto& (i) : (a)) cout << i << ' '

#define cinall(a)           for (auto& (i) : (a)) cin >> i

#define cin_1all(a, n)      for (int (i) = 1; (i) <= (n) ; i++) cin >> a[i]

#define rsort(a)            sort((a).rbegin(), (a).rend())

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

#define pqmn                priority_queue<int, vector<int>, greater<int> >

#define mx_all(c)           *max_element((c).begin(), (c).end())

#define mn_all(c)           *min_element((c).begin(), (c).end())

#define FIO                 ios::sync_with_stdio(false); cin.tie(nullptr);

#define in                  freopen("input.txt", "r", stdin);

#define el                  cout << "\n"

#define no                  cout << "No" << endl

#define yes                 cout << "Yes" << endl

#define NO                  cout << "NO" << endl

#define YES                 cout << "YES" << endl

const int INF = (long long)2e9;

const int MOD = (long long) 7+1e9;

const ld  PI  = 3.1415926535897932384626;

void FASTIO();

void solve();

int32_t main() {

    FASTIO();

    w(t)

    {

        solve();

    }

    // solve();

}

/*===================================================================//

       ██╗  ██╗     █████╗     ███████╗    ███████╗    ███╗   ███╗

       ██║ ██╔╝    ██╔══██╗    ██╔════╝    ██╔════╝    ████╗ ████║

       █████╔╝     ███████║    ███████╗    █████╗      ██╔████╔██║

       ██╔═██╗     ██╔══██║    ╚════██║    ██╔══╝      ██║╚██╔╝██║

       ██║  ██╗    ██║  ██║    ███████║    ███████╗    ██║ ╚═╝ ██║

       ╚═╝  ╚═╝    ╚═╝  ╚═╝    ╚══════╝    ╚══════╝    ╚═╝     ╚═╝

//====================================================================*/

void FASTIO()

{

    FIO

#ifndef ONLINE_JUDGE

    freopen("input.txt", "r", stdin);

    freopen("error.txt", "w", stderr);

#endif

}

int ctoi(char c) {

    return (c - '0');

}

int sum_of_digits(int n) {

    string s = to_string(n);

    return s.size();

}

void solve() {

    int n; cin >> n;

    vector<char> a(n);

    int p = 0, s = 0;

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

    {

        cin >> a[i];

        if (a[i] == 'p') p++;

        if (a[i] == 's') s++;

    }

    if (!s || !p) YES;

    else if (s == 1 && a.back() == 'p') YES;

    else if (p == 1 && a.front() == 's') YES;

    else NO;

}

Answer: 1


a = int(input())

for y in range(a):

  b = int(input())

  c = input()

  k = 0

  for z in range(b):

    if c[z] == "p" and k == 0:

      k = 1

    elif k == 1 and c[z] == "s":

      k = -1

      break

  if "s" in c and "p" in c:

    if c[-1] != "p":

      print("No")

    elif k == -1:

      print("No")

    else:

      print("Yes")

  elif k == -1:

    print("No")

  else:

    print("Yes")

a = int(input())

for y in range(a):

  b = int(input())

  c = input()

  j = list(c)

  if j[0] == "s":

    j[0] = "."

  if j[-1] == "p":

    j[-1] = "."

  l = 0

  if "s" in j and "p" in j:

    l = -1

  print("Yes") if l == 0 else print("No")

Answer: 2


#include<bits/stdc++.h>

using namespace std;

#define int long long int

void solve(){

    int n;

    cin>>n;

    string s;

    cin>>s;

    bool f = false;

    int cnts = 0;

    int cntp = 0;

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

        if(s[i]=='p') cntp++;

        else if(s[i]=='s') cnts++;

    }

    if(cntp<=1 || cnts<=1){

        if(cntp==0 || cnts==0){

            cout<<"YES\n";

            return;

        }

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

            cout<<"YES\n";

            return;

        }

        else{

            cout<<"NO\n";

            return;

        }

        if(cnts==1 && s[0]=='s'){

            cout<<"YES\n";

            return;

        }

        else{

            cout<<"NO\n";

            return;

        }

    }

    else{

        cout<<"NO\n";

        return;

    }

}

signed main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    int tt = 1;

    cin>>tt;

    while(tt--){

        solve();

    }

    return 0;

}

#include<bits/stdc++.h>

using namespace std;

#define int long long int

void solve(){

    int n;

    cin>>n;

    string s;

    cin>>s;

    bool f = false;

    int cnts = 0;

    int cntp = 0;

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

        if(s[i]=='p') cntp++;

        else if(s[i]=='s') cnts++;

    }

    if(cntp<=1 || cnts<=1){

        if(cntp==0 || cnts==0){

            cout<<"YES\n";

            return;

        }

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

            cout<<"YES\n";

            return;

        }

        else if(cnts==1 && s[0]=='s'){

            cout<<"YES\n";

            return;

        }

        else{

            cout<<"NO\n";

            return;

        }

    }

    else{

        cout<<"NO\n";

        return;

    }

}

signed main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    int tt = 1;

    cin>>tt;

    while(tt--){

        solve();

    }

    return 0;

}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

int main(){

    ios::sync_with_stdio(false);

    cin.tie(0) , cout.tie(0);

    int t;

    cin >> t;

    while(t --){

        int n;

        cin >> n;

        string s;

        cin >> s;

        int s_cnt = 0 , p_cnt = 0 , wzs = -1 , wzp = -1 , cs = -1;

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

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

                s_cnt ++;

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

                p_cnt ++;

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

                wzs = i;

            else if(s[i] == 'p' && wzp == -1)

                wzp = i;

            if(s[i] == 's' && cs == -1)

                cs = i;

        }

        if(s_cnt && p_cnt){

            if(wzs > wzp || cs != 0)

                cout << "NO" << '\n';

            else

                cout << "YES" << '\n';

        }else

            cout << "YES" << '\n';

    }

    return 0;

}

#include <bits/stdc++.h>

using namespace std;

int main(){

    ios::sync_with_stdio(false);

    cin.tie(0) , cout.tie(0);

    int t;

    cin >> t;

    while(t --){

        int n;

        cin >> n;

        string s;

        cin >> s;

        int wzs = -1 , wzp = -1;

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

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

                wzs = i;

            else if(s[i] == 'p' && wzp == -1)

                wzp = i;

        }

        if((wzs >= -1 && (wzp == n - 1 || wzp == -1)) || (wzs == -1 || wzs == 0) && wzp >= -1)

            cout << "YES" << '\n';

        else

            cout << "NO" << '\n';

    }

    return 0;

}

Answer: 2


#include<bits/stdc++.h>

#define ll long long

#define MAXN 100001

using namespace std;

vector<int> spf(MAXN + 1, 1);

void sieve()

{

    spf[0] = 0;

    for (int i = 2; i <= MAXN; i++) {

        if (spf[i] == 1) {

            for (int j = i; j <= MAXN; j += i) {

                if (spf[j]== 1)

                    spf[j] = i;

            }

        }

    }

}

map<int,int> getFactorization(int x)

{

    map<int,int> ret;

    while (x != 1) {

        ret[spf[x]]++;

        x = x / spf[x];

    }

    return ret;

}

void solve(){

    int n;

    cin>>n;

    string s;

    cin>>s;

    int f=0;

    int x=0;

    int z=0;

    int y=0;

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

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

            f=1;

        }

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

            x=1;

        }

        if(s[i]=='s'&&f==1){

            cout<<"NO"<<endl;

            return;

        }

    }

    if(x&&f){

        int a=1;

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

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

            a=0;

            break;

        }

       }

       int b=1;

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

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

            b=0;

            break;

        }

       }

       if(!(a||b)){

        cout<<"NO"<<endl;

        return;

       }

    }

    cout<<"YES"<<endl;

}

int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    int t;

    cin>>t;

   while(t--){

      solve();

   }

    return 0;

}

#include<bits/stdc++.h>

#define ll long long

#define MAXN 100001

using namespace std;

vector<int> spf(MAXN + 1, 1);

void sieve()

{

    spf[0] = 0;

    for (int i = 2; i <= MAXN; i++) {

        if (spf[i] == 1) {

            for (int j = i; j <= MAXN; j += i) {

                if (spf[j]== 1)

                    spf[j] = i;

            }

        }

    }

}

map<int,int> getFactorization(int x)

{

    map<int,int> ret;

    while (x != 1) {

        ret[spf[x]]++;

        x = x / spf[x];

    }

    return ret;

}

void solve(){

    int n;

    cin>>n;

    string s;

    cin>>s;

    int f=0;

    int x=0;

    int z=0;

    int y=0;

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

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

            f=1;

        }

        if(s[i]=='.'&&f==1){

            x=1;

        }

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

            y=1;

        }

        if(s[i]=='s'&&y==1){

            z=1;

        }

        if(s[i]=='s'&&f==1){

            cout<<"NO"<<endl;

            return;

        }

    }

    if(x&&z){

        cout<<"NO"<<endl;

        return;

    }

    cout<<"YES"<<endl;

}

int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    int t;

    cin>>t;

   while(t--){

      solve();

   }

    return 0;

}

Answer: 1


# include <bits/stdc++.h>

using namespace std;

   void solve(){

      int n;

      cin>>n;

      string s;

      cin>>s;

      int pp=0;

      int ss=0;

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

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

            pp++;

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

            ss++;

      }

   }

      if(ss==0||pp==0){

         cout<<"YES"<<endl;

         return ;

      }

      int s1=0;

      int p1=-1;

      int idx=0;

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

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

            s1=idx;

         }

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

            if(p1==-1){

               p1=idx;

            }

         }

         idx++;

      }

      if(s1==0||p1==n-1){

         cout<<"YES"<<endl;

         return;

      }

      cout<<"NO"<<endl;

   }

   int main(){

   int t;

   cin>>t;

   while(t--){

      solve();

   }

return 0;

}

# include <bits/stdc++.h>

using namespace std;

   void solve(){

      int n;

      cin>>n;

      string s;

      cin>>s;

      int pp=0;

      int ss=0;

      int dot=0;

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

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

            pp++;

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

            ss++;

         }else{

            dot++;

         }

      }

      // cout<<pp<<endl;

      if(ss+dot==n||pp+dot==n||dot==n){

         cout<<"YES"<<endl;

         return ;

      }

        bool flag=false;

        int cnt=0;

        int cnt2=0;

        bool s1=false;

        bool s2=false;

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

         if(s[i]=='s' &&cnt==0){

            cnt++;

            flag=true;

            s1=true;

         }

         if(flag==true&&s[i]=='p'){

            cnt++;

            s2=true;

         }

         if(s[i]=='.'&&s1){

            cnt++;

         }

      }

      bool found=true;

           bool p1=false;

           bool p2=false;

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

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

            cnt2++;

            p1=true;

         }

         if(s[i]=='p'&&found==true){

            cnt2++;

            found=false;

            p2=true;

         }

         if(p1==true&&p2==false&&s[i]=='.'){

            cnt2++;

         }

      }

      if(cnt==n||cnt2==n){

         cout<<"YES"<<endl;

         return ;

      }

      cout<<"NO"<<endl;

   }

   int main(){

   int t;

   cin>>t;

   while(t--){

      solve();

   }

return 0;

}

Answer: 1


        #include<bits/stdc++.h>

        using namespace std;

        #define ll long long

        #define test cout<<"ok"<<endl;

        #define check(n) for(auto x:n)cout<<x<<" "

        //  p.push_back(make_pair(a,b));

        // pr.push_back({1,3});

        //factor and divisor are same which is limited & multiple are unlimited

        #define debug(x) cout << #x <<" " << x << endl;

        #define Faster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

        #define MX  1000000+7

        vector < bool > is_prime(MX+ 1, true);

        /*is_prime[0] = false;

        is_prime[1] = true;

        for(int i = 2; i<= MX; i++){

            if(is_prime[i] == true && i * i <= MX)

                {

                    for(int j = i * i ; j <= MX ;j+= i)

                    {

                        is_prime[j] = false;

                    }

                }

        }*/

        void solve(){

        ll n; cin >> n;

         string s;

         cin >> s;

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

            s[0] = '.';

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

            s[n-1] = '.';

        bool flag1= false, flag2 = false;

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

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

                flag1 = true;

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

                flag2 = true;

        }

        if(flag1 & flag2)

            cout << "NO" << endl;

        else

            cout <<"YES" << endl;

        }

        int main(){

        Faster;

        int t;   cin >> t;

        while(t --){

            solve();

            }

        }

        #include<bits/stdc++.h>

        using namespace std;

        #define ll long long

        #define test cout<<"ok"<<endl;

        #define check(n) for(auto x:n)cout<<x<<" "

        //  p.push_back(make_pair(a,b));

        // pr.push_back({1,3});

        //factor and divisor are same which is limited & multiple are unlimited

        #define debug(x) cout << #x <<" " << x << endl;

        #define Faster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

        #define MX  1000000+7

        vector < bool > is_prime(MX+ 1, true);

        /*is_prime[0] = false;

        is_prime[1] = true;

        for(int i = 2; i<= MX; i++){

            if(is_prime[i] == true && i * i <= MX)

                {

                    for(int j = i * i ; j <= MX ;j+= i)

                    {

                        is_prime[j] = false;

                    }

                }

        }*/

        void solve(){

        ll n; cin >> n;

         string s;

         cin >> s;

         int ppos = 0, spos = 0;

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

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

            spos = i;

         }

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

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

            ppos = i;

            break;

           }

         }

        if(ppos < spos)

            cout <<"NO" << endl;

        else {

            bool flag1 = false;

            bool flag2 = false;

            for(int i = spos-1; i >=0; i--){

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

                    flag1 = true;

            }

            for(int i = ppos+1; i <n; i++){

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

                    flag2 = true;

            }

            if(flag1 & flag2)

                    cout << "NO" << endl;

            else

                cout << "YES" << endl;

        }

        }

        int main(){

        Faster;

        int t;   cin >> t;

        while(t --){

            solve();

            }

        }

Answer: 1


#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
string s;
cin>>s;
map<char,int>be,af;
int i=0;
while(i<n && s[i]!='p'){
    be[s[i]]++;
    i++;
}
if(i==n){
    cout<<"YES"<<endl;
}
else if(be['s']>0 && i==n-1){
    cout<<"YES"<<endl;
}
else if(be['s']>0 && i>1 && i<n-1){
    cout<<"NO"<<endl;
}
else{
    int p=i;
    while(i<n){
        af[s[i]]++;
        i++;
    }
    if(be['s']==0 && af['s']==0){
        cout<<"YES"<<endl;
    }
    else if(af['s']>0){
        cout<<"NO"<<endl;
    }
    else{
        cout<<"YES"<<endl;
    }
}
}
return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
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]='.';
bool x=false,y=false;
int i=0;
while(i<n){
    if(s[i]=='s') x=true;
    else if(s[i]=='p') y=true;
    i++;
}
if(x==true && y==true){
    cout<<"NO"<<endl;
}
else{
    cout<<"YES"<<endl;
}
}
}

Answer: 2


#include <bits/stdc++.h>

#define endl "\n"

// #define int long long

using namespace std;

using i64 = long long;

using u64 = unsigned long long;

constexpr int N = 2e5 + 1;

constexpr int P = 131;

constexpr int INF = 1e9;

void solve() {

    int n;

    cin >> n;

    string s;

    cin >> s;

    s = " " + s;

    int r = INF;

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

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

            r = i;

            break;

        }

    }

    bool ok = true;

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

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

            if (n > r) {

                ok = false;

                break;

            }

        }

    }

    if (ok) {

        cout << "YES\n";

    } else {

        cout << "NO\n";

    }

}

signed main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    cout.tie(nullptr);

    int T;

    cin >> T;

    while (T--) {

        solve();

    }

}

#include <bits/stdc++.h>

#define endl "\n"

// #define int long long

using namespace std;

using i64 = long long;

using u64 = unsigned long long;

constexpr int N = 2e5 + 1;

constexpr int P = 131;

constexpr int INF = 1e9;

void solve() {

    int n;

    cin >> n;

    string s;

    cin >> s;

    s = " " + s;

    int mnp = INF, mxs = 0;

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

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

            mnp = min(mnp, i);

        } else {

            mxs = max(mxs, i);

        }

    }

    if (mnp < mxs) {

        cout << "NO\n";

    } else {

        cout << "YES\n";

    }

}

signed main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    cout.tie(nullptr);

    int T;

    cin >> T;

    while (T--) {

        solve();

    }

}

Answer: 1


import static java.lang.Math.max;

import static java.lang.Math.min;

import static java.lang.Math.abs;

import java.util.*;

import java.io.*;

import java.math.*;

public final class Main {

    static PrintWriter out = new PrintWriter(System.out);

    static FastReader in = new FastReader();

    static final int MOD1 = (int) (1e9 + 7);

    static final int MOD2 = 998244353;

    static final int inf = Integer.MAX_VALUE;

    static final int minf = Integer.MIN_VALUE;

    static final long linf = 1L << 62;

    public static void main(String[] args){

        int tt = i();

        while (tt-- > 0) {

            solve();

        }

        out.flush();

    }

    public static void solve(){

        // int MIN = -1*(int) 1e9;

        // int MAX = (int) 1e9;

        // PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());

        int n = i();

        String s = s();

        // int ar[]=input(n);

        // int ar[] = new int[n];

        int id1=-1,id2=-1,id3=-1,id4=-1;

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

            if(s.charAt(i)=='p'){

                if(id3==-1)id3=i;

                id1=i;

            }

            if(s.charAt(i)=='s'){

                if(id4==-1)id4=i;

                id2=i;

            }

        }

        if(id1==-1||id2==-1){

            pl("YES");

            return;

        }

        if(id3<id2||id1<id4){

            no();

            return;

        }

        if(id3==n-1||id4==0){

            pl("YES");

            return;

        }else{

            no();

        }

        // pl();

    }

    static int BinarySearch(long ar[], int k) {

        int lo = 0;

        int hi = ar.length - 1;

        int mid;

        int ans = -1;

        while (lo <= hi) {

            mid = lo + ((hi - lo) / 2);

            if (ar[mid] >= k) {

                ans = mid;

                hi = mid - 1;

            } else {

                lo = mid + 1;

            }

        }

        return ans;

    }

    // ------------------------------------------COMMON|FUNCTIONS--------------------------------------------------//

    // -------------BINARYSEARCH-----------//

    // UPPERBOUND find lowest i which satisfy a[i]>=x

    static int upperbound(List<Integer> a, int x) {

        int l = 0;

        int r = a.size() - 1;

        while (l < r) {

            int m = l + (r - l) / 2;

            if (a.get(m) >= x) {

                r = m;

            } else {

                l = m + 1;

            }

        }

        return r;

    }

    static int upperbound(List<Long> a, long x) {

        int l = 0;

        int r = a.size() - 1;

        while (l < r) {

            int m = l + (r - l) / 2;

            if (a.get(m) >= x) {

                r = m;

            } else {

                l = m + 1;

            }

        }

        return r;

    }

    static int upperbound(int[] a, int x) {

        int l = 0;

        int r = a.length - 1;

        while (l < r) {

            int m = l + (r - l) / 2;

            if (a[m] >= x) {

                r = m;

            } else {

                l = m + 1;

            }

        }

        return r;

    }

    static int upperbound(long[] a, long x) {

        int l = 0;

        int r = a.length - 1;

        while (l < r) {

            int m = l + (r - l) / 2;

            if (a[m] >= x) {

                r = m;

            } else {

                l = m + 1;

            }

        }

        return r;

    }

    // LOWERBOUND find highest i which satisfy a[i]<=x

    static int lowerbound(List<Long> a, long x) {

        int l = 0;

        int r = a.size() - 1;

        while (l < r) {

            int m = (l + r + 1) / 2;

            if (a.get(m) <= x) {

                l = m;

            } else {

                r = m - 1;

            }

        }

        return l;

    }

    static int lowerbound(List<Integer> a, int x) {

        int l = 0;

        int r = a.size() - 1;

        while (l < r) {

            int m = (l + r + 1) / 2;

            if (a.get(m) <= x) {

                l = m;

            } else {

                r = m - 1;

            }

        }

        return l;

    }

    static int lowerbound(int[] a, int x) {

        int l = 0;

        int r = a.length - 1;

        while (l < r) {

            int m = (l + r + 1) / 2;

            if (a[m] <= x) {

                l = m;

            } else {

                r = m - 1;

            }

        }

        return l;

    }

    static int lowerbound(long[] a, long x) {

        int l = 0;

        int r = a.length - 1;

        while (l < r) {

            int m = (l + r + 1) / 2;

            if (a[m] <= x) {

                l = m;

            } else {

                r = m - 1;

            }

        }

        return l;

    }

    // -------------BINARYSEARCH-----------//

    // ---------------MATH-----------------//

    public static long fact(int n, int mod) {

        long res = 1;

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

            res = (res * i) % mod;

        }

        return res;

    }

    static int GCD(int a, int b) {

        int dividend = a > b ? a : b;

        int divisor = a < b ? a : b;

        while (divisor > 0) {

            int reminder = dividend % divisor;

            dividend = divisor;

            divisor = reminder;

        }

        return dividend;

    }

    static long GCD(long a, long b) {

        long dividend = a > b ? a : b;

        long divisor = a < b ? a : b;

        while (divisor > 0) {

            long reminder = dividend % divisor;

            dividend = divisor;

            divisor = reminder;

        }

        return dividend;

    }

    static long LCM(int a, int b) {

        return (long) a / GCD(a, b) * b;

    }

    static long LCM(long a, long b) {

        return a / GCD(a, b) * b;

    }

    static long pow(long a, long b, int mod) {

        long pow = 1;

        long x = a;

        while (b != 0) {

            if ((b & 1) != 0) {

                pow = (pow * x) % mod;

            }

            x = (x * x) % mod;

            b /= 2;

        }

        return pow;

    }

    static long pow(long a, long b) {

        long pow = 1;

        long x = a;

        while (b != 0) {

            if ((b & 1) != 0) {

                pow *= x;

            }

            x = x * x;

            b /= 2;

        }

        return pow;

    }

    static long modInverse(long x, int mod) {

        return pow(x, mod - 2, mod);

    }

    static boolean isPrime(long N) {

        if (N <= 1) {

            return false;

        }

        if (N <= 3) {

            return true;

        }

        if (N % 2 == 0 || N % 3 == 0) {

            return false;

        }

        for (int i = 5; i * i <= N; i = i + 6) {

            if (N % i == 0 || N % (i + 2) == 0) {

                return false;

            }

        }

        return true;

    }

    static long log(long a) {

        return (long) (Math.log(a));

    }

    static long log2(long a) {

        return (long) (Math.log(a) / Math.log(2));

    }

    static long sqrt(long x) {

        long start = 0, end = (long) 3e9, ans = 1;

        while (start <= end) {

            long mid = (start + end) / 2;

            if (mid * mid <= x) {

                ans = mid;

                start = mid + 1;

            } else

                end = mid - 1;

        }

        return ans;

    }

    static long ceil(long a, long b) {

        return (a / b) + ((a % b == 0) ? 0 : 1);

    }

    static boolean isPerfectSquare(double number) {

        double sqrt = Math.sqrt(number);

        return ((sqrt - Math.floor(sqrt)) == 0);

    }

    // ---------------MATH-----------------//

    // ---------------CALCS-----------------//

    static long sum(List<Long> a) {

        long sum = 0;

        for (long ele : a)

            sum += ele;

        return sum;

    }

    static long sum(int[] a) {

        long sum = 0;

        for (int ele : a)

            sum += ele;

        return sum;

    }

    static long sum(long[] a) {

        long sum = 0;

        for (long ele : a)

            sum += ele;

        return sum;

    }

    static int maxArray(long a[]) {

        int in = 0;

        long m = a[0];

        for (int i = 1; i < a.length; i++) {

            if (a[i] > m) {

                m = a[i];

                in = i;

            }

        }

        return in;

    }

    static int maxArray(int a[]) {

        int in = 0;

        int m = a[0];

        for (int i = 1; i < a.length; i++) {

            if (a[i] > m) {

                m = a[i];

                in = i;

            }

        }

        return in;

    }

    static int minArray(long a[]) {

        int in = 0;

        long m = a[0];

        for (int i = 1; i < a.length; i++) {

            if (a[i] < m) {

                m = a[i];

                in = i;

            }

        }

        return in;

    }

    static int minArray(int a[]) {

        int in = 0;

        int m = a[0];

        for (int i = 1; i < a.length; i++) {

            if (a[i] < m) {

                m = a[i];

                in = i;

            }

        }

        return in;

    }

    // ---------------CALCS-----------------//

    // ------------------------------------------COMMON|FUNCTIONS--------------------------------------------------//

    // ------------------------------------------MODIFICATIONS--------------------------------------------------//

    static void shuffle(int[] arr) {

        for (int i = 0; i < arr.length; i++) {

            int rand = (int) (Math.random() * arr.length);

            int temp = arr[rand];

            arr[rand] = arr[i];

            arr[i] = temp;

        }

    }

    static void shuffleAndSort(int[] arr) {

        for (int i = 0; i < arr.length; i++) {

            int rand = (int) (Math.random() * arr.length);

            int temp = arr[rand];

            arr[rand] = arr[i];

            arr[i] = temp;

        }

        Arrays.sort(arr);

    }

    static void shuffleAndSort(long[] arr) {

        for (int i = 0; i < arr.length; i++) {

            int rand = (int) (Math.random() * arr.length);

            long temp = arr[rand];

            arr[rand] = arr[i];

            arr[i] = temp;

        }

        Arrays.sort(arr);

    }

    static void swap(int A[], int a, int b) {

        int t = A[a];

        A[a] = A[b];

        A[b] = t;

    }

    static void swap(long A[], int a, int b) {

        long t = A[a];

        A[a] = A[b];

        A[b] = t;

    }

    static void swap(char A[], int a, int b) {

        char t = A[a];

        A[a] = A[b];

        A[b] = t;

    }

    public static String reverse(String str) {

        if (str == null) {

            return null;

        }

        return new StringBuilder(str).reverse().toString();

    }

    public static void reverse(int[] arr) {

        int l = 0;

        int r = arr.length - 1;

        while (l < r) {

            swap(arr, l, r);

            l++;

            r--;

        }

    }

    public static void reverse(long[] arr) {

        int l = 0;

        int r = arr.length - 1;

        while (l < r) {

            swap(arr, l, r);

            l++;

            r--;

        }

    }

    public static String repeat(char ch, int repeat) {

        if (repeat <= 0) {

            return "";

        }

        final char[] buf = new char[repeat];

        for (int i = repeat - 1; i >= 0; i--) {

            buf[i] = ch;

        }

        return new String(buf);

    }

    public static String repeat(char ch[], int repeat) {

        if (repeat <= 0) {

            return "";

        }

        final char[] buf = new char[repeat];

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

            buf[i] = ch[i % ch.length];

        }

        return new String(buf);

    }

    public static String repeat(String ch, int repeat) {

        if (repeat <= 0) {

            return "";

        }

        final char[] buf = new char[repeat];

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

            buf[i] = ch.charAt(i % ch.length());

        }

        return new String(buf);

    }

    static void fillFrequency(Map<Long, Integer> map, long a[]) {

        for (int i = 0; i < a.length; i++) {

            fill(map, a[i]);

        }

    }

    static void fill(Map<Long, Integer> map, long val) {

        if (map.containsKey(val))

            map.put(val, map.get(val) + 1);

        else

            map.put(val, 1);

    }

    static void fillFrequency(Map<Integer, Integer> map, int a[]) {

        for (int i = 0; i < a.length; i++) {

            fill(map, a[i]);

        }

    }

    static void fill(Map<Integer, Integer> map, int val) {

        if (map.containsKey(val))

            map.put(val, map.get(val) + 1);

        else

            map.put(val, 1);

    }

    static void remove(Map<Long, Integer> map, long val) {

        if (map.get(val) == 1)

            map.remove(val);

        else

            map.replace(val, map.get(val) - 1);

    }

    static void remove(Map<Integer, Integer> map, int val) {

        if (map.get(val) == 1)

            map.remove(val);

        else

            map.replace(val, map.get(val) - 1);

    }

    // ------------------------------------------MODIFICATIONS--------------------------------------------------//    // -----------------------------------------------PRECOMPUTE--------------------------------------------------//

    // --------------BITS-----------------//

    static int[][] PrefixBitsCount(int n, int[] a) {

        int pref[][] = new int[n + 1][32];

        // Builds the prefix sums for each bit

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

            for (int j = 0; j < 32; j++) {

                if ((a[i] & (1 << j)) != 0) {

                    pref[i + 1][j] = pref[i][j] + 1;

                } else {

                    pref[i + 1][j] = pref[i][j];

                }

            }

        }

        return pref;

    }

    static int[] prefixAnd(int[] a) {

        int[] pre = new int[a.length];

        pre[0] = a[0];

        for (int i = 1; i < a.length; i++) {

            pre[i] = pre[i - 1] & a[i];

        }

        return pre;

    }

    static int[] prefixOr(int[] a) {

        int[] pre = new int[a.length];

        pre[0] = a[0];

        for (int i = 1; i < a.length; i++) {

            pre[i] = pre[i - 1] | a[i];

        }

        return pre;

    }

    static int[] prefixXor(int[] a) {

        int[] pre = new int[a.length];

        pre[0] = a[0];

        for (int i = 1; i < a.length; i++) {

            pre[i] = pre[i - 1] ^ a[i];

        }

        return pre;

    }

    // --------------BITS-----------------//

    // --------------ARRAYS-----------------//

    static int[] getPrefMax(int arr[]) {

        int n = arr.length;

        int pref[] = new int[n];

        pref[0] = arr[0];

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

            pref[i] = max(arr[i], pref[i - 1]);

        }

        return pref;

    }

    static int[] getPrefMin(int arr[]) {

        int n = arr.length;

        int pref[] = new int[n];

        pref[0] = arr[0];

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

            pref[i] = min(arr[i], pref[i - 1]);

        }

        return pref;

    }

    static int[] getSuffMin(int arr[]) {

        int n = arr.length;

        int suff[] = new int[n];

        suff[n - 1] = arr[n - 1];

        for (int i = n - 2; i >= 0; i--) {

            suff[i] = min(suff[i + 1], arr[i]);

        }

        return suff;

    }

    static long[] prefix(int[] a) {

        long[] pre = new long[a.length + 1];

        pre[0] = 0;

        for (int i = 0; i < a.length; i++) {

            pre[i + 1] = pre[i] + a[i];

        }

        return pre;

    }

    static List<Long> prefix(List<Integer> a) {

        List<Long> pre = new ArrayList<>();

        pre.add(0l);

        for (int i = 0; i < a.size(); i++) {

            pre.add(pre.get(i) + a.get(i));

        }

        return pre;

    }

    static long[] prefix(long[] a) {

        long[] pre = new long[a.length + 1];

        pre[0] = 0;

        for (int i = 0; i < a.length; i++) {

            pre[i + 1] = pre[i] + a[i];

        }

        return pre;

    }

    static long[] suffix(int[] a) {

        long[] post = new long[a.length + 1];

        post[a.length] = 0;

        for (int i = a.length - 1; i >= 0; i++) {

            post[i] = post[i + 1] + a[i];

        }

        return post;

    }

    static long[] suffix(long[] a) {

        long[] post = new long[a.length + 1];

        post[a.length] = 0;

        for (int i = a.length - 1; i >= 0; i++) {

            post[i] = post[i + 1] + a[i];

        }

        return post;

    }

    // --------------ARRAYS-----------------//

    // --------------Sieve&Factors-----------------//

    static List<Integer> sieveOfEratosthenes(int n) {

        List<Integer> primeList = new ArrayList<>();

        boolean prime[] = new boolean[n + 1];

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

            prime[i] = true;

        for (int p = 2; p * p <= n; p++) {

            if (prime[p] == true) {

                for (int i = p * p; i <= n; i += p)

                    prime[i] = false;

            }

        }

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

            if (prime[i] == true)

                primeList.add(i);

            // System.out.print(i + " ");

        }

        return primeList;

    }

    static List<Integer> allDivisors(int n) {

        List<Integer> divisoers = new ArrayList<>();

        for (int i = 1; i * i <= n; i++) {

            if (n % i == 0) {

                divisoers.add(i);

                if (i != n / i) {

                    divisoers.add(n / i);

                }

            }

        }

        return divisoers;

    }

    // --------------Sieve&Factors-----------------//

    // -----------------------------------------------PRECOMPUTE--------------------------------------------------//

    // ---------------------------------------------INPUT&OUTPUT--------------------------------------------------//

    static int i() {

        return in.nextInt();

    }

    static long l() {

        return in.nextLong();

    }

    static double d() {

        return in.nextDouble();

    }

    static String s() {

        return in.nextLine();

    }

    static ArrayList<Integer> inputList(int n) {

        ArrayList<Integer> a = new ArrayList<Integer>(n);

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

            a.add(i());

        return a;

    }

    static ArrayList<Long> inputListLong(int n) {

        ArrayList<Long> a = new ArrayList<Long>(n);

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

            a.add(l());

        return a;

    }

    static int[][] inputWithIdx(int N) {

        int A[][] = new int[N][2];

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

            A[i] = new int[] { in.nextInt(), i };

        }

        return A;

    }

    static int[][] inputMatrix(int N, int M) {

        int A[][] = new int[N][M];

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

            for (int j = 0; j < M; j++) {

                A[i][j] = i();

            }

        }

        return A;

    }

    static long[][] inputMatrixLong(int N, int M) {

        long A[][] = new long[N][M];

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

            for (int j = 0; j < M; j++) {

                A[i][j] = i();

            }

        }

        return A;

    }

    static int[] input(int N) {

        int A[] = new int[N];

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

            A[i] = in.nextInt();

        }

        return A;

    }

    static Integer[] inputWrapper(int N) {

        Integer A[] = new Integer[N];

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

            A[i] = in.nextInt();

        }

        return A;

    }

    static long[] inputLong(int N) {

        long A[] = new long[N];

        for (int i = 0; i < A.length; i++) {

            A[i] = in.nextLong();

        }

        return A;

    }

    static void p(String s) {

        out.print(s);

    }

    static void p(int s) {

        out.print(s);

    }

    static void p(long s) {

        out.print(s);

    }

    static void p(double s) {

        out.print(s);

    }

    static void p(char s) {

        out.print(s);

    }

    static void pl(String s) {

        out.println(s);

    }

    static void pl(int s) {

        out.println(s);

    }

    static void pl(long s) {

        out.println(s);

    }

    static void pl(double s) {

        out.println(s);

    }

    static void pl(char c) {

        out.println(c);

    }

    static void pl() {

        out.println();

    }

    static void pl(int[] o) {

        for (int i = 0; i < o.length; i++) {

            out.print(o[i] + " ");

        }

        out.println();

    }

    static void pl(long[] o) {

        for (int i = 0; i < o.length; i++) {

            out.print(o[i] + " ");

        }

        out.println();

    }

    static <T> void pl(T[] o) {

        for (int i = 0; i < o.length; i++) {

            out.print(o[i] + " ");

        }

        out.println();

    }

    static <T> void pl(List<T> A) {

        for (T a : A) {

            out.print(a + " ");

        }

        out.println();

    }

    static void pl(Object o) {

        out.println(o);

    }

    static void ps(int s) {

        out.print(s + " ");

    }

    static void ps(long s) {

        out.print(s + " ");

    }

    static void ps(double s) {

        out.print(s + " ");

    }

    static void ps(char c) {

        out.print(c + " ");

    }

    static void yes() {

        pl("YES");

    }

    static void no() {

        pl("NO");

    }

    // ---------------------------------------------INPUT&OUTPUT--------------------------------------------------//

}

  class FastReader {

    BufferedReader br;

    StringTokenizer st;

    public FastReader() {

        br = new BufferedReader(new InputStreamReader(System.in));

    }

    String next() {

        while (st == null || !st.hasMoreElements()) {

            try {

                st = new StringTokenizer(br.readLine());

            } catch (IOException e) {

                e.printStackTrace();

            }

        }

        return st.nextToken();

    }

    char nextChar() {

        return next().charAt(0);

    }

    int nextInt() {

        return Integer.parseInt(next());

    }

    long nextLong() {

        return Long.parseLong(next());

    }

    double nextDouble() {

        return Double.parseDouble(next());

    }

    String nextLine() {

        String str = "";

        try {

            str = br.readLine();

        } catch (IOException e) {

            e.printStackTrace();

        }

        return str;

    }

}

import static java.lang.Math.max;

import static java.lang.Math.min;

import static java.lang.Math.abs;

import java.util.*;

import java.io.*;

import java.math.*;

public final class Main {

    static PrintWriter out = new PrintWriter(System.out);

    static FastReader in = new FastReader();

    static final int MOD1 = (int) (1e9 + 7);

    static final int MOD2 = 998244353;

    static final int inf = Integer.MAX_VALUE;

    static final int minf = Integer.MIN_VALUE;

    static final long linf = 1L << 62;

    public static void main(String[] args){

        int tt = i();

        while (tt-- > 0) {

            solve();

        }

        out.flush();

    }

    public static void solve(){

        // int MIN = -1*(int) 1e9;

        // int MAX = (int) 1e9;

        // PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());

        int n = i();

        String s = s();

        // int ar[]=input(n);

        // int ar[] = new int[n];

        int id1=-1,id2=-1,id3=-1,id4=-1;

        int c1=0,c2=0;

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

            if(s.charAt(i)=='p'){

                if(id3==-1)id3=i;

                id1=i;

                c1++;

            }

            if(s.charAt(i)=='s'){

                if(id4==-1)id4=i;

                id2=i;

                c2++;

            }

        }

        if(id1==-1||id2==-1){

            pl("YES");

            return;

        }

        if(c1>1&&c2>1){

            pl("NO");

            return;

        }

        if(c1>1){

            if(id2==0)yes();

            else no();

            return;

        }else if(c2>1){

            if(id1==n-1)yes();

            else no();

            return;

        }else{

            if(id2==0||id1==n-1)yes();

            else no();

        }

        // pl();

    }

    static int BinarySearch(long ar[], int k) {

        int lo = 0;

        int hi = ar.length - 1;

        int mid;

        int ans = -1;

        while (lo <= hi) {

            mid = lo + ((hi - lo) / 2);

            if (ar[mid] >= k) {

                ans = mid;

                hi = mid - 1;

            } else {

                lo = mid + 1;

            }

        }

        return ans;

    }

    // ------------------------------------------COMMON|FUNCTIONS--------------------------------------------------//

    // -------------BINARYSEARCH-----------//

    // UPPERBOUND find lowest i which satisfy a[i]>=x

    static int upperbound(List<Integer> a, int x) {

        int l = 0;

        int r = a.size() - 1;

        while (l < r) {

            int m = l + (r - l) / 2;

            if (a.get(m) >= x) {

                r = m;

            } else {

                l = m + 1;

            }

        }

        return r;

    }

    static int upperbound(List<Long> a, long x) {

        int l = 0;

        int r = a.size() - 1;

        while (l < r) {

            int m = l + (r - l) / 2;

            if (a.get(m) >= x) {

                r = m;

            } else {

                l = m + 1;

            }

        }

        return r;

    }

    static int upperbound(int[] a, int x) {

        int l = 0;

        int r = a.length - 1;

        while (l < r) {

            int m = l + (r - l) / 2;

            if (a[m] >= x) {

                r = m;

            } else {

                l = m + 1;

            }

        }

        return r;

    }

    static int upperbound(long[] a, long x) {

        int l = 0;

        int r = a.length - 1;

        while (l < r) {

            int m = l + (r - l) / 2;

            if (a[m] >= x) {

                r = m;

            } else {

                l = m + 1;

            }

        }

        return r;

    }

    // LOWERBOUND find highest i which satisfy a[i]<=x

    static int lowerbound(List<Long> a, long x) {

        int l = 0;

        int r = a.size() - 1;

        while (l < r) {

            int m = (l + r + 1) / 2;

            if (a.get(m) <= x) {

                l = m;

            } else {

                r = m - 1;

            }

        }

        return l;

    }

    static int lowerbound(List<Integer> a, int x) {

        int l = 0;

        int r = a.size() - 1;

        while (l < r) {

            int m = (l + r + 1) / 2;

            if (a.get(m) <= x) {

                l = m;

            } else {

                r = m - 1;

            }

        }

        return l;

    }

    static int lowerbound(int[] a, int x) {

        int l = 0;

        int r = a.length - 1;

        while (l < r) {

            int m = (l + r + 1) / 2;

            if (a[m] <= x) {

                l = m;

            } else {

                r = m - 1;

            }

        }

        return l;

    }

    static int lowerbound(long[] a, long x) {

        int l = 0;

        int r = a.length - 1;

        while (l < r) {

            int m = (l + r + 1) / 2;

            if (a[m] <= x) {

                l = m;

            } else {

                r = m - 1;

            }

        }

        return l;

    }

    // -------------BINARYSEARCH-----------//

    // ---------------MATH-----------------//

    public static long fact(int n, int mod) {

        long res = 1;

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

            res = (res * i) % mod;

        }

        return res;

    }

    static int GCD(int a, int b) {

        int dividend = a > b ? a : b;

        int divisor = a < b ? a : b;

        while (divisor > 0) {

            int reminder = dividend % divisor;

            dividend = divisor;

            divisor = reminder;

        }

        return dividend;

    }

    static long GCD(long a, long b) {

        long dividend = a > b ? a : b;

        long divisor = a < b ? a : b;

        while (divisor > 0) {

            long reminder = dividend % divisor;

            dividend = divisor;

            divisor = reminder;

        }

        return dividend;

    }

    static long LCM(int a, int b) {

        return (long) a / GCD(a, b) * b;

    }

    static long LCM(long a, long b) {

        return a / GCD(a, b) * b;

    }

    static long pow(long a, long b, int mod) {

        long pow = 1;

        long x = a;

        while (b != 0) {

            if ((b & 1) != 0) {

                pow = (pow * x) % mod;

            }

            x = (x * x) % mod;

            b /= 2;

        }

        return pow;

    }

    static long pow(long a, long b) {

        long pow = 1;

        long x = a;

        while (b != 0) {

            if ((b & 1) != 0) {

                pow *= x;

            }

            x = x * x;

            b /= 2;

        }

        return pow;

    }

    static long modInverse(long x, int mod) {

        return pow(x, mod - 2, mod);

    }

    static boolean isPrime(long N) {

        if (N <= 1) {

            return false;

        }

        if (N <= 3) {

            return true;

        }

        if (N % 2 == 0 || N % 3 == 0) {

            return false;

        }

        for (int i = 5; i * i <= N; i = i + 6) {

            if (N % i == 0 || N % (i + 2) == 0) {

                return false;

            }

        }

        return true;

    }

    static long log(long a) {

        return (long) (Math.log(a));

    }

    static long log2(long a) {

        return (long) (Math.log(a) / Math.log(2));

    }

    static long sqrt(long x) {

        long start = 0, end = (long) 3e9, ans = 1;

        while (start <= end) {

            long mid = (start + end) / 2;

            if (mid * mid <= x) {

                ans = mid;

                start = mid + 1;

            } else

                end = mid - 1;

        }

        return ans;

    }

    static long ceil(long a, long b) {

        return (a / b) + ((a % b == 0) ? 0 : 1);

    }

    static boolean isPerfectSquare(double number) {

        double sqrt = Math.sqrt(number);

        return ((sqrt - Math.floor(sqrt)) == 0);

    }

    // ---------------MATH-----------------//

    // ---------------CALCS-----------------//

    static long sum(List<Long> a) {

        long sum = 0;

        for (long ele : a)

            sum += ele;

        return sum;

    }

    static long sum(int[] a) {

        long sum = 0;

        for (int ele : a)

            sum += ele;

        return sum;

    }

    static long sum(long[] a) {

        long sum = 0;

        for (long ele : a)

            sum += ele;

        return sum;

    }

    static int maxArray(long a[]) {

        int in = 0;

        long m = a[0];

        for (int i = 1; i < a.length; i++) {

            if (a[i] > m) {

                m = a[i];

                in = i;

            }

        }

        return in;

    }

    static int maxArray(int a[]) {

        int in = 0;

        int m = a[0];

        for (int i = 1; i < a.length; i++) {

            if (a[i] > m) {

                m = a[i];

                in = i;

            }

        }

        return in;

    }

    static int minArray(long a[]) {

        int in = 0;

        long m = a[0];

        for (int i = 1; i < a.length; i++) {

            if (a[i] < m) {

                m = a[i];

                in = i;

            }

        }

        return in;

    }

    static int minArray(int a[]) {

        int in = 0;

        int m = a[0];

        for (int i = 1; i < a.length; i++) {

            if (a[i] < m) {

                m = a[i];

                in = i;

            }

        }

        return in;

    }

    // ---------------CALCS-----------------//

    // ------------------------------------------COMMON|FUNCTIONS--------------------------------------------------//

    // ------------------------------------------MODIFICATIONS--------------------------------------------------//

    static void shuffle(int[] arr) {

        for (int i = 0; i < arr.length; i++) {

            int rand = (int) (Math.random() * arr.length);

            int temp = arr[rand];

            arr[rand] = arr[i];

            arr[i] = temp;

        }

    }

    static void shuffleAndSort(int[] arr) {

        for (int i = 0; i < arr.length; i++) {

            int rand = (int) (Math.random() * arr.length);

            int temp = arr[rand];

            arr[rand] = arr[i];

            arr[i] = temp;

        }

        Arrays.sort(arr);

    }

    static void shuffleAndSort(long[] arr) {

        for (int i = 0; i < arr.length; i++) {

            int rand = (int) (Math.random() * arr.length);

            long temp = arr[rand];

            arr[rand] = arr[i];

            arr[i] = temp;

        }

        Arrays.sort(arr);

    }

    static void swap(int A[], int a, int b) {

        int t = A[a];

        A[a] = A[b];

        A[b] = t;

    }

    static void swap(long A[], int a, int b) {

        long t = A[a];

        A[a] = A[b];

        A[b] = t;

    }

    static void swap(char A[], int a, int b) {

        char t = A[a];

        A[a] = A[b];

        A[b] = t;

    }

    public static String reverse(String str) {

        if (str == null) {

            return null;

        }

        return new StringBuilder(str).reverse().toString();

    }

    public static void reverse(int[] arr) {

        int l = 0;

        int r = arr.length - 1;

        while (l < r) {

            swap(arr, l, r);

            l++;

            r--;

        }

    }

    public static void reverse(long[] arr) {

        int l = 0;

        int r = arr.length - 1;

        while (l < r) {

            swap(arr, l, r);

            l++;

            r--;

        }

    }

    public static String repeat(char ch, int repeat) {

        if (repeat <= 0) {

            return "";

        }

        final char[] buf = new char[repeat];

        for (int i = repeat - 1; i >= 0; i--) {

            buf[i] = ch;

        }

        return new String(buf);

    }

    public static String repeat(char ch[], int repeat) {

        if (repeat <= 0) {

            return "";

        }

        final char[] buf = new char[repeat];

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

            buf[i] = ch[i % ch.length];

        }

        return new String(buf);

    }

    public static String repeat(String ch, int repeat) {

        if (repeat <= 0) {

            return "";

        }

        final char[] buf = new char[repeat];

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

            buf[i] = ch.charAt(i % ch.length());

        }

        return new String(buf);

    }

    static void fillFrequency(Map<Long, Integer> map, long a[]) {

        for (int i = 0; i < a.length; i++) {

            fill(map, a[i]);

        }

    }

    static void fill(Map<Long, Integer> map, long val) {

        if (map.containsKey(val))

            map.put(val, map.get(val) + 1);

        else

            map.put(val, 1);

    }

    static void fillFrequency(Map<Integer, Integer> map, int a[]) {

        for (int i = 0; i < a.length; i++) {

            fill(map, a[i]);

        }

    }

    static void fill(Map<Integer, Integer> map, int val) {

        if (map.containsKey(val))

            map.put(val, map.get(val) + 1);

        else

            map.put(val, 1);

    }

    static void remove(Map<Long, Integer> map, long val) {

        if (map.get(val) == 1)

            map.remove(val);

        else

            map.replace(val, map.get(val) - 1);

    }

    static void remove(Map<Integer, Integer> map, int val) {

        if (map.get(val) == 1)

            map.remove(val);

        else

            map.replace(val, map.get(val) - 1);

    }

    // ------------------------------------------MODIFICATIONS--------------------------------------------------//    // -----------------------------------------------PRECOMPUTE--------------------------------------------------//

    // --------------BITS-----------------//

    static int[][] PrefixBitsCount(int n, int[] a) {

        int pref[][] = new int[n + 1][32];

        // Builds the prefix sums for each bit

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

            for (int j = 0; j < 32; j++) {

                if ((a[i] & (1 << j)) != 0) {

                    pref[i + 1][j] = pref[i][j] + 1;

                } else {

                    pref[i + 1][j] = pref[i][j];

                }

            }

        }

        return pref;

    }

    static int[] prefixAnd(int[] a) {

        int[] pre = new int[a.length];

        pre[0] = a[0];

        for (int i = 1; i < a.length; i++) {

            pre[i] = pre[i - 1] & a[i];

        }

        return pre;

    }

    static int[] prefixOr(int[] a) {

        int[] pre = new int[a.length];

        pre[0] = a[0];

        for (int i = 1; i < a.length; i++) {

            pre[i] = pre[i - 1] | a[i];

        }

        return pre;

    }

    static int[] prefixXor(int[] a) {

        int[] pre = new int[a.length];

        pre[0] = a[0];

        for (int i = 1; i < a.length; i++) {

            pre[i] = pre[i - 1] ^ a[i];

        }

        return pre;

    }

    // --------------BITS-----------------//

    // --------------ARRAYS-----------------//

    static int[] getPrefMax(int arr[]) {

        int n = arr.length;

        int pref[] = new int[n];

        pref[0] = arr[0];

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

            pref[i] = max(arr[i], pref[i - 1]);

        }

        return pref;

    }

    static int[] getPrefMin(int arr[]) {

        int n = arr.length;

        int pref[] = new int[n];

        pref[0] = arr[0];

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

            pref[i] = min(arr[i], pref[i - 1]);

        }

        return pref;

    }

    static int[] getSuffMin(int arr[]) {

        int n = arr.length;

        int suff[] = new int[n];

        suff[n - 1] = arr[n - 1];

        for (int i = n - 2; i >= 0; i--) {

            suff[i] = min(suff[i + 1], arr[i]);

        }

        return suff;

    }

    static long[] prefix(int[] a) {

        long[] pre = new long[a.length + 1];

        pre[0] = 0;

        for (int i = 0; i < a.length; i++) {

            pre[i + 1] = pre[i] + a[i];

        }

        return pre;

    }

    static List<Long> prefix(List<Integer> a) {

        List<Long> pre = new ArrayList<>();

        pre.add(0l);

        for (int i = 0; i < a.size(); i++) {

            pre.add(pre.get(i) + a.get(i));

        }

        return pre;

    }

    static long[] prefix(long[] a) {

        long[] pre = new long[a.length + 1];

        pre[0] = 0;

        for (int i = 0; i < a.length; i++) {

            pre[i + 1] = pre[i] + a[i];

        }

        return pre;

    }

    static long[] suffix(int[] a) {

        long[] post = new long[a.length + 1];

        post[a.length] = 0;

        for (int i = a.length - 1; i >= 0; i++) {

            post[i] = post[i + 1] + a[i];

        }

        return post;

    }

    static long[] suffix(long[] a) {

        long[] post = new long[a.length + 1];

        post[a.length] = 0;

        for (int i = a.length - 1; i >= 0; i++) {

            post[i] = post[i + 1] + a[i];

        }

        return post;

    }

    // --------------ARRAYS-----------------//

    // --------------Sieve&Factors-----------------//

    static List<Integer> sieveOfEratosthenes(int n) {

        List<Integer> primeList = new ArrayList<>();

        boolean prime[] = new boolean[n + 1];

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

            prime[i] = true;

        for (int p = 2; p * p <= n; p++) {

            if (prime[p] == true) {

                for (int i = p * p; i <= n; i += p)

                    prime[i] = false;

            }

        }

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

            if (prime[i] == true)

                primeList.add(i);

            // System.out.print(i + " ");

        }

        return primeList;

    }

    static List<Integer> allDivisors(int n) {

        List<Integer> divisoers = new ArrayList<>();

        for (int i = 1; i * i <= n; i++) {

            if (n % i == 0) {

                divisoers.add(i);

                if (i != n / i) {

                    divisoers.add(n / i);

                }

            }

        }

        return divisoers;

    }

    // --------------Sieve&Factors-----------------//

    // -----------------------------------------------PRECOMPUTE--------------------------------------------------//

    // ---------------------------------------------INPUT&OUTPUT--------------------------------------------------//

    static int i() {

        return in.nextInt();

    }

    static long l() {

        return in.nextLong();

    }

    static double d() {

        return in.nextDouble();

    }

    static String s() {

        return in.nextLine();

    }

    static ArrayList<Integer> inputList(int n) {

        ArrayList<Integer> a = new ArrayList<Integer>(n);

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

            a.add(i());

        return a;

    }

    static ArrayList<Long> inputListLong(int n) {

        ArrayList<Long> a = new ArrayList<Long>(n);

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

            a.add(l());

        return a;

    }

    static int[][] inputWithIdx(int N) {

        int A[][] = new int[N][2];

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

            A[i] = new int[] { in.nextInt(), i };

        }

        return A;

    }

    static int[][] inputMatrix(int N, int M) {

        int A[][] = new int[N][M];

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

            for (int j = 0; j < M; j++) {

                A[i][j] = i();

            }

        }

        return A;

    }

    static long[][] inputMatrixLong(int N, int M) {

        long A[][] = new long[N][M];

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

            for (int j = 0; j < M; j++) {

                A[i][j] = i();

            }

        }

        return A;

    }

    static int[] input(int N) {

        int A[] = new int[N];

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

            A[i] = in.nextInt();

        }

        return A;

    }

    static Integer[] inputWrapper(int N) {

        Integer A[] = new Integer[N];

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

            A[i] = in.nextInt();

        }

        return A;

    }

    static long[] inputLong(int N) {

        long A[] = new long[N];

        for (int i = 0; i < A.length; i++) {

            A[i] = in.nextLong();

        }

        return A;

    }

    static void p(String s) {

        out.print(s);

    }

    static void p(int s) {

        out.print(s);

    }

    static void p(long s) {

        out.print(s);

    }

    static void p(double s) {

        out.print(s);

    }

    static void p(char s) {

        out.print(s);

    }

    static void pl(String s) {

        out.println(s);

    }

    static void pl(int s) {

        out.println(s);

    }

    static void pl(long s) {

        out.println(s);

    }

    static void pl(double s) {

        out.println(s);

    }

    static void pl(char c) {

        out.println(c);

    }

    static void pl() {

        out.println();

    }

    static void pl(int[] o) {

        for (int i = 0; i < o.length; i++) {

            out.print(o[i] + " ");

        }

        out.println();

    }

    static void pl(long[] o) {

        for (int i = 0; i < o.length; i++) {

            out.print(o[i] + " ");

        }

        out.println();

    }

    static <T> void pl(T[] o) {

        for (int i = 0; i < o.length; i++) {

            out.print(o[i] + " ");

        }

        out.println();

    }

    static <T> void pl(List<T> A) {

        for (T a : A) {

            out.print(a + " ");

        }

        out.println();

    }

    static void pl(Object o) {

        out.println(o);

    }

    static void ps(int s) {

        out.print(s + " ");

    }

    static void ps(long s) {

        out.print(s + " ");

    }

    static void ps(double s) {

        out.print(s + " ");

    }

    static void ps(char c) {

        out.print(c + " ");

    }

    static void yes() {

        pl("YES");

    }

    static void no() {

        pl("NO");

    }

    // ---------------------------------------------INPUT&OUTPUT--------------------------------------------------//

}

  class FastReader {

    BufferedReader br;

    StringTokenizer st;

    public FastReader() {

        br = new BufferedReader(new InputStreamReader(System.in));

    }

    String next() {

        while (st == null || !st.hasMoreElements()) {

            try {

                st = new StringTokenizer(br.readLine());

            } catch (IOException e) {

                e.printStackTrace();

            }

        }

        return st.nextToken();

    }

    char nextChar() {

        return next().charAt(0);

    }

    int nextInt() {

        return Integer.parseInt(next());

    }

    long nextLong() {

        return Long.parseLong(next());

    }

    double nextDouble() {

        return Double.parseDouble(next());

    }

    String nextLine() {

        String str = "";

        try {

            str = br.readLine();

        } catch (IOException e) {

            e.printStackTrace();

        }

        return str;

    }

}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

typedef pair<int, int> pii;

typedef pair<double, double> pdd;

typedef pair<long long, long long> pll;

typedef vector<int> vi;

typedef vector<long long> vll;

typedef map<int, int> mii;

typedef vector<vector<int>> vvi;

typedef vector<vector<long long>> vvll;

#define f(i, a, b, j) for(int i = int(a); i < int(b); i = i + int(j))

#define M map

#define V vector

#define P pair

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

#define rall(a) a.rbegin(), a.rend()

#define nl "\n"

#define pb push_back

#define mp make_pair

#define reset(a, b) memset(a, int(b), sizeof(a))

#define MOD1 (ll)1000000007

#define MOD2 (ll)998244353

ll mod = MOD1;

ll power(ll a,ll b){

    ll res = 1;

    while(b){

        if(b & 1){

            res *= a;

            res %= mod;

        }

        a *= a;

        a %= mod;

         b >>= 1;

    }

    return res;

}

ll inverse(ll a){

    return power(a,mod - 2);

}

void solve(){

    ll n;

    cin >> n;

    string s;

    cin >> s;

    // p before s (not possible)

    ll r_s = n;

    for(int i = n - 1; i >= 0; i--){

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

            r_s = i;

            break;

        }

    }

    if(r_s == n){

        cout << "YES" << nl;

        return;

    }

    ll l_p = -1;

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

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

            l_p = i;

            break;

        }

    }

    if(l_p == -1){

        cout << "YES" << nl;

        return;

    }

    if(l_p < r_s){

        cout << "NO" << nl;

        return;

    }

    ll count_s = 0;

    ll count_p = 0;

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

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

            count_s++;

        }

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

            count_p++;

        }

    }

    if(count_s > 1 and count_p > 1){

        cout << "NO" << nl;

        return;

    }

    if(count_s == 1 and count_p == 1){

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

            cout << "NO" << nl;

            return;

        }

        cout << "YES" << nl;

        return;

    }

    if(count_s == 1){

        // more than one p

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

            cout << "NO" << nl;

            return;

        }

        cout << "YES" << nl;

        return;

    }

    // count_p == 1

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

        cout << "NO" << nl;

        return;

    }

    cout << "YES" << nl;

    return;

}

int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    ll t;

    cin >> t;

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

        solve();

    }

    return 0;

}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

typedef pair<int, int> pii;

typedef pair<double, double> pdd;

typedef pair<long long, long long> pll;

typedef vector<int> vi;

typedef vector<long long> vll;

typedef map<int, int> mii;

typedef vector<vector<int>> vvi;

typedef vector<vector<long long>> vvll;

#define f(i, a, b, j) for(int i = int(a); i < int(b); i = i + int(j))

#define M map

#define V vector

#define P pair

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

#define rall(a) a.rbegin(), a.rend()

#define nl "\n"

#define pb push_back

#define mp make_pair

#define reset(a, b) memset(a, int(b), sizeof(a))

#define MOD1 (ll)1000000007

#define MOD2 (ll)998244353

ll mod = MOD1;

ll power(ll a,ll b){

    ll res = 1;

    while(b){

        if(b & 1){

            res *= a;

            res %= mod;

        }

        a *= a;

        a %= mod;

         b >>= 1;

    }

    return res;

}

ll inverse(ll a){

    return power(a,mod - 2);

}

void solve(){

    ll n;

    cin >> n;

    string s;

    cin >> s;

    // p before s (not possible)

    ll r_s = n;

    for(int i = n - 1; i >= 0; i--){

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

            r_s = i;

            break;

        }

    }

    if(r_s == n){

        cout << "YES" << nl;

        return;

    }

    ll l_p = -1;

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

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

            l_p = i;

            break;

        }

    }

    if(l_p == -1){

        cout << "YES" << nl;

        return;

    }

    if(l_p < r_s){

        cout << "NO" << nl;

        return;

    }

    ll count_s = 0;

    ll count_p = 0;

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

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

            count_s++;

        }

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

            count_p++;

        }

    }

    if(count_s > 1 and count_p > 1){

        cout << "NO" << nl;

        return;

    }

    if(count_s == 1){

        // more than one p

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

            cout << "NO" << nl;

            return;

        }

        cout << "YES" << nl;

        return;

    }

    // count_p == 1

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

        cout << "NO" << nl;

        return;

    }

    cout << "YES" << nl;

    return;

}

int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    ll t;

    cin >> t;

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

        solve();

    }

    return 0;

}

Answer: 1


 #include <bits/stdc++.h>

#define int long long //二维数组可能会爆

#define pll pair<int,int>

#define INF 0x3f3f3f3f3f3f3f3f

using namespace std;

#define IOS ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);

const int N=1e6+7;

const int mod=1e9+7;

void solve(){

    int n;

    cin>>n;

    string s;

    cin>>s;

    bool ok=1;

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

    	for(int j=0;j<n;j++)

    	{

    		if(s[i]=='p' && s[j]=='s' )

    		{

    			if(!(i==n-1 || j==0))ok=0;

    		}

    	}

    if(ok)

    {

    	cout<<"YES"<<endl;

    }

    else cout<<"NO"<<endl;

    return ;

}

signed main (){

    IOS;

    int _;

    cin>>_;

    while(_--){

        solve();

    }

    return 0;

}

/*

*/

 #include <bits/stdc++.h>

#define int long long //二维数组可能会爆

#define pll pair<int,int>

#define INF 0x3f3f3f3f3f3f3f3f

using namespace std;

#define IOS ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);

const int N=1e6+7;

const int mod=1e9+7;

void solve(){

    int n;

    cin>>n;

    string s;

    cin>>s;

    bool ok=0;

    int cnts=0,cntp=0,cntd=0;

    for(int i=0;i<s.size();i++)

    {

        if(s[i]=='s')cnts++;

        else if(s[i]=='p')cntp++;

        else cntd++;

    }

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

    {

    	int idxp=0,idxs=0;

    	for(int i=1;i<s.size();i++)

    	{

            if(s[i]=='s')idxs=i;

            if(s[i]=='p' && idxp==0)idxp=i;

    	}

    	if(idxs<idxp)ok=1;

    }

    if(cnts*cntp==0 || ok)

    {

    	cout<<"YES"<<endl;

    }

    else cout<<"NO"<<endl;

    return ;

}

signed main (){

    IOS;

    int _;

    cin>>_;

    while(_--){

        solve();

    }

    return 0;

}

/*

*/

Answer: 1


#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;
}

#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;
    }

    int i=0;int j = 0 ;
    while(i<n){
        if(i=='.'){
            i++;
            continue;
        }

        if(i==n-1){
            yy;
            return;
        }

        j=i+1;
        while(j<n && s[j]=='.') j++;
        if(j==n) {
            yy;
            return;
        }

        if(s[i]==s[j]){
            i=j;continue;
        }

        if(i==0 || i==n-2){
            if(s[i]!='s'){
                nn;
                return;
            }

        }else{
            nn;
            return;
        }
        i++;
    }
    yy;

}

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

    solve();

    }
    return 0;
}

Answer: 1


#include <bits/stdc++.h>

using namespace std;

#define fastIO()                              \

    do {                                      \

        ios::sync_with_stdio(false);         \

        cin.tie(NULL);                        \

        cout.tie(NULL);                       \

    } while (0)

void solve() {

    int n;

    cin >> n;

    string s;

    cin >> s;

    map<char,int> m;

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

        m[s[i]]++;

    }

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

        m['s']--;

        m['.']++;

    }

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

        m['p']--;

        m['.']++;

    }

    if(m['s']+m['.']==n || m['p']+m['.']==n ) cout << "YES" << endl;

    else cout << "NO" << endl;

}

int main() {

    fastIO();

    int tc;

    cin >> tc;

    while (tc--) {

        solve();

    }

    return 0;

}

#include <bits/stdc++.h>

using namespace std;

#define fastIO()                              \

    do {                                      \

        ios::sync_with_stdio(false);         \

        cin.tie(NULL);                        \

        cout.tie(NULL);                       \

    } while (0)

void solve() {

    int n;

    cin >> n;

    string s;

    cin >> s;

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

        cout << "YES" << endl;

        return;

    }

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

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

            cout << "NO" << endl;

            return;

        }

    }

    cout << "YES" << endl;

}

int main() {

    fastIO();

    int tc;

    cin >> tc;

    while (tc--) {

        solve();

    }

    return 0;

}

Answer: 1


#include <iostream>

#include <vector>

#include <string>

#include <set>

#include <math.h>

#include <cmath>

#include <map>

#include <algorithm>

#include <iterator>

#include <queue>

#include <queue>

#include <stack>

#include <deque>

#include <unordered_map>

#include <unordered_set>

#include <iomanip>

using namespace std;

#pragma GCC target("avx2")

using ll = long long;

using ii = pair<int, int>;

using vi = int;

using vl = vector<ll>;

using pll = pair<ll, ll>;

using dd = pair<double, double>;

using db = double;

#define int long long

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

#define X first

#define Y second

#define endl "\n"

#define mod 998244353

void solve() {

    int n;

    cin>>n;

    string s;

    cin>>s;

    vector<int> a,b;

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

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

            a.push_back(i);

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

            b.push_back(i);

    }

    if (min(a.size(),b.size())==0){

        cout<<"YES"<<endl;

        return;

    }else{

        if (min(a.size(),b.size())>1){

            cout<<"NO"<<endl;

        }else{

            if (a.size()==1 and a[0]==0 or b.size()==1 and b.back()==n-1)

                cout<<"YES"<<endl;

            else{

                cout<<"NO"<<endl;

            }

        }

    }

}

signed main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    ll tt = 1;

    cin >> tt;

    while (tt--)

        solve();

}

#include <iostream>

#include <vector>

#include <string>

#include <set>

#include <math.h>

#include <cmath>

#include <map>

#include <algorithm>

#include <iterator>

#include <queue>

#include <queue>

#include <stack>

#include <deque>

#include <unordered_map>

#include <unordered_set>

#include <iomanip>

using namespace std;

#pragma GCC target("avx2")

using ll = long long;

using ii = pair<int, int>;

using vi = int;

using vl = vector<ll>;

using pll = pair<ll, ll>;

using dd = pair<double, double>;

using db = double;

#define int long long

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

#define X first

#define Y second

#define endl "\n"

#define mod 998244353

void solve() {

    int n;

    cin>>n;

    string s;

    cin>>s;

    vector<int> a={-1},b;

    cin>>s;

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

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

            a.push_back(i);

        else if (s[i]=='b')

            b.push_back(i);

    }

    b.push_back(n+1);

    if (a.back()<b[0]){

        cout<<"YES"<<endl;

    }else{

        cout<<"NO"<<endl;

    }

}

signed main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    ll tt = 1;

    cin >> tt;

    while (tt--)

        solve();

}

Answer: 1