[Link] https://www.acmicpc.net/problem/5373


Axis Setting

Cube[6] 0,3 +-X, 1,4 +=Y, 2,5 +=Z Cube[][i][j] i, j: X,Y,Z coordinate


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <stack>
#include <cmath>
// #include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define command_param int argc, char *argv[]
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i < n; i++)
#define fori(s, e) for(int i = s; i < e; i++)
#define ll long long
#define endl "\n"
#define nulls '\0'
#define dkdk " "

const int INF = 987654321;
int n, t;
char cube[6][3][3];
char color[6] = { 'g', 'r', 'w', 'b', 'o', 'y' };

void rotate_face(int face_idx, bool clock) {
  char store[2] = { cube[face_idx][0][0], cube[face_idx][1][0] }, tmp[2];
  if(clock) {
    for0(i, 2) tmp[i] = cube[face_idx][0][2-i];
    for0(i, 2) cube[face_idx][0][2-i] = store[i], store[i] = tmp[i];

    for0(i, 2) tmp[i] = cube[face_idx][2-i][2];
    for0(i, 2) cube[face_idx][2-i][2] = store[i], store[i] = tmp[i];

    for0(i, 2) tmp[i] = cube[face_idx][2][i];
    for0(i, 2) cube[face_idx][2][i] = store[i], store[i] = tmp[i];
  } else {
    for0(i, 2) tmp[i] = cube[face_idx][2][i];
    for0(i, 2) cube[face_idx][2][i] = store[i], store[i] = tmp[i];

    for0(i, 2) tmp[i] = cube[face_idx][2-i][2];
    for0(i, 2) cube[face_idx][2-i][2] = store[i], store[i] = tmp[i];

    for0(i, 2) tmp[i] = cube[face_idx][0][2-i];
    for0(i, 2) cube[face_idx][0][2-i] = store[i], store[i] = tmp[i];
  }
  for0(i, 2) cube[face_idx][i][0] = store[i];
}

void rotate_cube(char face, bool clock) {
  if(face == 'U' || face == 'D') {
    clock = clock ^ (face == 'D');
    rotate_face(face == 'U' ? 2 : 5, clock);
    int h = face == 'U' ? 2 : 0;
    char store[3]; char tmp[3]; for0(i, 3) store[i] = cube[4][h][i];
    if(clock) {
      for0(i, 3) tmp[i] = cube[3][2-i][h];
      for0(i, 3) cube[3][2-i][h] = store[i], store[i] = tmp[i];
      for0(i, 3) tmp[i] = cube[1][h][2-i];
      for0(i, 3) cube[1][h][2-i] = store[i], store[i] = tmp[i];
      for0(i, 3) tmp[i] = cube[0][i][h];
      for0(i, 3) cube[0][i][h] = store[i], store[i] = tmp[i];
    } else {
      for0(i, 3) tmp[i] = cube[0][i][h];
      for0(i, 3) { cube[0][i][h] = store[i];  store[i] = tmp[i]; }
      for0(i, 3) tmp[i] = cube[1][h][2-i];
      for0(i, 3) cube[1][h][2-i] = store[i], store[i] = tmp[i];
      for0(i, 3) tmp[i] = cube[3][2-i][h];
      for0(i, 3) cube[3][2-i][h] = store[i], store[i] = tmp[i];
    }
    for0(i, 3) cube[4][h][i] = store[i];
  }
  if(face == 'F' || face == 'B') {
    clock = clock ^ (face == 'B');
    rotate_face(face == 'F' ? 1 : 4, clock);
    int h = face == 'F' ? 2 : 0;
    char store[3], tmp[3]; for0(i, 3) store[i] = cube[2][2-i][h];
    if(clock) {
      for0(i, 3) tmp[i] = cube[3][h][2-i];
      for0(i, 3) cube[3][h][2-i] = store[i], store[i] = tmp[i];
      for0(i, 3) tmp[i] = cube[5][i][h];
      for0(i, 3) cube[5][i][h] = store[i], store[i] = tmp[i];
      for0(i, 3) tmp[i] = cube[0][h][i];
      for0(i, 3) cube[0][h][i] = store[i], store[i] = tmp[i];
    } else {
      for0(i, 3) tmp[i] = cube[0][h][i];
      for0(i, 3) cube[0][h][i] = store[i], store[i] = tmp[i];
      for0(i, 3) tmp[i] = cube[5][i][h];
      for0(i, 3) cube[5][i][h] = store[i], store[i] = tmp[i];
      for0(i, 3) tmp[i] = cube[3][h][2-i];
      for0(i, 3) cube[3][h][2-i] = store[i], store[i] = tmp[i];
    }
    for0(i, 3) cube[2][2-i][h] = store[i];
  }
  if(face == 'L' || face == 'R') {
    clock = clock ^ (face == 'R');
    rotate_face(face == 'L' ? 0 : 3, clock);
    int h = face == 'L' ? 2 : 0;
    char store[3], tmp[3]; for0(i, 3) store[i] = cube[2][h][i];
    if(clock) {
      for0(i, 3) tmp[i] = cube[1][2-i][h];
      for0(i, 3) cube[1][2-i][h] = store[i], store[i] = tmp[i];
      for0(i, 3) tmp[i] = cube[5][h][2-i];
      for0(i, 3) cube[5][h][2-i] = store[i], store[i] = tmp[i];
      for0(i, 3) tmp[i] = cube[4][i][h];
      for0(i, 3) cube[4][i][h] = store[i], store[i] = tmp[i];
    } else {
      for0(i, 3) tmp[i] = cube[4][i][h];
      for0(i, 3) cube[4][i][h] = store[i], store[i] = tmp[i];
      for0(i, 3) tmp[i] = cube[5][h][2-i];
      for0(i, 3) cube[5][h][2-i] = store[i], store[i] = tmp[i];
      for0(i, 3) tmp[i] = cube[1][2-i][h];
      for0(i, 3) cube[1][2-i][h] = store[i], store[i] = tmp[i];
    }
    for0(i, 3) cube[2][h][i] = store[i];
  }
}

int main(int argc, char *argv[]) {
  FASTIO; cin >> t;
  while(t--) {
    cin >> n;
    for0(i, 6) for0(j, 3) for0(k, 3) cube[i][j][k] = color[i];
    for0(i, n) {
      string cmd; cin >> cmd;
      rotate_cube(cmd[0], cmd[1] == '+');
    }
    for0(j, 3) { for0(i, 3) cout << cube[2][2-i][j]; cout << endl; }
  }
  return 0;
}