This page is still under construction.

Parts of this page are still being built. What you see may change.

Bugs Integrated, Inc.

Time limit15sMemory limit128 MB

Summary
Given a grid with some blocked cells, find the maximum number of 2x3 or 3x2 non-overlapping rectangles that fit on good cells.
Level

Hard8 of 10

Topics
Dynamic programming, Bit manipulation
Solved
No attempts yet

Problem

Bugs Integrated, Inc. is a major manufacturer of advanced memory chips. They are launching production of a new six-terabyte Q-RAM chip. Each chip consists of six unit squares arranged as a 2×32 \times 3 rectangle.

Q-RAM chips are made as follows. First take a rectangular silicon plate divided into N×MN \times M unit squares. Then every square is carefully tested and the defective ones are marked with a black marker.

Silicon plate divided into unit squares with defective squares marked in black

Finally the plate is cut into memory chips. Each chip consists of 2×32 \times 3 (or 3×23 \times 2) unit squares, and no chip may contain any defective (marked) square. It might not be possible to cut the plate so that every good square is part of some chip. The company wants to waste as few good squares as possible, so they would like to know how to cut the plate to produce the maximum possible number of chips.

You are given the dimensions of several silicon plates together with the list of all defective squares for each plate. Write a program that, for each plate, computes the maximum number of chips that can be cut from it.

Input

The first line contains a single integer DD (1≤D≤51 \le D \le 5), the number of silicon plates. DD blocks follow, each describing one plate.

The first line of each block contains three integers NN (1≤N≤1501 \le N \le 150), MM (1≤M≤101 \le M \le 10), and KK (0≤K≤N⋅M0 \le K \le N \cdot M), separated by single spaces. NN is the length of the plate, MM is its height, and KK is the number of defective squares on the plate.

The next KK lines list the defective squares. Each line contains two integers xx and yy (1≤x≤N1 \le x \le N, 1≤y≤M1 \le y \le M), the coordinates of one defective square. The upper-left square has coordinates [1,1][1, 1] and the bottom-right square has coordinates [N,M][N, M].

Output

For each plate, output a single line containing the maximum number of memory chips that can be cut from it.

Hint

Illustration of cutting a plate into 2x3 / 3x2 chips

The figure above illustrates an example of cutting a plate into chips.

Examples3

  1. Example 1

    Input
    2
    6 6 5
    1 4
    4 6
    2 2
    3 6
    6 4
    6 5 4
    3 3
    6 1
    6 2
    6 4
    
    Expected output
    3
    4
    
  2. Example 2

    Input
    1
    2 3 0
    
    Expected output
    1
    
  3. Example 3

    Input
    1
    3 2 0
    
    Expected output
    1