#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define  no               cout<<"NO"<<endl
#define  yes              cout<<"YES"<<endl
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  N         1000005
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define PB push_back


void solve(){
	int n; cin>>n;
	string s; cin>>s;
	int t=0,m=0;
	for(int i=0; i<n; i++) {
		if(s[i]=='T') t++;
		else m++;
	}
	if(2*m==t) {
		t=0,m=0;
		for(int i=0; i<n; i++) {
			if(s[i]=='T') t++;
			else m++;
			if(t<m) {
				cout<<"NO"<<endl;
				return;
			}
		}	
		t=0,m=0;
		for(int i=n-1; i>=0; i--) {
			if(s[i]=='T') t++;
			else m++;
			if(t<m) {
				cout<<"NO"<<endl;
				return;
			}
		}
		cout<<"YES"<<endl;
	}
	else no;
}
int main()
{
	fast
	int T = 1;
	cin >> T;
	while (T--)solve();
	return 0;
}