#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define mxn 1000100
#define N int(1e7) + 1
#define inf int(1e15)


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

    #ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);
	    freopen("output.txt","w",stdout);
	#endif

    int t = 1;
    cin >> t;
    for(int test = 1 ; test <= t ; ++test) {
        int n;
        cin >> n;
        vector <int> m, t;
        string s;
        cin >> s;
        for(int i = 0 ; i < n ; ++i) {
            if(s[i] == 'T') t.push_back(i);
            else m.push_back(i);
        }
        int ok = 1;
        if(t.size() != (m.size() << 1)) {
            cout << "NO" << endl;
            ok = 0;
            continue;
        }
        for (int i = 0 ; i < m.size() ; ++i) {
            if(m[i] < t[i] || m[i] > t[i + m.size()]) {
                cout << "NO" << endl;
                ok = 0;
                break;
            } 
        }
        if(ok) cout << "YES" << endl;
    }
    #ifndef ONLINE_JUDGE
        cout<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s\n";
    #endif
    return 0;
}
