#include <iostream>
#include <bits/stdc++.h>
#define endl "\n"
#define mem(a, n) memset(a, n, sizeof(a))
#define mod 1000000007
#define ll long long 

using namespace std;

bool el(string s , int n)
{
    int index_m=0;
    int count_t=0;
    vector<int> m;
    for(int i=0 ; i<n ; i++)
    {
        if(s[i] == 'T') count_t++;
        else
        {
            m.push_back(count_t);
        }
    }
    for(int i=m.size()-1 ; i>=0 ; i--)
    {
        if(i+1 > m[i])
        {
            return false;
        }
    }
    return true;
    // for(int i=0 ; i<m.size() ; i++)
    // {
    //     cout<<m[i]<<" ";
    // }
    
}

void solve()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int count_t=0 , count_m=0;
    for(int i=0 ; i<n ; i++)
    {
        if(s[i] == 'T') count_t++;
        else    count_m++;
    }
    if(2*count_m > count_t       ||       2*count_m < count_t)
    {
        cout<<"NO"<<endl;
        return;
    }
    bool flag1=el(s,n);
    reverse(s.begin() , s.end());
    bool flag2=el(s , n);
    if(flag1  && flag2) cout<<"YES"<<endl;
    else    cout<<"NO"<<endl;
    //cout<<flag1<<" "<<flag2<<endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int T=1;	
    cin>>T;
    //int o=1;
    while(T--)
    {
        //cout<<"Case #"<<o<<": ";
        solve();
        //o++;
	}
	return 0;
}