9040 - Mspaint   

Description

MSpaint is a program that allows users to draw pictures.  The canvas is defined by two integers, N and M, specifying the height and the width of the canvas.  The coordinate system of the canvas is described as follows.  The left-bottom corner is the origin, (0,0).  The x-axis is the horizontal line; and the y-axis is the vertical line.  You may assume all given coordinate (x, y) are positive integers and within the range of canvas, 0 <= y < N, and 0 <= x < M.  The picture is represented by a bitmap.  Each pixel of the picture is either empty or filled.

MSpaint accepts four kinds of commands:

1.R x1 y1 x2 y2: Draw a rectangle from(x1, y1) to (x2, y2)

2.F x y: If the point (x, y) is filled, then do nothing. 

 

Otherwise, fill the smallest closed region which contains the point(x, y).

3.L x1 y1 x2 y2: Draw a vertical or horizontal line from (x1, y1) to (x2, y2), which means either x1=x2 or y1=y2.

4.E: The end of the case.
 
The fill operation in the ‘F x y’ command works as follows. It first fills the current pixel, which must be empty.  Next it finds the four neighbors (left, right, top, and bottom of the current pixel.  If one of them is empty, it moves to the empty neighbor pixel and fills it recursively, until all neighbors are filled or out of the range of the canvas.

Input

The input file begins with an integer T (1 < T < 500), indicating the number of test cases.  Each test case begins with two integers N and M , 1 < N < 100, 1 < M < 100.  Next N lines describe the bitmap of the picture (0 is empty and 1 is filled).  There are commands followed by the bitmap.  And all the commands of a test case end with command ‘E’.  The number of commands of a test case is less than 20.

Output

For each case please output the bitmap of the picture.  Print a blank line after each case.

Sample Input  Download

Sample Output  Download

Tags




Discuss