Spatial Concepts Test

Time limit1sMemory limit128 MB

Summary
Given a labeled cube net with oriented pictures on each face, determine which of five given corner views (top, right, left faces with orientations) can actually result from folding and rotating the cube.
Level

Hard8 of 10

Topics
Simulation, Geometry, Implementation
Solved
No attempts yet

Problem

You are given the net of a cube and five corner views, where each corner view shows three visible faces. Decide which views can match the cube after the net is folded.

Each face contains one picture labeled from A through F. Each picture is symmetric about its vertical axis, and its four ends are all distinguishable, so its orientation matters. A face is written as one picture letter followed by one direction digit. Directions 1, 2, 3, and 4 mean that the picture's top, right, bottom, and left end, respectively, points upward on that face.

A cube net is given as six such pairs, so it is a string of length 12. The six pairs are placed in positions 0 through 5 of this fixed net order.

    2
1 0 4 5
    3

A corner view is given as three such pairs, so it is a string of length 6. The pairs describe, in order, the face seen on the top, the face seen on the right, and the face seen on the left. The direction digit in each pair describes which end of that picture points upward in the view.

A view is correct if folding the net and rotating the resulting cube can produce exactly the same three visible faces with the same orientations.

Input

The first line contains the number of test cases T.

Each test case consists of 6 lines. The first line contains a length-12 string describing the cube net. Each of the next 5 lines contains a length-6 string describing one corner view.

Output

For each test case, print one line. First print the number of correct views, then print five flags in input order: Y if the corresponding view is correct and N otherwise. Separate all values with one space.

Examples1

  1. Example 1

    Input
    2
    F3E4E2D3C2F3
    C2D2F2
    E3F3C4
    F2C2D2
    D1E1F3
    E1C1E1
    A2F4F1A3A3C4
    C3A4A2
    F3F4A1
    F3C4A1
    A2C3A2
    A4A4F1
    
    Expected output
    2 Y N Y N N
    0 N N N N N