N = int(input()) list = [] for i in range(N): n = input() m = n.split() p = [int(i) for i in m] list.append(p) else: a = [2, 8] b = [3, 9] c = [7, 9] while len(list) != 0: r = list[0] q = r[0:2] if a == q: a = r[2:4] elif b == q: b = r[2:4] elif c == q: c = r[2:4] else: pass del list[0] else: if a == [5, 8] and b == [4, 8] and c == [6, 8]: print("YES") else: print("NO")