Twin Siblings Birthday
Problem
Today is your and your twin sibling's birthday. To celebrate, you got a rectangular cake to share. The cake is decorated with NN triangular patches of icing (which may overlap). All the icing patches were created with the same triangular mold, so they have the same shape and orientation. Although you and your twin are very similar, your tastes in icing are much different. This difference is formalized by each of you having a different enjoyment value for each patch of icing. Specifically, your enjoyment value for eating the entire ii-th patch of icing is AiAi, and your twin's is BiBi. If someone eats part of a patch, they get enjoyment proportional to the eaten area. For example, if you eat 2323 of the area of the ii-th icing patch, you would get 2Ai32Ai3 enjoyment from it. Note that there may be some flavors of icing that you or your twin do not enjoy, so the AiAi and/or BiBi values can be negative.
You will cut the cake into two rectangular pieces by making a single vertical cut (parallel to the Y-axis). After cutting the cake, you will eat the left piece and your twin will eat the right piece. Your total enjoyment is the sum of the enjoyment you get from all icing to the left of the cut. Similarly, your twin's enjoyment is the sum of the enjoyment they get from all icing to the right of the cut.
To be as fair as possible, you want to cut the cake such that the absolute value of the difference between your total enjoyment and your twin's total enjoyment is as small as possible. Given the NN triangular icing patches on a rectangular cake, what is the minimum possible absolute value of the difference between your and your twin's total enjoyments you can get?
Input
The first line of the input gives the number of test cases, TT. TT test cases follow. Each test case starts with a line containing three positive integers, NN, WW, and HH, representing the number of icing patches on the cake and the width and height of the top of the cake, respectively. The bottom-left corner of the cake is located at (0,0)(0,0) and the top-right corner is at (W,H)(W,H). Then, a line describing the icing patch mold follows. This line contains four integers: PP, QQ, RR, and SS. The icing patch mold is a triangle with vertices at (0,0)(0,0), (P,Q)(P,Q), and (R,S)(R,S). Then, NN lines follow. The ii-th of these lines contains four integers XiXi, YiYi, AiAi, and BiBi. The ii-th patch is a triangle with vertices at (Xi,Yi)(Xi,Yi), (Xi+P,Yi+Q)(Xi+P,Yi+Q), and (Xi+R,Yi+S)(Xi+R,Yi+S). You would get AiAi enjoyment from eating it and your twin would get BiBi enjoyment.
Output
For each test case, output one line containing Case #xx:
yy/zz
, where xx is the test case number (starting from 1) and yzyz is the minimum absolute value of the difference between your and your twin's total enjoyment that can be achieved with a single vertical cut as an irreducible fraction (that is, zz must be positive and of minimum possible value).
Problem
Today is your and your twin sibling's birthday. To celebrate, you got a rectangular cake to share. The cake is decorated with NN triangular patches of icing (which may overlap). All the icing patches were created with the same triangular mold, so they have the same shape and orientation. Although you and your twin are very similar, your tastes in icing are much different. This difference is formalized by each of you having a different enjoyment value for each patch of icing. Specifically, your enjoyment value for eating the entire ii-th patch of icing is AiAi, and your twin's is BiBi. If someone eats part of a patch, they get enjoyment proportional to the eaten area. For example, if you eat 2323 of the area of the ii-th icing patch, you would get 2Ai32Ai3 enjoyment from it. Note that there may be some flavors of icing that you or your twin do not enjoy, so the AiAi and/or BiBi values can be negative.
You will cut the cake into two rectangular pieces by making a single vertical cut (parallel to the Y-axis). After cutting the cake, you will eat the left piece and your twin will eat the right piece. Your total enjoyment is the sum of the enjoyment you get from all icing to the left of the cut. Similarly, your twin's enjoyment is the sum of the enjoyment they get from all icing to the right of the cut.
To be as fair as possible, you want to cut the cake such that the absolute value of the difference between your total enjoyment and your twin's total enjoyment is as small as possible. Given the NN triangular icing patches on a rectangular cake, what is the minimum possible absolute value of the difference between your and your twin's total enjoyments you can get?
Input
The first line of the input gives the number of test cases, TT. TT test cases follow. Each test case starts with a line containing three positive integers, NN, WW, and HH, representing the number of icing patches on the cake and the width and height of the top of the cake, respectively. The bottom-left corner of the cake is located at (0,0)(0,0) and the top-right corner is at (W,H)(W,H). Then, a line describing the icing patch mold follows. This line contains four integers: PP, QQ, RR, and SS. The icing patch mold is a triangle with vertices at (0,0)(0,0), (P,Q)(P,Q), and (R,S)(R,S). Then, NN lines follow. The ii-th of these lines contains four integers XiXi, YiYi, AiAi, and BiBi. The ii-th patch is a triangle with vertices at (Xi,Yi)(Xi,Yi), (Xi+P,Yi+Q)(Xi+P,Yi+Q), and (Xi+R,Yi+S)(Xi+R,Yi+S). You would get AiAi enjoyment from eating it and your twin would get BiBi enjoyment.
Output
For each test case, output one line containing Case #xx:
yy/zz
, where xx is the test case number (starting from 1) and yzyz is the minimum absolute value of the difference between your and your twin's total enjoyment that can be achieved with a single vertical cut as an irreducible fraction (that is, zz must be positive and of minimum possible value).