#include #include #include using namespace std; int n,v[1000],contor,power; char x; int main() { freopen("input.in","r",stdin); //cin>>n; scanf("%d ",&n); contor = 1; for(int i=1;i<=n;++i) { contor = 0; while(scanf("%c",&x)) { if(x=='\n') { break; } else if(x!=':') { v[++contor] = x-48; } } power = 1; if(v[1]!=0) { for(int j=1;j<23;++j) { power = power*2; if(power == v[1]*1000+v[2]*100+v[3]*10+v[4])break; } } if(v[1]*10+v[2]>=24||v[3]*10+v[4]>=60)cout<<"NO"<<'\n'; else if(power!=23&&power>=2)cout<<"YES"<<'\n'; else if(v[3]==0&&v[4]==0)cout<<"YES"<<'\n'; else if(v[1]==v[3]&&v[2]==v[4])cout<<"YES"<<'\n'; else if(v[1]==v[4]&&v[2]==v[3])cout<<"YES"<<'\n'; else if(v[4]==v[3]-1&&v[3]==v[2]-1&&v[2]==v[1]-1)cout<<"YES"<<'\n'; else if(v[4]==v[3]+1&&v[3]==v[2]+1&&v[2]==v[1]+1)cout<<"YES"<<'\n'; else cout<<"NO"<<'\n'; } return 0; }