#include int n; using namespace std; int main() { string s; cin>>n; for (int i = 1;i<=n;i++) { cin>>s; int x1,x2,y1,y2; x1 = s[0] - '0'; x2 = s[1] - '0'; y1 = s[3] - '0'; y2 = s[4] - '0'; if (x1 * 10 + x2 < 0 || x1 * 10 + x2 > 23 || y1 * 10 + y2 < 0 || y1 * 10 + y2 > 59) cout<<"NO"<<'\n'; else { int ok = 0; if (y1 == 0 && y2 == 0) ok = 1; if (x1 == y1 && x2 == y2) ok = 1; if (x1 == y2 && x2 == y1) ok = 1; if (x1 < x2 && x2 < y1 && y1 < y2) ok = 1; if ((x1 == 1 && x2 == 0 && y1 == 2 && y2 == 4) || (x1 == 2 && x2 == 0 && y1 == 4 && y2 == 8)) ok = 1; if (ok == 1) cout<<"YES"<<'\n'; else if (ok == 0) cout<<"N0"<<'\n'; } } }