#include #include #include using namespace std; int n; char s[10]; int check_pow(int x) { int nr=0; for(int i=0;(x>>i);i++) if( ((x>>i)&1) ) nr++; if(nr==1) return 1; return 0; } int check() { int x,y; x=(s[1]-'0')*10+s[2]-'0'; y=(s[4]-'0')*10+s[5]-'0'; if(x<0 || x>=24) return 0; if(y<0 || y>=60) return 0; if(y==0) return 1; if(x==y) return 1; if(s[1]==s[5] && s[2]==s[4]) return 1; if(s[2]==(s[1]+1) && s[4]==(s[2]+1) && s[5]==(s[4]+1) ) return 1; if( x>=10 && check_pow(x*100+y) ) return 1; return 0; } int main() { // freopen("date.in","r",stdin); scanf("%d\n",&n); for(int it=1;it<=n;it++) { scanf("%s\n",s+1); if(check()) printf("YES\n"); else printf("NO\n"); } fclose(stdin); fclose(stdout); return 0; }