q = int(input()) for i in range(q): n = int(input()) xedges = [] yedges = [] isRect = True for j in range(n): xy = input().split() x = int(xy[0]) y = int(xy[1]) if len(xedges) < 2: xedges.append(x) yedges.append(y) else: if x not in xedges and y not in yedges: print("NO") isRect = False break if isRect: print("YES")