#include<bits/stdc++.h>
using namespace std;
#define ll long long int
vector<ll>tleft,tright,mleft,mright;
map<char,int>mp;
set<int>s;
set<int>:: iterator itr;
int main()
{
  ll i,j,k,t,n;string str;
  cin>>t;
  while(t--)
  {
      cin>>n;
      cin>>str;
      tleft.clear();
      tright.clear();
      mleft.clear();
      mright.clear();
      mp.clear();
      s.clear();
      for(i=0;i<n;i++)
      {
          mp[str[i]]++;
          tleft.push_back(mp['T']);
          mleft.push_back(mp['M']);
          if(str[i]=='M')
          s.insert(i);
      }
      mp.clear();
      for(i=n-1;i>=0;i--)
      {
          mp[str[i]]++;
          tright.push_back(mp['T']);
          mright.push_back(mp['M']);
      }
      reverse(tright.begin(),tright.end());
      reverse(mright.begin(),mright.end());
      if(mp['M']!=(n/3))
      cout<<"NO"<<endl;
      else{
          bool possible=true;
          for(itr=s.begin();itr!=s.end();itr++)
          {
             // cout<<"index at "<<*itr<<" values  "<<tleft[*itr]<<" "<<mleft[*itr]<<" "<<tright[*itr]<<" "<<mright[*itr]<<endl;
              if(tleft[*itr]<mleft[*itr] || tright[*itr]<mright[*itr] )
              {
                  possible=false;
                  break;
              }
          }
          if(possible)
          cout<<"YES"<<endl;
          else
          cout<<"NO"<<endl;
      }
  }
}