Under construction

Still being built. Things may change

Chocolate and the Friends' Raid

Time limit1sMemory limit1024 MB

Summary
Given an M x N chocolate with up to 4 eaten squares, find the maximum number of 1x2 or 2x1 pieces that can be cut from the rest.
Level

Medium5 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

Coco's chocolate machine produces rectangular chocolate bars whose width and height are both multiples of 4. Coco wants to sell each M×NM \times N bar by splitting it into 1×21 \times 2 or 2×12 \times 1 pieces. One day, KK (0≤K≤40 \le K \le 4) friends came over, and each of them ate one 1×11 \times 1 square from the bar. Find the maximum number of pieces Coco can get by splitting the remaining chocolate.

Input

The first line contains the number of test cases TT. The next TT test cases follow in order.

The first line of each test case contains MM, NN, and KK. MM is the width and NN is the height of the chocolate. The next KK lines each give the position of one square a friend ate, as the column mm followed by the row nn. The top-left cell is (1,1)(1, 1), and no two eaten positions are the same.

Output

For each test case, print on one line the maximum number of 1×21 \times 2 or 2×12 \times 1 pieces that can be obtained by splitting the given chocolate.

Constraints

  • 1≤T≤10001 \le T \le 1000
  • 4≤M,N≤10004 \le M, N \le 1000
  • MM and NN are multiples of 44
  • 0≤K≤40 \le K \le 4
  • 1≤m≤M1 \le m \le M, 1≤n≤N1 \le n \le N

Examples1

  1. Example 1

    Input
    4
    4 4 0
    4 4 2
    1 1
    4 4
    4 4 4
    1 1
    4 4
    2 3
    3 4
    4 4 4
    1 2
    2 1
    3 3
    4 4
    
    Expected output
    8
    6
    6
    5