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(); int j = 0; HashSet x = new HashSet(); HashSet y = new HashSet(); boolean[] flags_x = new boolean[n]; boolean[] flags_y = new boolean[n]; in.nextLine(); while (j < n && in.hasNextLine()) { String line = in.nextLine(); String[] arr = line.split(" "); int first = Integer.parseInt(arr[0]); int second = Integer.parseInt(arr[1]); if (x.size() > 0) { if (x.contains(first)) { flags_x[j] = true; } else { flags_x[j] = false; x.add(first); } } else { x.add(first); flags_x[j] = true; } if (y.size() > 0) { if (y.contains(second)) { flags_y[j] = true; } else { flags_y[j] = false; y.add(second); } } else { y.add(second); flags_y[j] = true; } j++; } String answer = "YES"; for (int k = 0; k < n; k++) { if ((flags_x[k] == false) && (flags_y[k] == false)) { answer = "NO"; } } System.out.println(answer); } } }