#P5297. [北京省选集训2019] 完美塔防

[北京省选集训2019] 完美塔防

Description

The game board is an n×mn \times m grid. Each cell may contain one of the following objects:

  1. Type A turret: shoots lasers in both up and down directions at the same time, represented by |.
  2. Type B turret: shoots lasers in both left and right directions at the same time, represented by -.
  3. Empty cell: a laser passes through and keeps moving in the same direction, represented by ..
  4. Obstacle: when a laser reaches it, the laser disappears, represented by #.
  5. Main mirror: when a laser reaches it, it changes direction according to the laws of physics and continues moving, represented by \.
  6. Secondary mirror: when a laser reaches it, it changes direction according to the laws of physics and continues moving, represented by /.

Note that lasers can pass through each other, but if a laser goes out of the grid boundary, it also disappears.
Xiao N is a perfectionist player. He wants every empty cell to be hit by at least one laser, but he must not let any laser hit his own turrets and damage them.
Xiao N can change any number of Type A turrets into Type B turrets, and can also change any number of Type B turrets into Type A turrets.
Can you tell whether he can achieve his goal through these modifications?

Input Format

The first line contains a positive integer TT, the number of test cases.
For each test case, the first line contains two positive integers n,mn, m.
The next nn lines each contain a string of length mm, describing the board.

Output Format

For each test case, if there is no solution, output one line IMPOSSIBLE. Otherwise, output one line POSSIBLE, then output the modified board.
If there are multiple solutions, output any one.

3
1 3
-.-
3 4
#.##
#--#
####
4 3
.|.
-//
.-.
#\/
IMPOSSIBLE
POSSIBLE
#.##
#||#
####
POSSIBLE
.-.
|//
.-.
#\/

Hint

Constraints

For 100%100\% of the testdata:

  • 1T2001\le T \le 200.
  • 1n,m501\le n,m \le 50.

Special Judge provided by @tiger2005.

Translated by ChatGPT 5