#include #include #include #include #include #include using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int test; cin >> test; while(test--){ int n; cin >> n; long long int nodes[n][2]; int graph[n][n]; for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) graph[i][j] = 0; for(int i = 0; i < n; i++) cin >> nodes[i][0] >> nodes[i][1]; for(int i = 0; i < n; i++) for(int j = i+1; j < n; j++) if(nodes[i][1] - nodes[j][1] == 0 || nodes[i][0] - nodes[j][0] == 0){ graph[i][j] = 1; graph[j][i] = 1; } queue q; q.push(0); int visited[n]; for(int i = 0; i < n; i++) visited[i] = 0; while(!q.empty()){ int u = q.front(); q.pop(); for(int i = 0; i < n; i++){ if(!visited[i] && graph[u][i] == 1) q.push(i); } visited[u] = 1; } bool flag = true; for(int i = 0; i < n; i++) if(visited[i] == 0){ flag = false; break; } if(flag) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }