// Problem: B. ТМТ документ
// Contest: Codeforces - Codeforces Round #715 (Div. 2)
// URL: http://codeforces.com/contest/1509/problem/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
 
using namespace std;

typedef long long ll;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend() 
#define sz(s) int((s).size())
#define sup(a, n) sort(a + 1, a + n + 1); // sup, broo!!!
#define sdown(a, n) sort (a + 1, a + n + 1, greater<>());
#define sll(a) sort(a.begin(), a.end());
#define ret return
#define speedup ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define nl "\n"
#define sp ' '

int binPow(int k, int n) {
	int res = 1;
	while (k) {
		if (k & 1)
			res *= n;
		n *= n;
		k >>= 1;
	}
	return res;
} //binary exponentiation is definitely better than pow

const int N = 1e5 + 123, INF = 1e9;	

bool check(int pos, int f, int s) {
	return (f < pos && pos < s);
}

void solve() {
	int n, t = 0, k = 0;
	char a[N];
	
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (a[i] == 'M')
			k++;
	}
	
	if (n != 3 * k) {
		cout << "NO" << nl;
		return;
	}
	
	for (int i = 1; i <= n; i++) {
		if (a[i] == 'T')
			t++;
		else
			t--;
		if (t < 0 || t > k) {
			cout << "NO" << nl;
			return;
		}
	}
	
	cout << "YES" << nl;
}

void cf() {
	int t;
	cin >> t;
	while (t--) {
		solve();
	}
}

int main() {
	speedup;
	
	// freopen("sum.in", "r", stdin);
	// freopen("sum.out", "w", stdout);
	
	cf();
}