Coders High 2014 ended, and the problem setters went out for grilled meat. Myeongwoo took charge of the grilling, and he modeled the meat on the hotplate like this.
The hotplate is a grid of H×W cells. One slab of meat covers several cells of the grid, and a cell that holds meat is completely filled.
Enough time has passed that the bottom side is done, so it is time to flip the meat.

All the meat in one slab flips together. The first picture is the original state of the hotplate. The second picture shows a slab flipped left to right. In the third picture the slab was flipped but does not line up with the grid cells. Myeongwoo hates that, so he never flips a slab into that position. The fourth picture shows a slab flipped and then turned 90 degrees clockwise, and that arrangement is allowed. Turning it 180 or 270 degrees is allowed too.
Myeongwoo wants every slab to end up flipped. He is a perfectionist and hates meat overlapping after the flip, so no two slabs may overlap and every slab must stay inside the hotplate.
Many arrangements satisfy those conditions. The output section fixes which one to print.
The first line has the number of test cases T. Then T test cases follow.
The first line of each test case has two integers H and W (1≤H,W≤11), the size of the grid, separated by a space.
The next H lines give the current state of the hotplate. Each line has W characters with no spaces, and each character is a lowercase letter or .. Cells with the same lowercase letter belong to the same slab. Belonging to the same slab means that by moving up, down, left, or right through cells of that slab only, you can reach every other cell of that slab.
For each test case, print the state of the hotplate after the flip on H lines. Each line must have W characters.
Print the arrangement you get by mirroring the whole hotplate left to right: print the characters of each input line in reverse order, keeping the lines in their original order. Mirroring the whole hotplate turns every slab into its own mirror image, no two slabs overlap, and no slab leaves the hotplate.
Do not print a blank line between test cases.