#include<bits/stdc++.h>
#define ll long long 
#define dbg(x) cout<<#x<<"=="<<x<<endl;
#define bug printf("*********\n");
#define debug(x) cout<<"["<<x<<"]" <<endl;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rrp(i,a,b) for(int i=b;i>=a;i--)
#define mem(a,b)   memset(a,b,sizeof a)
#define PI acos(-1.0)
#define esp 1e-6
using namespace std;
const int maxn=3e5+5;
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
inline ll rdll(){ll x = 0;ll  f=1;char ch=getchar();while(ch>'9'||ch<'0'){if(ch=='-') f=-f;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return f*x;}
inline int rd(){int x = 0;int f=1;char ch=getchar();while(ch>'9'||ch<'0'){if(ch=='-') f=-f;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return f*x;}
template <class T> void read(T &x) { T res = 0, f = 1;char c = getchar();while (!isdigit(c)) {if (c == '-') f = -1;c = getchar();} while (isdigit(c)) {res = (res << 3) + (res << 1) + c - '0';c = getchar();}x = res * f;}

void run(){
    int n=rd();
    string s;
    cin>>s;
    int num=0;
    rep(i,0,s.size()-1){
        if(s[i]=='M') {
            num++;
        }
    }
    if(n/3!=num){
        puts("NO");
    }else{
        bool flag=1;
        int t=0,m=0;
       rep(i,0,s.size()-1){
          if(s[i]=='M'){
              m++;
              if(n-num-t-(n/3-m)<=0){
                flag=0;
                //cout<<"xxxxx"<<endl;
                break;
                }
            if(t-m<0){
                flag=0;
                //cout<<"xxxxx"<<endl;
                break;
            }
          }
          else t++;
          
       }
       puts(flag?"YES":"NO");
    }

}
signed main(){
    int _=rd();
    while(_--){
        run();
    }
    return 0;
}