'''
Created on Jan 20, 2015

@author: alessandro
'''
    

def main():
    n = input()
 
    for x in range(n):
        
        nr = raw_input()
        x = nr.split(":")
        if x[0] > "24" or x[1] > "60":
            print "NO"
            continue
        if x[1] == "00" or x[0] == x[1] or  x[0] == x[1][::-1] :
            print "YES"
            continue        
        if int(x[0][0])+2 == int(x[1][0]) and int(x[0][1])+2 == int(x[1][1]):
            print "YES"
            continue
            
        y = x[0] + x[1]
        y = int(y)
        if  (y & (y - 1)) == 0 and y>1:
            print "YES"
            continue
        print "NO"

main()