#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
#include<cmath>
char str[1000005];
int pow( int t )
{
return (1<<(t));
}
int main(){
int t;
scanf("%d",&t);
while( t-- ){
scanf("%s",str);
bool flg = false; bool fell = false;
int len = strlen( str ); int t = 0;
for( int i = 0; i < len; i++ )
{
if( str[i] == 'I' )t+=1;
else if( str[i] == 'U' )t += 3;
if( str[i] == 'M' && i != 0 )fell = true;
}
if( str[0] != 'M' || fell ){puts("No");continue;}
for( int i = 0; i < 30; i++ )
{
int c = pow(i);
if( c - t >= 0 && ( c- t )%6 == 0 ){flg = true;}
}
if( flg )puts("Yes");
else puts("No");
}
}