Under construction

Still being built. Things may change

Bricks in the Wall

Interview

Time limit2sMemory limit1024 MB

Summary
Given a grid of bricks and empty cells, find two non-overlapping horizontal or vertical runs of empty cells with the largest total length.
Level

Medium5 of 10

Topics
Matrix, Implementation, Brute force
Solved
No attempts yet

Problem

Bob is decorating a loft-style rectangular wall with bricks. The wall consists of n×mn \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 11 unit and can have any positive integer length. Each brick can only be placed horizontally or vertically, so each new brick occupies 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

The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains two integers nn and mm, the height and the width of the wall (1≤n,m1 \le n, m; n⋅m≤106n \cdot m \le 10^6).

The next nn lines contain mm characters each, describing the wall. An occupied cell is denoted by #, and an empty cell is denoted by ..

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

Output

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

Examples1

  1. Example 1

    Input
    5
    2 2
    ..
    ..
    4 5
    ###.#
    #....
    .##.#
    #.#.#
    2 1
    .
    .
    2 3
    ###
    #.#
    5 4
    ##.#
    ..#.
    #.#.
    ....
    #.##
    
    Expected output
    4
    6
    2
    1
    7