#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ull unsigned long long
const int maxn=2e6+5;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
typedef pair<string, int> pii;
int a[maxn],b[maxn];
void solve()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	int cnt1=0,cnt2=0;
	int f=1;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='T')
		{
			cnt1++;
		}
		else
		{
			cnt1--;
			cnt2++;
			if(cnt1<0) f=0;
		}
	}
	if(f==0||(cnt1!=cnt2))
	{
		cout<<"NO"<<endl;
		return;
	}
	vector<int> v;
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='T')
		v.push_back(i);
		else
		{
			a[cnt++]=i;
		}
	}
	for(int i=cnt2;i<v.size();i++)
	{
		if(v[i]<=a[i-cnt2]) f=0;
	}
	if(f==0) cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	int t=1;
	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0; 
}