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

Solution 1 (runtime: 46 ms):
#include <algorithm>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <unordered_set>
#include <utility>
#include <limits.h>
#include <climits>
#include <numeric>
#include <map>
#include <unordered_map>
#include <cfloat>
#define ll long long
#define int long long
#define DEBUG false
using namespace std;


void debug(string s) {
    if (DEBUG) cout << s << endl;
}

void debug(int s) {
    if (DEBUG) cout << s << endl;
}

void debug(vector<vector<int> > & v) {
    if (!DEBUG) return;
    for (int i = 0; i != v.size(); ++i) {
        for (int j = 0; j != v[i].size(); ++j) {
            cout << v[i][j] << " ";
        }
        cout << endl;
    }
}

//flat debug of vector of vectors
void fdebug(vector<vector<int> > & v) {
    if (!DEBUG) return;
    for (int i = 0; i != v.size(); ++i) {
        for (int j = 0; j != v[i].size(); ++j) {
            cout << v[i][j];
            if (j != v[i].size() - 1) {
                cout << " ";
            }
        }
        cout << "; ";
    }
    cout << endl;
}


void debug(vector<int> & v) {
    if (!DEBUG) return;
    for (int i = 0; i != v.size(); ++i) {
        cout << v[i] << " ";
    }
    cout << endl;
}


class Solution {
	int n;
	string s;
public:
    void init() {
		cin >> n;
		cin >> s;
    }

    string solve() {
        init();
		int cs = 0;
		int cp = 0;
		int ps = -1;
		int pp = -1;
		for (int i = 0; i != n; ++i) {
			if (s[i] == 's') {
				++cs;
				ps = i;
			}
			if (s[i] == 'p') {
				++cp;
				pp = i;
			}
		}
		if (cs == 0) return "YES";
		if (cp == 0) return "YES";
		if ((cs == 1) and (s[0] == 's')) return "YES";
		if ((cp == 1) and (s[n - 1] == 'p')) return "YES";

		/*if ((cs > 1) and (cp > 1)) return "NO";
		if ((cs == 0) or (cp == 0)) return "YES";
		if ((ps == 0) and (pp == 1)) return "YES";
		if ((ps == n - 2) and (pp == n - 1)) return "YES"; */
        return "NO";
    }

};


signed main()
{
    std::ios_base::sync_with_stdio (false);
    std::cin.tie(NULL);
    int n;
    cin >> n;
    Solution sol;
    for(int i = 1; i != n + 1; ++i) {
        cout << fixed << setprecision(0) << sol.solve() << "\n";
    }

    return 0;
}


Solution 2 (runtime: 31 ms):
#pragma region usual_defs
#include <iostream>
#include <string.h>
#include <algorithm>
#include <cmath>

// this is the only reason I like C++ (sorry, java, try to be more fun next time):
#define meow cin
#define murr cout
#define lol long long
#define lmao unsigned long long
#define el '\n'
#define none \
    {        \
    }
#define kaput return
#define kill break
#define nah continue
using namespace std;
#pragma endregion usual_defs
// #define SYNC
#define i_like_cats

int n;
string str;
bool l, _s, _p;
void cat()
{
    meow >> n;
    meow.ignore();
    getline(meow, str);
    _s = false;
    _p = false;
    for (int i = 0; i < n; i++)
    {
        if (str[i] == 's')
            _s = true;
        else if (str[i] == 'p')
            _p = true;
    }
    if (!(_s && _p))
    {
        murr << "YES\n";
        kaput;
    }

    _p = true;
    for (int i = 0; i < n - 1; i++)
    {
        if (str[i] == 'p')
        {
            _p = false;
            kill;
        }
    }
    if (_p)
    {
        murr << "YES\n";
        kaput;
    }

    _s = true;
    for (int i = 1; i < n; i++)
    {
        if (str[i] == 's')
        {
            _s = false;
            kill;
        }
    }
    if (_s)
    {
        murr << "YES\n";
        kaput;
    }
    murr << "NO\n";
}

#pragma region main
#ifdef i_like_cats
int INPUT_SETS_COUNT;
#endif
int main()
{
    ios_base::sync_with_stdio(false);
#ifndef SYNC
    meow.tie(NULL);
#endif
#ifdef i_like_cats
    meow >> INPUT_SETS_COUNT;
    meow.ignore();
    while (INPUT_SETS_COUNT--)
        cat();
#endif
#ifndef i_like_cats
    cat();
#endif
}
#pragma endregion main