import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int q = sc.nextInt(); while(q-- > 0){ int n = sc.nextInt() , xi[] = new int[n] , yi[] = new int[n]; for(int i = 0 ; i < n ; i++){ xi[i] = sc.nextInt() ; yi[i] = sc.nextInt(); } boolean poss = true; for(int i = 1 ; i < n ; i++){ boolean deg = false; for(int j = i - 1 ; j >= 0 ; j--){ if(xi[i] == xi[j] || yi[i] == yi[j]){ deg = true; break; } } if(!deg){poss = false; break;} } if(poss) System.out.println("YES"); else System.out.println("NO"); } } }