#include <bits/stdc++.h>
#define forn(i,n) for(int i=0;i<int(n);++i)
using namespace std;


int main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T;
    cin >> T;
    while (T--) {
        vector<int> Ts;
        vector<int> Ms;
        int n;
        cin >> n;
        forn (i,n) {
            char c;
            cin >> c;
            if (c == 'T') {
                Ts.push_back(i);
            } else {
                Ms.push_back(i);
            }
        }
        if (Ts.size() != 2 * Ms.size()) {
            cout << "NO\n";
            continue;
        }
        bool flag = true;
        forn (i, Ms.size()) {
            int pm = Ms[i];
            int pts = Ts[i];
            int pte = Ts[i + Ms.size()];
            if (!(pts <= pm && pm <= pte)) {
                flag = false;
                break;
            }
        }
        if (flag) {
            cout << "YES\n";
        } else {
            cout << "NO\n";
        }
    }
}