#include <stdio.h>
#include <stdlib.h>


int main()
{
FILE *f;
int n,i,x,y,z,t;
char s[10];
scanf("%d",&n);
for(i=1;i<=n;i++)
    {
    fscanf(f,"%s",s);
    x=s[0]-'0';
    y=s[1]-'0';
    z=s[3]-'0';
    t=s[4]-'0';
    if( (x>=0 && x<=1 && y>=0 && y<=9 && z>=0 && z<=5 && t>=0 && t<=9 ) || (x==2 && y>=0 && y<=3 && z>=0 && z<=5 && t>=0 && t<=9) )
        if( (z==0 && t==0) || (x==z && y==t) || (x==t && y==z) || (t==z+1 && z==y+1 && y==x+1) || (x==1 && y==0 && z==2 && t==4) || (x==2 && y==0 && z==4 && t==8) )
            printf("YES\n");
        else
            printf("NO\n");
    else
        printf("NO\n");
    }
    return 0;
}