// Maximum-TNT #include #include #include #include #include #include #include #include #include using namespace std; #define cin fin const int BUFSIZE = 1024; ifstream fin("rect.txt"); struct rect_t { int x1,x2,y1,y2; rect_t(){} }; vector > g_mat; vector g_rect; vector g_flg; bool IsSameColor(rect_t& a,rect_t& b) { if(a.x1 <= b.x2 && a.y1 <= b.y2 && b.x1 <= a.x2 && b.y1 <= a.y2)return true; return false; } void MakeMat() { int n = g_rect.size(); for(int i= 0 ; i < n ; i++) for(int j = i+1 ; j < n ;j++) if(IsSameColor(g_rect[i],g_rect[j])) { g_mat[i][j] = g_mat[j][i] = 1; } } void Dfs(int now) { g_flg[now] = true; for(int i = 0 ; i < (int)g_flg.size() ; i++) if(!g_flg[i] && g_mat[now][i]) Dfs(i); } int Solve() { int ans=0,n=g_flg.size(); for(int i = 0 ; i < n ; i++) { if(!g_flg[i]) { Dfs(i); ans++; } } return ans; } int main() { int n,t; cin >> t; while(t--) { cin >> n ; g_mat.assign(n,vector (n,0)); g_rect.assign(n,rect_t()); g_flg.assign(n,0); for(int i = 0 ; i < n ; i++) { cin >> g_rect[i].x1 >> g_rect[i].y1 >> g_rect[i].x2 >> g_rect[i].y2; } MakeMat(); cout << Solve() << endl; } return 0; }