Rectangle Coloring

No attempts yetTime limit1sMemory limit128 MB

Problem

You are given nn axis-parallel rectangles on the plane. An axis-parallel rectangle is a rectangle whose edges are parallel to the xx-axis or the yy-axis. Determine the number of colors needed to paint the nn rectangles according to the following rules.

  1. Each rectangle is painted with exactly one color.
  2. Two intersecting rectangles must be painted the same color. Regarding a rectangle as the set of points including its boundary, two rectangles intersect if their intersection is non-empty.
  3. For rectangles RaR_a and RbR_b, if there exists a sequence Ra=Ri1,Ri2,,Rik=RbR_a = R_{i_1}, R_{i_2}, \dots, R_{i_k} = R_b such that RijR_{i_j} and Rij+1R_{i_{j+1}} intersect for every 1j<k1 \le j < k, then RaR_a and RbR_b must have the same color; otherwise they must have different colors. For example, in the figure below rectangle R9R_9 must have the same color as R4R_4, R5R_5, R8R_8, and a different color from R1R_1, R2R_2, R3R_3, R6R_6, R7R_7.

In other words, rectangles connected through the intersection relation form one group, and each group is painted a single distinct color. Hence the number of colors needed equals the number of such groups (connected components).

Input

The input consists of TT test cases. The first line contains the number of test cases TT. The first line of each test case contains the number of rectangles NN (1N2001 \le N \le 200). Each of the next NN lines contains four positive integers x1x_1, y1y_1, x2x_2, y2y_2 (1x1,y1,x2,y2100001 \le x_1, y_1, x_2, y_2 \le 10000) describing one rectangle, where (x1,y1)(x_1, y_1) is the lower-left corner and (x2,y2)(x_2, y_2) is the upper-right corner. The four integers are separated by one or more spaces.

Output

For each test case, print the number of colors needed, one per line.