Game Level Detector#3322

Game Level Detector

3 seconds
256 megabytes
Very hard

Alex is a game developer working on a puzzle game with procedurally generated mazes. The game has different level configurations numbered from to d - 1. Each level is a w \times h grid where each cell is either a wall (black) or a path (white). All level configurations are distinct (that is, each two levels differ in at least one cell).

Alex needs to write an AI that spawns in the top-left cell of a level and must quickly identify which level configuration it's in. The AI executes a program written in a specific scripting language described below.

The scripting language for the AI consists of the following commands:

Each movement command takes one time unit to execute. The execution of conditional operator and level identification commands is instantaneous.

Alex wants a program that always works correctly. That is, if the AI spawns on level , then the execution of the program must end with command i.

Given the set of level configurations, design a correct program for the AI, such that its execution time in the worst case is minimal.

Input

The first line contains three integers , , and (1 \le d \le 10; 1 \le h, w \le 10) -- the number of level configurations, the height and the width of each level.

The rest of the input file contains descriptions of levels. Each description consists of lines of length . All characters are either B or W, representing a wall (black) or a path (white) respectively.

Level descriptions are given in the order from to d - 1. Descriptions are separated by an empty line.

Output

Return a correct program for the AI with minimal possible worst-case execution time. If there are multiple possible programs, output any of them.

All whitespace is ignored when parsing a program.

Examples

The AI has to distinguish between the given level configurations in the example.

Example 1

Loading
Loading