Safe Squares (Large)

Count all grid-aligned square regions of any size that contain no monster, given a sparse set of at most K monster cells on an R by C board.

Hard8ArrayDynamic programmingPrefix sumMatrixNo attempts yetTime limit5sMemory limit512 MB

Problem

Monster trainers go looking for monsters, but a monster is dangerous to anyone who is not a trainer. You want to find safe spots that hold no monsters.

Think of the world as a grid. Some cells hold one monster each. A safe square is a grid-aligned square region of D×DD \times D cells that contains no monster at all (D1D \ge 1). Count how many safe squares of any size the whole world has. Two squares of the same size at different positions count separately.

Input

The first line contains the number of test cases TT.

Each test case starts with a line holding three integers RR, CC, and KK. The grid has RR rows and CC columns and holds KK monsters. Each of the next KK lines holds the row RiR_i and the column CiC_i of the ii-th monster. Rows are numbered from top to bottom starting at 0, and columns from left to right starting at 0.

Output

For each test case, print one line in the form Case #x: y, where xx is the test case number starting at 1 and yy is the number of safe squares in that test case.

Constraints

  • 1T201 \le T \le 20
  • 1R30001 \le R \le 3000
  • 1C30001 \le C \le 3000
  • 0K30000 \le K \le 3000
  • 0Ri<R0 \le R_i < R (1iK1 \le i \le K)
  • 0Ci<C0 \le C_i < C (1iK1 \le i \le K)
  • (Ri,Ci)(Rj,Cj)(R_i, C_i) \ne (R_j, C_j) for iji \ne j. No cell holds more than one monster.