# Enter your code here. Read input from STDIN. Print output to STDOUT for _ in range(input()): dx = dict() dy = dict() count =0 for _ in range(input()): x,y = map(int, raw_input().split()) if x in dx.keys() or y in dy.keys(): pass else: if x not in dx.keys(): dx[x] = 1 if y not in dy.keys(): dy[y] = 1 count += 1 if count >1: print "NO" else: print "YES"