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().split(' ') [h,m] = line[0].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 = raw_input().split(' ') n = int(n[0]) h = [0]*n m = [0]*n ih = [0]*n im = [0]*n for i in range(n): [h[i],m[i],ih[i],im[i]] = read() for i in range(n): if not validate(ih[i],im[i]): print "NO" continue else: if(im[i] == 0): print "YES" continue if(h[i] == m[i]): print "YES" continue if(h[i][0] == m[i][1] and h[i][1] == m[i][0]): print "YES" continue if(consecutive(h[i],m[i])): print "YES" continue if(power2(h[i],m[i])): print "YES" continue print "NO" main()