#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        string s;
        cin>>s;
        int cntt=0,cntm=0,flag =1;
        for(int i =0;i<n;i++)
        {
            if(s[i]=='T')
            cntt++;
            else if(s[i]=='M')
            cntm++;
            if(cntm>cntt||cntt-cntm>n/3)
            {
                flag = 0;
                break;
            }
        }
        
        if(flag && cntm*2==cntt)
        cout<<"YES"<<endl;
        else
        cout<<"NO"<<endl;
    }
}