/**********************************************
* AUTHOR : Subhrangshu Pandey
* INSTITUTION : HIT, Kolkata
**********************************************/
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod ((long long)(1e9+7))
#define endl "\n"
#define all(x) (x).begin(), (x).end()
//smaller always visited and larger never
#define rep(i, begin, end) for(ll i = begin; i < end; ++i)
#define rev(i, begin, end) for(ll i = begin; i >= end; --i)
#define timetaken cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n"
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    
	ll t; cin>>t; while(t--){
		ll n;
		cin>>n;
		string s;
		cin>>s;
		ll cntt = 0, cntm = 0;
		rep(i, 0, n){
			if(s[i] == 'T') cntt++;
			else cntm++;
		}
		if(cntt != cntm*2){
			cout<<"NO\n";
			continue;
		}

		ll ft = 0, lt = 0;
		bool notposs = false;
		rep(m, 0, n){
			if(s[m] == 'M'){
				while(ft < n && s[ft] != 'T') ft++;
				lt = max(lt, m+1);
				while(lt < n && s[lt] != 'T') lt++;
				if(ft == n || lt == n || ft > m){
					notposs = true;
					break;
				}
				ft++; lt++;
			}
		}
		if(notposs){
			cout<<"NO\n";
			continue;
		}
		else{
			cout<<"YES\n";
		}
	}
	

	timetaken;
	return 0;
}