/*
 * generated by github.com/calgagi/cp_gen
 * file: B.cpp
 * time: Fri Apr 16 07:39:12 2021
 */

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;


/* ===== BEGIN USER CODE ===== */

void solve() {
    int n;
    cin >> n;
    vector<char> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    map<char, int> s;
    for (int i = 0; i < n; i++) {
        s[a[i]]++;
    }
    if (2*s['M'] != s['T']) {
        cout << "NO" << endl;
        return;
    }

    int m = 0, t = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == 'M') {
            m++;
        }
        if (a[i] == 'T') {
            t++;
        }
        if (m > t) {
            cout << "NO" << endl;
            return;
        }
    }
    m = 0, t = 0;
    for (int i = n-1; ~i; i--) {
        if (a[i] == 'M') {
            m++;
        }
        if (a[i] == 'T') {
            t++;
        }
        if (m > t) {
            cout << "NO" << endl;
            return;
        }
    }

    cout << "YES" << endl;

    return;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

    int tests = 1;
    cin >> tests;
    for (int tc = 1; tc <= tests; tc++) {
        /* cout << "Case #" << tc << ": "; */
        solve();
    }

    return 0;
}
