# Enter your code here. Read input from STDIN. Print output to STDOUT t=int(raw_input()) flag=False for i in range(t): x_s=set() y_s=set() q=int(raw_input()) for j in range(q): x,y=map(int,raw_input().split()) len_x=len(x_s) len_y=len(y_s) x_s.add(x) y_s.add(y) if len(x_s)>2 or len(y_s)>2: if len_x!=len(x_s) and len_y!=len(y_s): flag=True else: continue if flag==True: print 'NO' else: print 'YES'