#include<bits/stdc++.h> 
using namespace std;
#define int long long int 
#define endl '\n'
#define mod 1000000007
const int N= 1e7+10;
vector<int>a;
vector<int>b;
vector<vector<int>>v;

signed main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);
    
    int t;cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        string s;
        cin>>s;
        int count_tp=0;
        int count_m=0;
        int count=0;
        bool flag=true;
        for(int i=0;i<n;i++)
        {
            if(s[i]=='T')
            {
                count++;
                count_tp++;
            }
            else
            {
                count--;
                count_m++;
            }
            if(count<0)
            {
                cout<<"NO"<<endl;
                flag=false;
                break;
            }
        }
        count=0;
        if(flag)
        {
            for(int i=n-1;i>=0;i--)
            {
                if(s[i]=='T')
                    count++;
                else
                    count--;
                if(count<0)
                {
                    flag=false;
                    cout<<"NO"<<endl;
                    break;
                }
            }
        }
        if(flag)
        {
            if(2*count_m==count_tp)
                cout<<"YES"<<endl;
            else
                cout<<"NO"<<endl;
        }
    }
    return 0;
}