n=int(input()) z=['']*100 z[28]='A' z[39]='B' z[79]='C' for i in range(n): *a,=input().split() p=int(a[0]+a[1]) f=int(a[2]+a[3]) z[f],z[p]=z[p],'' print('YNEOS'[z[58]+z[48]+z[68]!='ABC'::2])