#include #include using namespace std; typedef int var; //ifstream cin("date.in"); //ofstream cout("date.out"); char x, y, c, z, t; bool pelicular() { if(((x-'0')*10 + y-'0')>=24) return false; if(z>='6') return false; if(z=='0' && t=='0') return true; if(x == z && y == t) { return true; } if(x==t && y==z) { return true; } if(y == x+1 && z == y+1 && t == z+1) { return true; } var num = (x-'0')*1000 + (y-'0')*100 + (z-'0')*10 + t-'0'; if(num >= 1000 && num == (num&(-num))) { return true; } return false; } int main() { var n; cin>>n; while(n--) { cin>>x>>y>>c>>z>>t; if(pelicular()) { cout<<"YES\n"; } else cout<<"NO\n"; } return 0; }