Enclosing Grid Points

Place the fewest stones on an N by M grid so at least K points either hold a stone or cannot reach the border without crossing a stone.

Medium7GeometryMathBrute forceNo attempts yetTime limit5sMemory limit512 MB

Problem

A grid has NN horizontal lines and MM vertical lines, so it has N×MN \times M intersection points. You put stones on some of the intersection points, and you want at least KK points to end up enclosed.

An intersection point is enclosed if either of the following holds.

  1. A stone sits on the point.
  2. Starting from the point, moving along the grid lines to neighboring points and stepping only on points that hold no stone, you cannot reach an empty point on the border of the grid.

Find the smallest number of stones that leaves at least KK enclosed points.

For example, enclosing 8 points on a 4×54 \times 5 grid takes at least 6 stones. The picture below shows one such placement. Enclosed points are marked with an x.

Input

The first line of the input gives the number of test cases, TT. Each of the next TT lines holds three integers NN, MM, KK separated by spaces.

Limits

  • 1T1001 \le T \le 100
  • 1N1 \le N
  • 1M1 \le M
  • 1KN×M1 \le K \le N \times M
  • N×M1000N \times M \le 1000

Output

For each test case, print one line in the form "Case #x: y", where xx is the test case number starting from 1 and yy is the minimum number of stones.