#include <cstdio>
#include <cstring>
#include <stack>
using namespace std;

char time[10];
int x, y, z, t;

int main(){

//freopen("baruri.in", "r", stdin);

int T; scanf("%d", &T);

while(T--){
    scanf("%s", time);

    x = time[0] - '0';
    y = time[1] - '0';
    z = time[3] - '0';
    t = time[4] - '0';

    int H = x * 10 + y;
    int M = z * 10 + t;
    int power = x * 1000 + y * 100 + z * 10 + t;
    
    if(!(H >= 0 && H <= 24 && M >= 0 && M <= 60)){
        printf("NO\n");
        continue;
    }
    if(!z && !t || x==z && y==t || x==t && y==z || (y-x==1 && z-y==1 && t-z==1)){
        printf("YES\n");
        continue;
    }
    if(power > 1000 && !(power & (power-1))){
        printf("YES\n");
        continue;
    }
    printf("NO\n");
}

return 0;
}