#include<bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fio freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
using namespace std;
const ll INF = 1e18 + 5;
const ll MOD = 1e9 + 7;
const ll MAXN = 1e6 + 10;
const ll MASKN = 20;

vector<string> gens(int n, int len) {
	vector<string> res(n);
	for(int i=0; i<n; ++i) {
		string s(len, ' ');
		for(int j=0; j<len; ++j) {
			s[j] = 'A' + rand() % 26;
		}
		res[i] = s;
	}
	return res;
}

vector<int> geni(int n, int l, int r) {
	vector<int> res(n);
	unordered_set<int> us;
	int i = 0;
	while(i<n) {
		int ran = (rand() % (r-l+1)) + l;
			res[i] = ran;
			++i;
	}
	return res;
}


void test() {

}


void print(vector<int> &a) {
	for(auto i : a) {
		cout << i << ' ';
	}
	cout << '\n';
}

void solve() {
	ll n;
	cin >> n;
	string s;
	cin >> s;
	int cntt = 0, cntm = 0;
	vector<int> M,T;
	for(int i = 0; i < n; ++i) {
		cntt+=(s[i]=='T');
		cntm+=(s[i]=='M');
		if(s[i]=='T') {
			T.push_back(i);
		}
		if(s[i]=='M') {
			M.push_back(i);
		}
	}
	if(2*cntm!=cntt) {
		cout << "NO\n";
		return;
	}
	int st = 0, e = (int) T.size() - 1;
	for(int i = 0; i < (int) M.size(); ++i) {
		if(M[i] < T[i] || M[i] > T[i + (int)M.size()]) {
			cout << "NO\n";
			return;
		}
	}
	cout << "YES\n";
}

int main()
{
	#ifndef ONLINE_JUDGE
	fio
	#endif
	fast
	ll tc=1;
	cin >> tc;
	while(tc--) {
		solve();
		// test();
	}
	return 0;
} 
