Jungle Trail
시간 제한3초메모리 제한1024 MB
각 행과 열을 최대 한 번씩 탭해 뱀의 독 상태를 바꾸고, 독이 있는 뱀과 막힌 칸을 피해 왼쪽 위에서 오른쪽 아래로 오른쪽/아래 이동 경로를 찾는다.
문제
In the mobile game "Jungle Trail", you are given a rectangular board divided into squares. Each square is either empty, blocked (impassable) or contains a den of snakes, either poisonous or benign (not poisonous). If a square contains a den of snakes, then either all the snakes on a given field are poisonous, or all are benign.
The game allows you to tap any column or any row of the board. If you tap a column, all poisonous snakes in this column are turned to benign, and vice versa. Similarly, if you tap any row, all snakes in the row change their state. You can tap each row/column only once. If a den is in a tapped row as well as in a tapped column, its state returns to the original one.
After performing all those operations, you must find a trail through the jungle: a path which starts at the top left corner, in every move goes either one square down or one to the right, ends at the bottom right corner and never passes through a den of poisonous snakes or a blocked field.
입력
The first line of input contains the number of test cases (). The descriptions of the test cases follow.
The first line contains two integers and ().
Each of the following lines contains characters ., #, O (capital o) and @ (at sign), meaning an empty square, blocked square, den of benign snakes and den of poisonous snakes, respectively. You may assume that the top left corner and the bottom right corner are not blocked.
Neither the sum of values over all test cases nor the sum of all values exceed .
출력
For every test case output the solution in the following format:
The first line should contain TAK if a jungle trail is possible or NIE if it isn't.
If the answer is TAK, in the next three lines output:
- A sequence of characters or , the -th character being if the -th row should be tapped, if not;
- A sequence of characters or , determining in the same way whether the columns should be tapped;
- A sequence of characters or denoting the trail: means a move right, means a move down.
힌트
After tapping the rows and columns described on the output, the board is in the following state:
..#..
OOOO@
##O#@
..O.O
Now the given path goes only through . and O squares.