401850: GYM100541 I Space Tour
Description
Alpha Centauri-M (ACM) is a planet with marvelous scenes for visitors from the Earth. Luckily you win a ticket to participate in a space tour to Alpha Centauri-M.
The map of the planet ACM is divided into a grid of M rows and N columns. The columns are indexed from 1 to N (from left to right) and the rows are indexed from 1 to M (from top to bottom). There are several cells on the map that are not safe for visitors to explore because of high mountains and volcanoes.
Upon arriving at ACM, the spaceship will land on any safe cell on the grid and passengers can visit the planet via a special system of space cars. From the landing cell (r0, c0) on the map, a space car can go to either one of the four connected adjacent cells, namely (r0–1, c0), (r0 + 1, c0), (r0, c0–1), (r0, c0 + 1). Subsequently, the space car will continue moving the following fixed navigation pattern:
- Turn right and go forward one cell
- Turn left and go forward one cell
- Go back to step 1.
A space car can only visit safe cells, therefore it will stop if the next cell is not safe or is beyond the map boundaries. The following figure illustrates a map consisting of M = 6 rows and N = 7 columns. From the landing cell (4, 3), you may visit 16 cells (including the landing cell).
For each landing cell on the map, you can determine the number of cells that you can visit (including the landing cell). Your task is to choose the landing cell from which you can visit the maximum number of cells on Alpha Centauri-M.
InputThe input file consists of several datasets. The first line of the input file contains the number of datasets which is a positive integer and is not greater than 20. The following lines describe the datasets.
The first line of a dataset contains 2 space-separated positive integers M and N (1 ≤ M, N ≤ 1000). The ith line in the next M lines of the dataset contains N binary digits to represent the states of all cells in the ith row of the map (1: safe cell, 0: unsafe cell).
OutputFor each dataset, write in one line the maximum number of cells that you can visit on Alpha Centauri-M (including the landing cell).
ExamplesInput2Output
3 3
011
111
111
6 7
1101011
0111111
1111101
1111111
1111110
0111111
8
20