#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define endl '\n'
typedef pair<int,int> ii;
int n,t;
string s;
deque<int> d;
deque<ii> f;
bool kt;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
//    freopen("c.inp","r",stdin);
//    freopen("c.out","w",stdout);
    cin >> t;
    while(t--){
        cin >> n;
        cin.ignore();
        getline(cin,s);
        kt = 1;
        while(!d.empty())d.pop_back();
        while(!f.empty())f.pop_back();
        for(int i = 0;i < n;++i){
            if(s[i]=='T')d.pb(i);
            else{
                if(d.empty()){
                    kt = 0;
                    break;
                }
                f.pb({d.front(),i});
                d.pop_front();
            }
        }
        if(f.size()!=d.size())kt = 0;
        while(!f.empty()&&kt){
            if(f.front().second<d.front()){
                f.pop_front();
                d.pop_front();
            }
            else kt = 0;
        }
        if(kt)cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

