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

void solve(){
  int n;
  string s;
  cin>>n>>s;
  vector<int> t, m;
  for (int i=0; i<n; ++i) {
    if (s[i]=='T') t.push_back(i);
    else m.push_back(i);
  }
  if (t.size()!=2*m.size()) {
    cout<<"NO\n";
    return;
  }
  for (int i=0; i<m.size(); ++i) {
    if (m[i]<t[i]||t[i+m.size()]<m[i]) {
      cout<<"NO\n";
      return;
    }
  }
  cout<<"YES\n";
}
int main()
{
  int t = 1;
  cin>>t;
  while(t--)
  {
    solve();
  }
  return 0;
}