#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long int
#define pb push_back
#define f(i, a, b) for(ll i=a;i<b; i++)
#define fr(i, a, b) for(ll i=a-1; i>=b; i--)
 
const ll MOD = 1000000007;
const ll N = 1000000000000;
const ll INF = 1e9;

     
     
void solve()
{
	
	
	ll n;
   cin>>n;
   
   ll cnt = n/3;
   
   
    string s;
    cin>>s;
    
    ll t=0,m=0;
    for(ll i=0; i<n; i++)
    {
		if(s[i] == 'M')
		 m++;
		else if(s[i] == 'T')
		 t++;
	 } 
	 
	 
	 if(m != cnt )
	  {
		  cout<<"NO"<<"\n";
		  
	  }
	 else
	 {
		 
		 vector<ll> a,b;
		 
		 for(ll i=0; i<n; i++)
		  {
			  if(s[i] == 'M')
			   a.pb(i);
			  else
			   b.pb(i); 
		   }
		   
		   for(ll i=0; i<a.size(); i++)
		    {
				if(a[i] < b[i] || a[i] > b[i + a.size()])
				 {
					 cout<<"NO \n";
					 return;
				 }
			 }
		   
			
			
			cout<<"YES \n";      
		 
		   
	 }
	 
	 return;
	 
	   
}     
    
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll test;
    
    cin>>test;
    
    while(test--)
     solve();
     
     return 0;
    
   



} 