#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
char a[N];
int n, cm, ct, c1, c2, c3;

int main() {
    int T;
    scanf("%d", &T);
    while (T--) {
        scanf("%d", &n);
        scanf("%s", a);
        cm = ct = 0;
        for (int i = 0; i < n; ++ i) {
            if (a[i] == 'T') ++ ct;
            else ++ cm;
        }
        if (ct != cm * 2) { puts("NO"); continue; }
        c1 = c2 = c3 = 0;
        int ans = 1;
        for (int i = 0; i < n; ++ i) {
            if (a[i] == 'T') {
                if (c1 < cm) { ++ c1; }
                else { ++ c3; }
            } else {
                ++ c2;
            }
            if (c2 > c1 || c3 > c2) {
                ans = 0;
                break;
            }
        }
        if (ans) puts("YES");
        else puts("NO");
    }
    return 0;
}
