#include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define ll long long
void solve(){
int n;
cin>>n;char s[n];int a[n]={0};int b[n]={0};int k=0;
for(int i=0;i<n;i++){cin>>s[i];
if(s[i]=='p'){k=1;a[i]=i+1;}
if(s[i]=='s'){b[i]=n-i;}
if(k && s[i]=='s'){k=2;}}
if(k==2){cout<<"NO"<<endl;return;}
int l=0,r=n-1;
for(int i=n-1;i>=0;i--){
int j=0;
while(b[j]==0 && j<i){j++;}
if(a[i]&&b[j]){if(min(a[i],b[j])>i-j+1){cout<<"NO"<<endl;return;}}
}
cout<<"YES"<<endl;}
int main() {
int t;
cin>>t;
while(t--){solve(); }
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBsbCBsb25nIGxvbmcKCnZvaWQgc29sdmUoKXsgCgkgICAgaW50IG47CgkgICAgY2luPj5uO2NoYXIgc1tuXTtpbnQgYVtuXT17MH07aW50IGJbbl09ezB9O2ludCBrPTA7CgkgICBmb3IoaW50IGk9MDtpPG47aSsrKXtjaW4+PnNbaV07CgkgICBpZihzW2ldPT0ncCcpe2s9MTthW2ldPWkrMTt9CgkgICBpZihzW2ldPT0ncycpe2JbaV09bi1pO30KCSAgICAgICBpZihrICYmIHNbaV09PSdzJyl7az0yO319CgkgICAgICAgaWYoaz09Mil7Y291dDw8Ik5PIjw8ZW5kbDtyZXR1cm47fQoJICAgICAgIGludCBsPTAscj1uLTE7CgkgICAgICAgZm9yKGludCBpPW4tMTtpPj0wO2ktLSl7CgkgICAgICAgCWludCBqPTA7CgkgICAgICAgCQl3aGlsZShiW2pdPT0wICYmIGo8aSl7aisrO30KCSAgICAgICAgICAgCWlmKGFbaV0mJmJbal0pe2lmKG1pbihhW2ldLGJbal0pPmktaisxKXtjb3V0PDwiTk8iPDxlbmRsO3JldHVybjt9fQoJICAgICAgCgkgICAgICAgICAgICAgICAgICAgCgkgICAgICAgICAgICAgICB9CgkgICAgICAgICAgICAgICAKCSAgICAgICAgICAgCgkgICAgICAgICAgIAoJICAgICAgIGNvdXQ8PCJZRVMiPDxlbmRsO30KCSAgICAgICAKCSAgICAgICAKCSAgICAgICAKCSAgICAgICAKaW50IG1haW4oKSB7CglpbnQgdDsKCWNpbj4+dDsKCXdoaWxlKHQtLSl7c29sdmUoKTsgfQoJcmV0dXJuIDA7Cn0=