Problem I. Image Recognition

Author:ACM ICPC 2009-2010, NEERC, Northern Subregional Contest   Time limit:3 sec
Input file:image.in   Memory limit:256 Mb
Output file:image.out  

Statement

Irene works for Novel Efforts in Effective Recognition of Characters (NEERC). Her new project concerns image recognition using robots.

Since the approach is quite innovative, Irene starts with a very simple model first. She fixed d~images which are called digits 0 to d − 1. Each image is a w × h rectangle filled with white and black unit squares (call them pixels). All images are distinct (that is, each two images differ in at least one pixel).

The robot is placed in the upper left pixel of one of the images. It starts executing a program written in a specific programming language described below. The task of the robot is to recognize which of the d~images it was placed onto.

The programming language for the robot consists of the following commands:

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

Irene is interested in the program that always works correctly. That is, if a robot is placed onto the image corresponding to the digit i, then the execution of the program must end with the command i.

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

Input file format

The first line contains three integers d, h, and w (1 ≤ d ≤ 10; 1 ≤ h, w ≤ 10) — the number of considered images, the height and the width of each image.

The rest if the input file contains d descriptions of images. Each description consists of h lines of length w. All characters are either B or W, representing a black or a white pixel respectively.

Image descriptions are given in the order from 0 to d − 1. Descriptions are separated by an empty line.

Output file format

Return a correct program for the robot 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.

Sample tests

No. Input file (image.in) Output file (image.out)
1
3 5 4
WBBW
BWWB
BWWB
BWWB
WBBW

WWBW
WBBW
BWBW
WWBW
WWBW

WBBW
BWWB
WWBW
WBWW
BBBB
D(1:D(2:0))

0.090s 0.010s 13