def validate(h, m): if(h <= 24 and h >= 0 and m <= 60 and m>= 0): return True else: return False def read(): line = raw_input() [h,m] = line.split(':') intH = int(h) intM = int(m) return [h,m,intH,intM] def consecutive(h,m): h1 = int(h[0]) h2 = int(h[1]) m1 = int(m[0]) m2 = int(m[1]) if(h1 == h2-1 and h2 == m1-1 and m1 == m2-1): return True else: return False def power2(h,m): if int(h+m) == 1024 or int(h+m) == 2048: return True else: return False def main(): n = int(raw_input()) for i in range(n): [h,m,ih,im] = read() if not validate(ih,im): print "NO" continue else: if(im == 0): print "YES" continue if(h == m): print "YES" continue if(h[0] == m[1] and h[1] == m[0]): print "YES" continue if(consecutive(h,m)): print "YES" continue if(power2(h,m)): print "YES" continue main()