#include <bits/stdc++.h>

#define fi first
#define se second
#define SIZ 200011

using namespace std;

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <int, ii> iii;
typedef pair <ii, ii> iiii;
typedef pair <ll, ll> pll;

int n, tL[100011], tR[100011];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
//    freopen("INP.INP", "r", stdin);
//    freopen("OUT.OUT", "w", stdout);
    int tc;
    cin >> tc;
    while (tc--) {
        string s;
        cin >> n >> s;
        s = " " + s;
        int cM = 0;
        for (int i = 1; i <= n; i++) {
            if (s[i] == 'M')
                cM++;
        }
        bool yes = 1;
        if (cM != n/3)
            yes = 0;
        int cur = 0;
        vector <int> hold;
        for (int i = 1; i <= n; i++) {
            if (s[i] == 'M') {
                hold.push_back(i);
                for (int j = cur + 1; j <= n; j++) {
                    if (s[j] == 'T') {
                        if (j > i)
                            yes = 0;
                        cur = j;
                        break;
                    }
                }
//                cerr << "i, y: " << i << "  " << yes << '\n';
            }
        }
//        cerr << yes << '\n';
        int mark = 0;
        for (int i = cur + 1; i <= n; i++) {
            if (mark >= (int) hold.size())
                break;
            if (s[i] == 'T') {
                if (i < hold[mark])
                    yes = 0;
                mark++;
            }
        }
        if (yes)
            cout << "YES\n";
        else
            cout << "NO\n";
    }
    return 0;
}

/*
    long long range?
    reset array?
    special case?
    check array size
*/
