| Dahlia is taking a roadtrip across all of Canada! Along the way, she's | |
| spending a night in one of the country's hallmark cities, Toronto. | |
| Toronto's nighttime skyline can be represented as a 2D plane, with the ground | |
| forming a horizontal line with y-coordinate 0. There are **W** building | |
| windows, with the _i_th one at coordinates (**XWi**, **YWi**). There are also | |
| **S** visible stars, with the _i_th one at coordinates (**XSi**, **YSi**). | |
| It's guaranteed that all **W** \+ **S** of these points are distinct, and that | |
| no star is directly below a window (having the same x-coordinate but a smaller | |
| y-coordinate). | |
| At night, it's impossible to see any given window unless there's light coming | |
| from it. On any given night, each window is independently either lit up or not | |
| with equal probability. As such, there are 2**W** equally-likely subsets of | |
| windows which might be visible. Dahlia finds herself looking at Toronto's | |
| skyline on one such random night. | |
| Dahlia knows that Toronto consists of 0 or more buildings, each of which | |
| covers a rectangular portion of the sky with some bottom-left corner (**x1**, | |
| 0) and some top-right corner (**x2**, **h**), for some real values of **x1**, | |
| **x2**, and **h** (such that **x1** < **x2** and **h** > 0). The buildings | |
| might overlap with one another. Based on Dahlia's view of the stars and lit-up | |
| windows, she can infer some things about the set of buildings present. In | |
| particular, for each lit-up window _i_, Dahlia realizes that there must be at | |
| least one building whose rectangle inclusively covers the point (**XWi**, | |
| **YWi**). Furthermore, for each star _i_, Dahlia realizes that there must be | |
| no buildings whose rectangles inclusively cover the point (**XSi**, **YSi**). | |
| Dahlia is going to assume that Toronto consists of as few buildings as | |
| possible which are consistent with her observations on that night. What's the | |
| expected number of buildings which she'll assume exist? In order to avoid | |
| floating-point arithmetic and large integers, output this expected number | |
| multiplied by 2**W** (which is guaranteed to result in an integer) and then | |
| taken modulo 1,000,000,007. | |
| ### Input | |
| Input begins with an integer **T**, the number of skylines. For each skyline, | |
| there is first a line containing the space-separated integers **W** and **S**. | |
| Then, **W** lines follow, the _i_th of which contains the space-separated | |
| integers **XWi** and **YWi**. Then, **S** lines follow, the _i_th of which | |
| contains the space-separated integers **XSi** and **YSi**. | |
| ### Output | |
| For the _i_th universe, output a line containing "Case #_i_: " the expected | |
| number of buildings which Dahlia will assume exist, multiplied by 2**W** and | |
| then taken modulo 1,000,000,007. | |
| ### Constraints | |
| 1 ≤ **T** ≤ 150 | |
| 1 ≤ **W** ≤ 80 | |
| 1 ≤ **S** ≤ 50 | |
| 1 ≤ **XWi**, **YWi**, **XSi**, **YSi** ≤ 1,000,000,000 | |
| ### Explanation of Sample | |
| In the first case, there's a 50% chance that the single window will be | |
| visible, in which case Dahlia will assume that Toronto has 1 building. There's | |
| also a 50% chance that it won't be visible, in which case she'll assume that | |
| there are 0 buildings. As such, the expected number of buildings which she'll | |
| assume exist is (1 + 0) / 2 = 1/2. This should then be multiplied by 21 and | |
| taken modulo 1,000,000,007 to produce a final answer of 1. | |
| In the second case, however many windows are visible, Dahlia will assume | |
| Toronto has that many buildings. For example, if both windows are visible, | |
| then there must be at least 2 buildings, as a single building can't account | |
| for both windows without also covering the single visible star. This results | |
| in a final answer of ((0 + 1 + 1 + 2) / 4 * 22) modulo 1,000,000,007 = 4. | |
| In the third case, the final answer is ((0 + 1 + 1 + 1 + 1 + 1 + 2 + 2) / 8 * | |
| 23) modulo 1,000,000,007 = 9. | |