Grid Point Counting

Time Limit: 14000/7000 MS (Java/Others)

Memory Limit: 32768/32768 K (Java/Others)


You have a number of sticks, which are thin enough to be considered as segments on the XY plane.

Your task is simple: count the number of grid points that are covered by at least one segment.


The first line contains a single integer T (T <= 10), the number of test cases.
Each case begins with an integer n (1 <= n <= 500), the number of segments.
Each of the following n lines contains four real numbers x1, y1, x2, y2, denoting a segment (x1,y1)-(x2,y2).
All of x1, y1, x2, y2 will be no larger than 10000 in their absolute values, and will contain at most 4 digits after decimal point.


For each test case, print the case number and the number of grid points.

Sample Input

2 2 -1 0 1 0 0 1 0 -1 1 1 2 3 4.0001

Sample Output

Case 1: 5 Case 2: 1




2009 Asia Regional Ningbo Online