410356: GYM104012 B Bricks in the Wall

Memory Limit:512 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

B. Bricks in the Walltime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard output

Bob is decorating a loft-style rectangular wall with bricks. The wall consists of $$$n \times m$$$ unit cells. Some cells are already occupied by bricks, while the remaining cells are empty.

Bob wants to add up to two more bricks to this wall. New bricks must have a width equal to $$$1$$$ unit and can have any positive integer length. Each brick can only be placed horizontally or vertically, so each new brick will occupy several consecutive empty cells in one row or in one column. Also, these two bricks must not intersect, i.e. occupy the same cell.

What is the maximum possible sum of lengths of at most two new bricks that Bob can add to this wall?

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.

The first line of each test case contains two integers $$$n$$$ and $$$m$$$ — the height and the width of the wall ($$$1 \le n, m$$$; $$$n \cdot m \le 10^6$$$).

The next $$$n$$$ lines contain $$$m$$$ characters each, describing the wall. An occupied cell is denoted by '#', an empty cell is denoted by '.'.

It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^6$$$.

Output

For each test case, print a single integer — the maximum possible sum of lengths of at most two new bricks.

ExampleInput
5
2 2
..
..
4 5
###.#
#....
.##.#
#.#.#
2 1
.
.
2 3
###
#.#
5 4
##.#
..#.
#.#.
....
#.##
Output
4
6
2
1
7

加入题单

上一题 下一题 算法标签: