#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <cmath>

#define ri register int
#define ll long long

using namespace std;
typedef int lll;

inline lll gcd(lll a,lll b) {
	return (!b)?a:gcd(b,a%b);
}

ll t;
ll lena;
string a;
void solve()
{
	cin >> lena >> a;
	map<char,ll> mp;
	for(ri i=0;i<lena;++i)
	{
		mp[a[i]]++;
	}
	if(mp['T'] != mp['M']*2 || a[0]=='M' || a[lena-1]=='M')
	{
		cout << "NO" << '\n';
		return;
	}
	else
	{
		ll ans=0;
		for(ri i=0;i<lena;++i)
		{
			ans+=(a[i]=='T'?1:-1);
			if(ans<0) 
			{
				cout << "NO\n";
				return;
			}
		}
		ans=0;
		for(ri i=lena-1;i>=0;--i)
		{
			ans+=(a[i]=='T'?1:-1);
			if(ans<0) 
			{
				cout << "NO\n";
				return;
			}
		}
		cout << "YES\n";
	}
}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0); 
	cin >> t;
	while(t--) 
	solve();
    return 0;
}