#include<iostream>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<unordered_set>
 
using namespace std;

bool check(string s) {
    int t1 = 0;
    int totalM = 0;
    bool ok = true;
    for(char c:s) {
        if(c == 'T') {
            t1++;
        } else {
            totalM++;
            if(t1 > 0) {
                t1--;
            } else {
                ok = false;
            }
        }
    }
    if(!ok || (t1!=totalM)){
        return false;
    } else {
        return true;
    }
}
 
int main(){
    int Case;
    cin>>Case;
    while(Case--) {
        int n;
        cin>>n;
        string s;
        cin>>s;
        if(check(s)) {
            reverse(s.begin(), s.end());
            if(check(s)) {
                cout<<"YES"<<endl;
                continue;
            }
        }
        cout<<"NO"<<endl;
    }
    
}

/**
 
 TMT TMT
 
 T T MT MT
 
 T TM MT T
 
 T TMT MT
 
 TM T T MT
 
 TM TM T T
 
 TM   TMT   T
 
 
 
 
 TM    TTMTMT    T
 
 TTMTMT
 TMT
 
 TMT
 */
