#include using namespace std; typedef long long ll; int main() { ll q; cin >> q; mapmp; mapcp; map::iterator it; while(q--){ ll n; cin >> n; ll a,b; mp.clear(); cp.clear(); for(int i=0; i> a >> b; mp[a]++; cp[b]++; } ll mx = 0, tx = 0; for(it = mp.begin(); it!=mp.end(); it++){ mx = max(it->second,mx); } //cout << mx << endl; for(it = cp.begin(); it!=cp.end(); it++){ tx = max(it->second,tx); } //cout << tx << endl; if(((mx+tx)-1)==n) cout << "YES\n"; else cout << "NO\n"; } return 0; }