#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		string s;
		cin>>s;
		vector<int> v(n);
		int sum=0;
		bool flag=true;
		for(int i=0;i<n;i++){
			if(s[i]=='T')
				sum=sum+1;
			else
				sum=sum-1;
				
			if(sum<0 || (sum>n/3 && i<n-1))
			{
				cout<<"NO"<<"\n";
				flag=false;
				break;
			}
		}
			if(flag){
			if(sum==n/3)
				cout<<"YES"<<"\n";
			else
				cout<<"NO"<<"\n";
			}
				
		
	}
	return 0;
}