Magical Switches

No attempts yetTime limit8sMemory limit512 MB

Problem

You are given a rectangular board divided into square cells. It has 33 rows and 3M+13M + 1 columns, where MM is a positive integer. Rows are numbered 11 through 33 from top to bottom, and columns are numbered 11 through 3M+13M + 1 from left to right. The cell in row ii and column jj is written (i,j)(i, j).

Every cell is either a floor cell or a wall cell. The cells whose column number is 3k13k - 1 or 3k3k, that is the cells in columns 2,3,5,6,,3M1,3M2, 3, 5, 6, \ldots, 3M - 1, 3M, are all painted in some color (k=1,2,,Mk = 1, 2, \ldots, M). There are 2626 colors, numbered 11 through 2626. The other cells, those in columns 1,4,7,,3M+11, 4, 7, \ldots, 3M + 1, are not painted and all of them are floor cells.

You play the following game on the board. First you put a token on cell (2,1)(2, 1). Then you repeatedly move it to an adjacent floor cell. Two cells are adjacent when they share an edge. You cannot move the token to a wall cell or off the board. The objective is to move the token to cell (2,3M+1)(2, 3M + 1).

For this game you have 2626 magical switches. Switches are numbered 11 through 2626, and switch xx corresponds to the color with the same number. When you push switch xx, every floor cell painted in color xx becomes a wall cell and every wall cell painted in color xx becomes a floor cell, both at the same time.

You may push switches only before the token starts moving. Decide whether a set of switches that achieves the objective exists, and if it does, find one such set.

Input

The input holds at most 130130 datasets. The first line of each dataset contains an integer MM (1M10001 \le M \le 1000). The next three lines contain 3M+13M + 1 characters each and describe the board. The jj-th character of the ii-th of those lines describes cell (i,j)(i, j) as follows.

  • The xx-th uppercase letter means that cell (i,j)(i, j) is painted in color xx and is initially a floor cell.
  • The xx-th lowercase letter means that cell (i,j)(i, j) is painted in color xx and is initially a wall cell.
  • A period (.) means that cell (i,j)(i, j) is not painted, so it is a floor cell.

A character is a period when jj is one of 1,4,7,,3M+11, 4, 7, \ldots, 3M + 1, and only then. The end of the input is a line holding a single zero.

Output

Print one line for each dataset. If no set of switches achieves the objective, print -1. Otherwise print the set of switches you push in the following format.

n s1 s2 ... sn

Here nn is the number of switches you push, and s1,s2,,sns_1, s_2, \ldots, s_n are the uppercase letters of those switches, where the xx-th uppercase letter denotes switch xx. If you push no switch then n=0n = 0, and the line holds a single 00.

Several sets of switches can achieve the objective. Print only the one set determined as follows. Decide switches 11 through 2626 in this order. Keeping the decisions already made, leave the current switch unpushed if the objective can still be achieved by some choice of the switches after it, and push it only when no such choice exists. Print the chosen uppercase letters in alphabetical order, separated by single spaces.