| <p> | |
| A certain well-hidden valley is home to a thriving population of mysterious creatures — Foxen! | |
| However, keeping the valley safe from outsiders (such as humans) is a necessity. | |
| To that end, a group of Foxen have been sent out to patrol the border. | |
| </p> | |
| <p> | |
| On their patrol route, the Foxen know that they're going to pass by an interesting, rectangular forest. | |
| When viewed from above, the forest can be modeled as a grid of cells | |
| with <strong>R</strong> rows and <strong>C</strong> columns. The rows are numbered from 1 to <strong>R</strong> from North to South, while the column are numbered from 1 to <strong>C</strong> from West to East. | |
| One tree is growing in the center of each cell, and each tree's height (in metres) is some positive integer no larger than <strong>H</strong>. | |
| </p> | |
| <p> | |
| If the Foxen were to look at the forest from the North side, all of the trees in any given column of cells would obscure each other and blend together. | |
| In fact, the Foxen would really only be able make out the overall shape of the forest's "skyline" when viewed from that direction. | |
| This Northern skyline can be expressed as a sequence of <strong>C</strong> positive integers, | |
| with the <em>i</em>th one being the largest of the <strong>R</strong> tree heights in the <em>i</em>th column. | |
| </p> | |
| <p> | |
| Similarly, if they were to look at the forest from the West side, they would only be able to make out the shape of its skyline from that direction. | |
| This Western skyline is a sequence of <strong>R</strong> positive integers, | |
| with the <em>i</em>th one being the largest of the <strong>C</strong> tree heights in the <em>i</em>th row. | |
| </p> | |
| <p> | |
| On their way to the forest, the Foxen find themselves wondering about what it might look like. | |
| They've done their research and are aware of its dimensions <strong>R</strong> and <strong>C</strong>, | |
| as well as the maximum possible height of its trees <strong>H</strong>, but they don't know the actual heights of any of its trees. | |
| They'd like to determine how many different, distinct-looking forests they might end up finding. | |
| A forest is a set of heights for all <strong>R</strong>x<strong>C</strong> trees, | |
| and two forests are considered to be distinct-looking from one another if their Northern skyline sequences differ and/or their Western skyline sequences differ. | |
| </p> | |
| <p> | |
| Please help the Foxen determine the number of possible different, distinct-looking forests! As this quantity may be quite large, they're only interested in its value when taken modulo 1,000,000,007. | |
| </p> | |
| <h3>Input</h3> | |
| <p> | |
| Input begins with an integer <strong>T</strong>, the number of different forests visited by the Foxen. | |
| For each forest, there is a single line containing the three space-separated integers | |
| <strong>R</strong>, <strong>C</strong>, and <strong>H</strong>. | |
| </p> | |
| <h3>Output</h3> | |
| <p> | |
| For the <em>i</em>th forest, print a line containing "Case #<strong>i</strong>: " | |
| followed by the number of possible different, distinct-looking forests modulo 1,000,000,007. | |
| </p> | |
| <h3>Constraints</h3> | |
| <p> | |
| 1 ≤ <strong>T</strong> ≤ 30 <br /> | |
| 1 ≤ <strong>R</strong>, <strong>C</strong>, <strong>H</strong> ≤ 500,000 <br /> | |
| </p> | |
| <h3>Explanation of Sample</h3> | |
| <p> | |
| In the first case, there are 10 possible different, distinct-looking forests which consist of a 2x2 grid of trees, with each tree being either 1m or 2m tall. | |
| For example, the following 2 forests look different (even though their Western skylines are equal, their Northern skylines differ), so both should be counted: | |
| </p> | |
| <pre> | |
| 1 2 2 1 | |
| 1 1 1 1 | |
| </pre> | |
| <p> | |
| On the other hand, the following 2 forests look identical to one another from both the North and the West, so only one of them should be counted: | |
| </p> | |
| <pre> | |
| 1 2 2 2 | |
| 2 1 2 1 | |
| </pre> | |