Farmers' Tale

1 seconds
64 MB
Hard
LOJ-1320 Udebug Debug
English

You may have heard the story. There was a farmer and he had a big rectangular land. When he grew older he divided this land to his sons. His sons also divided their shares to their sons when they grew older. And this way the poor land was getting divided and getting smaller from time to time. And this way when the population increases, the area of total agricultural lands decrease.

In this problem you have to do something similar. You are given a rectangular land in a 2D space, its height L and width W. The lower left corner of the rectangle is (0, 0) and the upper right corner is (L, W). There will be some lines that connect two different sides of the rectangle. You have to find the number of different parts of the rectangular area after drawing the lines. In the picture below, there are three lines. And there are seven different parts in the rectangle.

Farmer's Land

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with a line containing three integers n (0 ≤ n ≤ 100), L, W (5 ≤ L, W ≤ 100). Each of the next n lines contains four integers x1, y1, x2, y2 denoting a line in the rectangle. You can assume that (x1, y1) and (x2, y2) are on the boundary of the rectangle in different sides. No line is given more than once.

Output

For each case, print the case number and the number of different parts.

Sample

Sample Input Sample Output

2 3 100 100 0 50 100 50 50 0 0 93 30 0 80 100 0 10 10

Case 1: 7 Case 2: 1

Notes

Better to use integer calculations for this problem. Precision may cause problems.