#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define int long long
#define R(i,a,b) for(ll i=a;i<b;i++)
#define RE(i,a,b) for(ll i=a;i<=b;i++)
#define RR(i,a,b) for(ll i=a;i>b;i--)
#define RRE(i,a,b) for(ll i=a;i>=b;i--)
#define F(i,n) for(ll i=0ll;i<n;i++)
#define FE(i,n) for(ll i=0ll;i<=n;i++)
#define FR(i,n) for(ll i=n;i>0ll;i--)
#define FRE(i,n) for(ll i=n;i>=0ll;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)((x).size())
#define pii pair <int, int>
#define t(tup, i) get<i>(tup)
#define pb push_back
#define ft first
#define sd second
#define endl "\n"
#define flush cout << flush

template<typename ...Args>
void get(Args && ...args) {
    (std::cin >> ... >> args);
}

template<typename ...Args>
void print(Args && ...args) {
    (std::cout << ... << args);
}

void solve() {
    int n;
    string a;
    cin >> n;
    cin >> a;

    vector<bool> used(n,false);
    int cnt = 0;

    F(i,n) {
        if (a[i] == 'M') {
            used[i] = true;
            cnt++;
        }
    }

    int i = 0;
    int j = 0;

    while (i<n && j<n) {
        while (j<n && a[j] != 'M') j++;
        while (i<n && a[i] != 'T') i++;

        if (j==n) break;

        if (i >= j) {
            cout << "NO" << endl;
            return;
        }

        used[i] = true;
        cnt++;
        i++;
        j++;
    }

    i = n-1;
    j = n-1;

    while (i>=0 && j>=0) {
        while (j>=0 && a[j] != 'M') j--;
        while (i>=0 && (a[i] != 'T' || used[i])) i--;

        if (j<0) break;

        if (i<=j) {
            cout << "NO" << endl;
            return;
        }

        used[i] = true;
        cnt++;
        i--;
        j--;
    }

    if (cnt == n) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

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

    int T = 1;
    cin >> T;

    for (int __rep=0; __rep<T; ++__rep) {
        //cout << "Case #" << __rep+1 << ": ";
        solve();
    }
    return 0;
}