Grid Escape

Point each grid room at one door so exactly K players walk out of the grid, and print the direction grid or IMPOSSIBLE.

Medium4GraphSimulationImplementationNo attempts yetTime limit20sMemory limit1024 MB

Problem

You are building an escape adventure inside a rectangular grid of rooms with RR rows and CC columns. Every room has four doors, one on each side: north, south, east, and west. A door on the border of the grid leads outside. Every other door connects two neighboring rooms.

Exactly R×CR \times C players play, one in each room. When the game starts, all doors lock and a mechanism fixes which door each room can open: in every room exactly one of the four doors opens from the inside, and that door stays the same for the whole adventure. A door between two rooms may open from one side and stay locked from the other side.

Each player moves on their own. A player may walk only through a door they opened themselves, and the door closes behind them. A player keeps walking through doors until they walk through a door that leads outside, which means they escaped, or until they have made R×CR \times C moves without leaving the grid, which means they failed.

Choose the door that opens in each room so that exactly KK players escape, or report that no choice does that.

Input

The first line has the number of test cases, TT. Each of the next TT lines has three integers RR, CC, and KK.

Output

For each test case, print one line in the form Case #x: y. Here x is the test case number starting from 1, and y is IMPOSSIBLE when no arrangement lets exactly KK players escape, or POSSIBLE when one does. After a POSSIBLE line, print RR more lines of CC characters each. The jj-th character of the ii-th of those lines is N, S, E, or W, telling which door opens in the room in row ii, column jj.

Several arrangements can let exactly KK players escape, so print the one built by the following rule. Let M=R×CKM = R \times C - K.

  1. Number the rooms in zigzag order: row 1 from left to right, row 2 from right to left, row 3 from left to right again, and so on, giving p1p_1 through pR×Cp_{R \times C}. Two rooms next to each other in this order always share a door.
  2. For ii from 1 to M1M - 1, the room pip_i opens the door leading to pi+1p_{i+1}. The room pMp_M opens the door leading to pM1p_{M-1}. When M=0M = 0, this step fixes no room.
  3. Every remaining room opens its south door.

Constraints

  • 1T1001 \le T \le 100
  • 1R1001 \le R \le 100
  • 1C1001 \le C \le 100
  • 0KR×C0 \le K \le R \times C

Hint

A player who does not escape is stuck in a loop. From any room the open doors give one path forward, so a player either reaches the outside or walks the same set of rooms forever. That is why R×CR \times C moves are enough to settle every player.

In a grid with a single room, the one door that opens leads outside, so that player always escapes.