#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,t;
string a;
map<char,int>mp;
int main(){
 
   scanf("%d",&t);
   while(t--){
   	cin>>n;
   	cin>>a;
   	mp.clear();
   	int f=1;
   	for(int i=0;i<n;i++){
   		  mp[a[i]]++;
	}
	if(mp['M']*3==n){
		int s1=0,s2=0;
		for(int i=0;i<n;i++){
			if(a[i]=='T')s1++;
			else s2++;
			if(s1<s2){
				f=0;break;
			} 
		}
		s1=0,s2=0;
		for(int i=n-1;i>=0;i--){
			if(a[i]=='T')s1++;
			else s2++;
			if(s1<s2){
				f=0;break;
			}
		}
		if(f)printf("YES\n");
		else printf("NO\n");
	}
	else {
		printf("NO\n");
	}
   }  
   return 0;
}