/* “No one is perfect - that’s why pencils have erasers.” */
 
#include <bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define sp <<" "<<
using namespace std;
const int mod = 1000000007;


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
      
      ll t;
      cin>>t;
      for(ll j=0;j<t;j++){
            ll n;
            cin>>n;
            string s1;
            cin>>s1;
            ll t=0,m=0;
            for (ll i=0;i<n;i++){
                  if(s1[i]=='T'){
                        t++;
                  }
                  else{
                        m++;
                  }
            }
            if(t!=2*m){
                  cout<<"NO"<<endl;
            }
            else{
                  ll a=0,b=0;
                  ll count=0;
                  for(ll i=0;i<n;i++){
                        if(s1[i]=='T'){
                              count++;
                        }
                        else if(s1[i]=='M'){
                              count--;
                        }
                        if(count<0){
                              //cout<<"NO"<<endl;
                              a++;
                              break;
                        }
                  }
                  count=0;
                  for(ll i=n-1;i>=0;i--){
                        if(s1[i]=='T'){
                              count++;
                        }
                        else if(s1[i]=='M'){
                              count--;
                        }
                        if(count<0){
                              //cout<<"NO"<<endl;
                               b++;
                              break;
                        }
                  }
                  
                  
                  
                  if(a==0 && b==0){
                        cout<<"YES"<<endl;
                  }
                  else{
                        cout<<"NO"<<endl;
                  }
            }
      }
	return 0;
}