Building Construction

According to recent activities in the Computer Engineering department, ACM (Association for Construction Management) has signed a contract with the department to build some pre-constructed blocks which can be attached to each other and easily form a building. These blocks are cubes and have facilities for being attached to other blocks face to face. The problem is that these connecting facilities are not the same. Each of the 6 faces of a block has its own type of connector named 1 to 6 respectively, as shown in figure 1. To connect two cubes to each other, their adjacent faces must have the same connector type or the sum of their connector numbers must be equal to 7. Faculty will give ACM a map for constructing the build- ing. The building is actually an M × N × K rectangular prism. Furthermore, faculty has decided to have some of the blocks on some faces of the prism fixed. In other words, some of the blocks on the faces of the prism must have a pre- determined connector facing outside. Given a map for the building to be constructed, you must help ACM to decide whether it can build the requested building with respect to the limitations of the problem or not. Input The first line of the input file consists of a single integer 1 ≤ T ≤ 10, 000 , the total number of test cases. For each test case, there is a line indicating 1 ≤ M, N, K ≤ 10. After this line, comes the description of each face of the whole building. Each number shows that which face of a block must be seen in that position. Whenever a ‘?’ is represented, it means there is no difference in which face of the block to be used there. Only 3 faces of the whole prism are given. First you will see K rows each one with N columns, representing face T (top face of the building). Then, there is M rows each one with N columns, representing face F (front face) and at last, there is M rows each one with K columns, representing face R (right side face). The order each face is introduced is the same as figure 2. Output For each line of input, simply write ‘YES’ if it is possible to arrange blocks in some way which fits in the conditions of the input or write ‘NO’ if it is not possible. Sample Input 1 222 11 11 22 22 Figure 1. Shape of a block Figure 2. A 3 × 3 × 3 Construction

2/2 33 3? Sample Output YES