import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int q = in.nextInt(); for (int i=0; i < q; i++) { int n = in.nextInt(); Set ys = new HashSet(); Set xs = new HashSet<>(); Set rx = new HashSet<>(); Set ry = new HashSet<>(); Set zz = new HashSet<>(); for (int j=0; j < n; j++) { int x = in.nextInt(); int y = in.nextInt(); if (xs.contains(x)) { rx.add(x); } else if (ys.contains(y)) { ry.add(y); } else { zz.add(x); } xs.add(x); ys.add(y); } //System.out.println(zz.size()); if (ry.size() > 2 || rx.size() > 2 || zz.size() > 1) { System.out.println("NO"); } else { System.out.println("YES"); } } /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ } }