#include #include #include #include #include using namespace std; bool IsPointsValidRect(vector> &points) { int minX = points[0].first; int maxX = points[0].first; int minY = points[0].second; int maxY = points[0].second; for(int i = 0; i < points.size(); i++) { minX = min(minX, points[i].first); maxX = max(maxX, points[i].first); minY = min(minY, points[i].second); maxY = max(maxY, points[i].second); } for(int i = 0; i < points.size(); i++) { int x = points[i].first; int y = points[i].second; if(x == minX || x == maxX) { if(y > maxY || y < minY) { return false; } } else if(y == minY || y == maxY) { if(x > maxX || x < minX) { return false; } } else { return false; } } return true; } int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int queries; cin >> queries; for(int i = 0; i < queries; i++) { int numPoints; cin >> numPoints; vector> points; for(int j = 0; j < numPoints; j++) { int x,y; cin >> x >> y; points.push_back(pair(x, y)); } if(IsPointsValidRect(points)) { cout << "YES" << endl; } else { cout << "NO" << endl; } } return 0; }