Noisy Neighbors (Large)

Place N tenants on an R by C grid to minimize the number of shared walls between occupied neighbors.

Medium7CombinatoricsGreedyMatrixNo attempts yetTime limit5sMemory limit512 MB

Problem

You are the landlord of an apartment building laid out as an RR by CC grid. Each apartment is one unit square cell with four walls. You want to rent NN of these apartments, one tenant per apartment, and leave the rest empty.

The trouble is that every prospective tenant is noisy. Whenever two occupied apartments share a wall, the building gains one point of unhappiness. Two apartments that meet only at a corner share no wall, so they add nothing. For example, a 2×22 \times 2 building with all four apartments occupied has four walls between neighbours, so its unhappiness is 4.

Place the NN tenants as well as possible and report the minimum unhappiness of the building.

Input

The first line contains the number of test cases TT. Each of the next TT lines contains three space separated integers RR, CC and NN.

Limits

  • 1T10001 \le T \le 1000
  • 1R×C100001 \le R \times C \le 10000
  • 0NR×C0 \le N \le R \times C

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 possible unhappiness of that building.

Hint

A 2×32 \times 3 building with six tenants has all seven internal walls sitting between neighbours.

A 4×14 \times 1 building with two tenants has several placements in which no wall is shared.

A 3×33 \times 3 building with eight tenants is best filled as a ring around the empty centre cell.