#include #define f first #define s second #define mp make_pair #define pb push_back #define all(c) (c).begin(), (c).end() #define sqr(x) (x)*(x) #define fname "" using namespace std; typedef long long ll; const double eps = 1e-9; const double PI = acos(-1.0); const int inf = int (1e9+7); const ll INF = (ll) 8e18+7; const int mod = int (1e9+7); const int N = int (2e5+7); int q, n; pair a[N]; bool check() { sort(a, a + n); n = unique(a, a + n) - a; int x1 = inf, x2 = -inf; for(int i = 0; i < n; i ++) x1 = min(x1, a[i].s), x2 = max(x2, a[i].s); for(int i = 0; i < n; i ++) { int j = i; while(j < n && a[j].f == a[i].f) j ++; if(i > 0 && j < n) { for(int k = i; k < j; k ++) if(a[k].s != x1 && a[k].s != x2) return 0; } if(j > i) i = j - 1; } return 1; } int main () { //freopen(fname".in", "r", stdin); //freopen(fname".out", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0); cin >> q; while(q --) { bool ok = 0; cin >> n; for(int i = 0; i < n; i ++) cin >> a[i].f >> a[i].s; if(check()) ok = 1; if(ok) cout << "YES\n"; else cout << "NO\n"; } return 0; }