// x = x >> y = x / (2 ^ y)     // x division by pow(2, y)
// x = x << y = x * (2 ^ y)    // x multiplication  by pow(2, y)
#include <bits/stdc++.h>
using namespace std;
#define speedy ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);
#define ll long long
#define all(x) (x).begin(), (x).end() 
#define pii pair<int,int>
#define pff pair<float,float>
#define pll pair<ll,ll>
#define f first 
#define s second
#define endl "\n"
#define pb push_back
#define mms(ss,b) memset(ss,b,sizeof(ss));
#define ps(x,y) fixed<<setprecision(y)<<x
 
const int N = 1e5 + 50;
const int M = 5e3 + 50;
int n,m,u,k,l,r,t;
int cnt,cnt1,cnt2,ans;
int mn = INT_MAX;
int mx = INT_MIN;
const int fx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int fy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };
int visited[N];
const int MOD = (1ll << 30);
const int mod = 1e9 + 7;
 
bool cmp(pair<int, int>a, pair<int, int>b){
    return abs(a.second) > abs(b.second);
}
 
bool cmp1(const pair<string, pair<int, int>> &a, const pair<string, pair<int, int>> &b){
    return abs(a.second.first) < abs(b.second.first);
}
 
bool isPowerOfTwo(int n){ 
   return (ceil(log2(n)) == floor(log2(n))); 
}
 
int makedigit(string n){
    int res = 0;
    for(int i = 0; i < n.size(); i++){
        res = res * 10 + (n[i] - '0');
    }
    return res;
}
 
string inttostrng(int a){
    ostringstream temp;
    string str;
    temp << a;
    return temp.str();
}
 
void clearr(int vis[N], int n){
    for(int i = 0; i <  n; i++){
        vis[i] = 0;
    }
}
 
void solve(){
    cin >> n;
    string s;
    cin >> s;
    if(n == 3){
        if(s == "TMT"){
            cout << "YES\n";
            return;
        }
        else{
            cout << "NO\n";
            return;
        }
    }
    if(n % 3 != 0){
        cout << "NO\n";
        return;
    }
    vector<int> t;
    int x = n / 3;
    int m = x * 2;
    cnt = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'T'){
            cnt++;
        }
    }
    if(cnt != m){
        cout << "NO\n";
        return;
    }
    int vis[N];
    clearr(vis, n);
    int cnt1 = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'T'){
            t.push_back(i);
            cnt1++;
            vis[i] = 1;
        }
        if(cnt1 == x){
            break;
        }
    }
    vector<int> v;
    cnt1 = 0;
    k = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'M'){
            if(t[k] > i){
                cout << "NO\n";
                return;
            }
            k++;
            v.push_back(i);
            cnt1++;
        }
        if(cnt1 == x){
            break;
        }
    }
    k = 0;
    for(int i = 0; i < n; i++){
        if(!vis[i] and s[i] == 'T'){
            if(v[k] > i){
                cout << "NO\n";
                return;
            }
            k++;
        }
    }
    cout << "YES\n";
}
 
int main(){ 
    speedy
    cin >> t;
    while(t--){
        solve();
    }
}