N = int(input()) A = "2 8" B = "3 9" C = "7 9" for i in range(N): S =input() if A == S[:3]: A = S[4:] if B == S[:3]: B = S[4:] if C == S[:3]: C = S[4:] if A == "5 8" and B == "4 8" and C == "6 8": print("YES") else: print("NO")