#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        string s;
        cin>>s;

        int x = n/3;
        long long int reqt = x*2;
        long long int reqm = x;
        long long int t = 0, m = 0, count = 0;

        if(s[0] == 'M' || s[n-1] == 'M')
        {
            cout<<"NO"<<endl;
            continue;
        }
        int i;
        bool flag = true;
        for(i=0; i<n; i++)
        {
            if(s[i] == 'T')
                t++, count++;
            else
                m++, count--;

            if(count < 0 || count > x)
            {
                flag = false;
                break;
            }
        }

        if(t != reqt || m != reqm || flag == false)
            cout<<"NO"<<endl;
        else
            cout<<"YES"<<endl;

    }

    return 0;
}

