#include #include #include #include #include #include #include #include #include #define in cin #define out cout #define abs(x) ((x>0)?(x):(-(x))) #define max(a,b) ((a)>(b)?(a):(b)) #define min(a,b) ((a)<(b)?(a):(b)) #define FOR(i, a, b) for(int i = a; i <= b; ++i) #define DOWNFOR(i, a, b) for(int i = a; i >= b; --i) #define FOREACH(i, t) for (typeof(t.begin()) i = t.begin(); i != t.end(); ++i) using namespace std; typedef long long ll; int main(){ #ifndef ONLINE_JUDGE ifstream in("test.in"); ofstream out("test.out"); #endif int N; in>>N; FOR(i,1,N){ string s; in>>s; int x=int(s[0])-'0'; int y=int(s[1])-'0'; int z=int(s[3])-'0'; int t=int(s[4])-'0'; int k=0; if(z==0 && t==0) k=1; if(x==z && y==t) k=1; if(x==t && y==z) k=1; if(y==x+1 && z==y+1 && t==z+1) k=1; if(x==1 && y==0 && z==2 && t==4) k=1; if(x==2 && y==0 && z==4 && t==8) k=1; int A=x*10+y; int B=z*10+t; if(A>=24) k=0; if(B>=60) k=0; if(k) out<<"YES\n"; else out<<"NO\n"; } return 0; }