The Minions Build a Brick Wall
Time limit1sMemory limit256 MB
Cover a grid with obstacles using dominoes to leave as few open cells bare as possible.
Problem
A wall in Gru's laboratory collapsed in an explosion, so the minions have to rebuild it. The wall is squares high and squares wide.
One brick covers exactly two squares. A horizontal brick covers two squares side by side in the same row, and a vertical brick covers two squares stacked in the same column. Some squares of the wall are forbidden, and no brick may cover a forbidden square. Bricks must not overlap, and both squares of a brick have to lie inside the wall.
The minions want to cover as many of the squares that are not forbidden as they can. Covering all of them is not always possible, so some squares may be left bare.
The wall is given as rows of characters. The character X marks a forbidden square, and the character O marks a square that a brick may cover.
For each wall, find the smallest number of squares that stay bare.

Figure 1: sample walls (a) and (c) with forbidden squares shaded, and brick layouts (b), (d), and (e) with the uncovered squares hatched. The wall in (c) cannot be covered completely, and both (d) and (e) are optimal layouts that leave two squares bare.
Input
The first line contains the number of test cases . ()
The first line of each test case contains the height and the width of the wall. ()
Each of the next lines contains characters. Every character is either X or O.
Output
For each test case, print one line with the smallest number of squares marked O that stay uncovered when the bricks cover as many of them as possible.