#P10943. [2015杭电多校]Walk Out

[2015杭电多校]Walk Out

Walk Out

Problem Description

In an nmn*m maze, the right-bottom corner is the exit (position (n,m)(n,m) is the exit). In every position of this maze, there is either a 00 or a 11 written on it. An explorer gets lost in this grid. His position now is (1,1)(1, 1), and he wants to go to the exit. Since to arrive at the exit is easy for him, he wants to do something more difficult. At first, he'll write down the number on position (1,1)(1, 1). Every time, he could make a move to one adjacent position (two positions are adjacent if and only if they share an edge). While walking, he will write down the number on the position he's on to the end of his number. When finished, he will get a binary number. Please determine the minimum value of this number in binary system.

Input

The first line of the input is a single integer T (T=10)T\ (T=10), indicating the number of testcases. For each testcase, the first line contains two integers nn and m (1n,m1000)m \ (1 \le n, m \le 1000). The ii-th line of the next nn lines contains one 01 string of length mm, which represents ii-th row of the maze.

Output

For each testcase, print the answer in binary system. Please eliminate all the preceding 00 unless the answer itself is 00 (in this case, print 00 instead).

Sample Input

2
2 2
11
11
3 3
001
111
101

Sample Output

111
101

Author

XJZX

Source

2015 Multi-University Training Contest 4