ENG  RUSTimus Online Judge
Online Judge
Online contests
About Online Judge
Frequently asked questions
Site news
Problem set
Submit solution
Judge status
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests

1843. Cutting a Parallelepiped

Time limit: 0.5 second
Memory limit: 64 MB
Erno's small brother have lost his Rubik's cube. The next day he brought a saw. His goal was Erno's rectangular parallelepiped, all six faces of which were painted in different colors…
When Erno saw what was happening, the brother already made a few cuts parallel to the faces of the parallelepiped. The cuts passed through the whole parallelepiped. After all the cuts were made, the parallelepiped fell to pieces. Help Erno determine the initial position of each piece in the parallelepiped.


The first line describes the original parallelepiped. It contains three space-separated integers, which are distance between front and rear faces d, distance between bottom and top faces h and distance between left and right faces w (1 ≤ d, h, w ≤ 1 000). Then follows a string of six characters denoting colors of the faces. The colors are denoted by symbols “R”, “O”, “Y”, “G”, “B”; and “V”. The front bottom left vertex has coordinates (0, 0, 0) and the rear top right vertex has coordinates (d, h, w). The colors of the faces are described in the order: front, rear, bottom, top, left, right. The second line contains a number of pieces n (1 ≤ n ≤ 1 000). The following n lines describe the pieces in the same format as the original parallelepiped. If a face of a piece was not a part of a face of the original parallelepiped, its color is denoted by “.”.


Output the position of each piece in the original parallelepiped. For each piece, output a symbol denoting a face which should become the front face, followed by a symbol denoting a face which should become the bottom face, followed by coordinates of the front bottom left vertex of this piece in the original parallelepiped. Denote the front face by “F”, rear face by “B”, bottom face by “D”, top face by “U”, left face by “L”, right face by “R”. The pieces should be described in the order of their appearance in the input. If there are several possible answers, output any of them. It is guaranteed that the solution exists.


2 2 2 ROYGBV
1 2 2 R.YGBV
2 2 1 YGVBO.
F D 0 0 0
R F 1 0 0
Problem Author: Mikhail Rubinchik
Problem Source: Ural SU Contest. Petrozavodsk Summer Session, August 2010