#pragma GCC optimize "O3" #include using namespace std; using LL=long long; #define FOR(i,l,r) for(int i=(l);i<=(r);++i) #define REP(i,n) FOR(i,0,(n)-1) #define ssize(x) int(x.size()) #ifdef DEBUG auto&operator<<(auto&o,pairp){return o<<"("<p){return o<<"("<(p)<<", "<(p)<<", "<(p)<<")";} auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<sync_with_stdio(0); int tests; cin >> tests; REP (test, tests) { int n; cin >> n; map> mp; REP (i, n) { int x, y; cin >> x >> y; mp[x + y].emplace_back(y); } set> t; t.emplace(0, 0, 1); int last = 0; bool broken = false; for (auto [tm, v] : mp) { if (broken) break; debug(t); while (last < tm) { if (t.empty()) { last = tm; break; } if (broken) break; ++last; map g; for (auto [l, r, w] : t) { g[l] += w - 1; g[l + 1] += w - 1; g[r + 1] -= w - 1; g[r + 2] -= w - 1; } int prv = 0, cur = 0; set> s; for (auto [y, w] : g) { if (!w) continue; if (cur) { s.emplace(prv, y - 1, cur); if (cur > 3) { broken = true; } } cur += w; prv = y; } assert(cur == 0); t = s; debug(last, t); } debug(v); for (auto y : v) { debug(y); auto ptr = t.lower_bound(tuple(y + 1, 0, 0)); if (ptr == t.begin()) continue; --ptr; auto [l, r, w] = *ptr; debug(l, r, w); if (l <= y && y <= r) { assert(w); if (w >= 3) { broken = true; break; } t.erase(ptr); if (l < y) t.emplace(tuple(l, y - 1, w)); t.emplace(tuple(y, y, w + 1)); if (y < r) t.emplace(tuple(y + 1, r, w)); } debug(t); if (broken) break; } debug("after", t); } if (broken) { cout << "NO\n"; } else { cout << "YES\n"; } } }