Citylights

0

0 votes
Problem

Ignus’15 is coming. The parivartan team has decided to lighten the city lanes. Since Timo is the most intelligent member in the team. So, the team decides to give this task to Timo.

The city is represented in the form of rectangular grid. Each cell of the grid contains either ‘H’ or ‘L’. ‘H’ represents house and ‘L’ represents ‘Lane’ . Timo has to place lamp post on the lanes. Each lamp post can illuminate in one of 4 directions- horizontal left, horizontal right, vertical up and vertical down. That is, a lamp post can illuminate all lanes connected to each other in the same direction. The light cannot pass through the houses. Since, the budget of FOC(Festival Organizing Committee) is not high, so Timo decided to set minimum number of lamp posts so that each lane is illuminated.

Input

First line of input file contains a single integer containing number of test cases. First line of each test case contains N and M, the number of rows and columns in the rectangular grid respectively. Then, N lines follow, each line contains a string having size M.

Ouput

For each test case, output a single integer representing the minimum number of lamp posts required to illuminate all lanes of the city.

Constraints

1<=T<=30

1<=N<=100

1<=M<=100

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

For the second test case, lamp post 1 will light grid (1,1) , lamp post 2 will light (1,3), (2,3), (3,3) and (4,3), , lamp post 3 will light grids (2,2), (2,3) and (2,4), and lamp post 4 will light grids (3,1) , (3,2) and (3,3). So, minimum number of lamp posts required is 4.

Note A lane can be illuminated by more than one lamp posts.

Editor Image

?