eolymp
bolt
Try our new interface for solving problems
Problems

Buy Your House

Buy Your House

\includegraphics{https://static.e-olymp.com/content/a6/a6e91c94e2b30fce1db37c92dfa14c3b74161d0d.jpg} You are going to buy a house and hence communicated with a real estate development company, which has just started their business and you are going to be the first buyer. So they are offering you something special. The real estate company has a rectangular shaped land of width \textbf{W} and height \textbf{H}. They are using co-ordinate system for measuring lands. \textbf{(0, 0)} is the lower left corner of their land and any point which has distance \textbf{x} from lower edge of the land and distance \textbf{y} from left edge of the land is known as \textbf{(x, y)} in the co-ordinate system. The real estate company has already built some houses in that piece of land. All of them are rectangular shaped and their edges are parallel to edges of the main land. The location of a house can be addressed by four integers \textbf{x_1}, \textbf{y_1},\textbf{x_2}, \textbf{y_2}. Where \textbf{(x_1, y_1)} is the lower left corner and \textbf{(x_2, y_2)} upper right corner of the house. The special offer is that you can choose any rectangular shaped region that contains exactly one house with any amount of adjacent open space. You may not have enough money to afford open space and choose to buy only the region that a house occupies. If you have enough money, you can keep open space in front of your house for gardening! But still there are some restrictions. For the ease of their future use of rest of their land you can only choose a rectangular shaped region and the edges of which are parallel to the edges of the main land. The corners of your selected region should be integer coordinates. It can be \textbf{(3, 2)} but cannot be \textbf{(3.5, 2)}. You cannot chose a region for which part of a house is inside the region and another part of that house is outside the region. You cannot choose a region having more than one house and a region having no house. How many ways you can choose your land following the above rules? \InputFile Input will start with an integer \textbf{T} (\textbf{T} is around \textbf{500}), the number of test cases. Each of the test cases starts with two integers \textbf{W} and \textbf{H} (\textbf{1} ≤ \textbf{W}, \textbf{H} ≤ \textbf{1000000000}), width and height of the land and the next line contains an integer \textbf{N}(\textbf{1} ≤ \textbf{N} ≤ \textbf{50}), the number of houses in the land. Each of the next \textbf{N} lines will contain four integer \textbf{x_1}, \textbf{y_1}, \textbf{x_2}, \textbf{y_2} (\textbf{0} ≤ \textbf{x_\{1 \}}< \textbf{x_2} ≤ \textbf{W} and \textbf{0} ≤ \textbf{y_1} < \textbf{y_2} ≤ \textbf{H}), which describes the location of the house. Note that no house can overlap with another house and all the given coordinates will be non negative integers. \OutputFile For each input, print a single line of the form "\textbf{Case #: W}", where '\textbf{#}' will be replaced by the case number and \textbf{W} will be replaced by the number of ways you can choose your land. Here \textbf{W} can be very large, so you should print the number of ways modulo \textbf{1000000007} as \textbf{W}.
Time limit 1 second
Memory limit 256 MiB
Input example #1
2
3 3
1
1 1 2 2
10 10
2
1 1 4 4
6 6 8 8
Output example #1
Case 1: 16
Case 2: 429