#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define debug(x) cerr << #x << " :: " << x << '\n';

const int N = 3e5 + 10;
const int MOD = 1e9 + 7;
const long long INF = 5e18;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        int n;
        string s;
        cin >> n >> s;
        int tc = 0, mc = 0;
        s = "x" + s;
        vector<int> ts(n + 1), ms(n + 1);
        for (int i = 1; i < s.size(); i++) {
            if (s[i] == 'T') {
                tc++;
                ts[i]++;
            } else {
                mc++;
                ms[i]++;
            }
            ts[i] += ts[i - 1];
            ms[i] += ms[i - 1];
        }
        if (mc * 2 != tc) {
            cout << "NO\n";
            continue;
        }
        int ok = 1, x = 0, y = 0;
        for (int i = 1; i <= n; i++) {
            if (s[i] == 'T') {
                if (x > 0) x--, y++;
                continue;
            }
            x++;
            int ase = ts[i] - ts[0] - y;
            if (ase < x) {
                ok = 0;
                break;
            }
            ase = ts[n] - ts[i];
            if (ase < x) {
                ok = 0;
                break;
            }
        }
        cout << (ok ? "YES" : "NO") << '\n';
    }
    return 0;
}
