Bitmap#10049

Bitmap

2 seconds
128 megabytes
Medium

Rectangular bitmap of size n \times m is given. Each pixel of the bitmap is either white or black, but at least one is white. The pixel in -th line and -th column is called the pixel . The distance between two pixels p_1 = (i_1, j_1) and p_2 = (i_2, j_2) is defined as:

d(p_1, p_2) = |i_1 - i_2| + |j_1 - j_2|

For each pixel find the distance to the nearest white pixel.

Input

The number of test cases is given in the first line, then test cases follow. First line of each test case contains pair of integer numbers n, m~(1 \le n \le 1000, 1 \le m \le 1000). In each of the following lines of the test case exactly one zero-one word of length , the description of one line of the bitmap, is written. On the -th position in the line i~(1 \le i \le n, 1 \le j \le m) there is if, and only if the pixel is white.

Output

For each test case, output lines, each containing integers f(i, 1), ..., f(i, m) separated by single spaces, where f(i, j) is the distance from the pixel to the nearest white pixel.

Examples

Example 1

Loading
Loading