#include using namespace std; ifstream fin("Input"); ofstream fout("Output"); int n, t1, t2, i, j, bun, rau, gasit; char c; int main() { fin >> n; fin.get(c); for(j=1;j<=n;++j) { bun=0; rau=0; gasit=0; fin.get(c); t1=c-'0'; t1*=10; fin.get(c); t1=t1+c-'0'; fin.get(c); fin.get(c); t2=c-'0'; t2*=10; fin.get(c); t2=t2+c-'0'; fin.get(c); while(c!='\n') { fin.get(c); rau=1; } if(t1>59) rau=1; if(t2>59) rau=1; if(t2==0) bun=1; if(t1==t2) bun=1; if(t1%10==t2/10&&t2%10==t1/10) bun=1; if(t1/10==t1%10-1&&t1%10==t2/10-1&&t2/10==t2%10-1) bun=1; t1*=100; t1+=t2; gasit=0; while(t1>0) { if(t1%2==1) gasit=1; t1/=2; } if(!gasit) bun=1; if(bun&&!rau) fout<<"YES"<<'\n'; else fout<<"NO"<<'\n'; } return 0; }