Problem D. My Faulty Touch Screen III

Problem

In case you have forgotten, this is what I have been doing recently. I play my favourite mini computer game on my mobile phone with a faulty touch screen. The mini computer game, when played with my faulty touch screen, essentially has the following rule: The game board is an m x n grid. Initially some cells are black and the others are white. The goal of the game is to turn the whole grid black. The only operation allowed is touching a cell on the grid. When the player touches a cell on the grid, the colors of up to four cells are flipped. They are the cell being touched, the cell on the left, the cell on the right and the cell above, as shown on the diagram below. Of course, if some of those cells are not on the grid (e.g. I pick the cell at the top right corner), the colors of less than four cells will be flipped.


Because of your help last time, now it is clear that the game can always be finished when the number of columns of the board plus one is not divisible by 3. The next question is: given a board with such board size, what is the minimum number of touches required to solve the puzzle?

Input

The input starts with the number of games g. Descriptions of g games follow. For each game, the first line consists of two positive integers m and n where m and n are at most 1000 and n + 1 is not divisible by 3. Then the initial configuration of the game board is shown. A white cell is represented by the character 'w' and a black cell is represented by the character 'b'.

Output

For each game, print the minimum number of touches required to finish the game.

Sample Input

2
5 5
bbbbb
bbwbb
bwwwb
bbbbb
bbbbb
5 5
bbbbb
bbwbb
bwwwb
bbbbb
bbbbb

Sample output

1
1

Author

Louis Siu