#include #include #include using namespace std; char time[7],h[3],m[3],nn[4]; char *p; short n; int xy,zt; bool mirror(char hh[3], char mm[3]) { if(hh[0]==mm[1]&&hh[1]==mm[0]) return true; return false; } bool consec(int x, int y) { int c1[3]={-1,-1,-1},c2[3]={-1,-1,-1},k=0; while(x) { c1[k++]=x%10; x/=10; } k=0; while(y) {c2[k++]=y%10; y/=10;} if(c1[1]==c1[0]+1&&c2[1]==c1[0]+1&&c2[0]==c2[1]+1) return true; return false; } bool ispoweroftwo(int x, int y) { int rez=x*100+y; return (rez &(rez - 1))==0; } void verifica() { if(zt==0) cout<<"YES\n"; else if(strcmp(h,m)==0) cout<<"YES\n"; else if(mirror(h,m)) cout<<"YES\n"; else if(consec(xy,zt)) cout<<"YES\n"; else if(ispoweroftwo(xy,zt)) cout<<"YES\n"; else cout<<"NO\n"; } int main() { cin>>n; cin.get(); for(int i=1;i<=n;i++) { cin.getline(time,6); p=strtok(time,":"); strcpy(h,p); xy=atoi(p); p=strtok(NULL,":"); strcpy(m,p); zt=atoi(p); verifica(); time[0]='\0'; } return 0; }