/* 18:10 */ #include #include #include #include #include using namespace std; struct coord_t { int x, y; }; bool operator<(const coord_t &p1, const coord_t &p2) { if (p1.x == p2.x) { return p1.y < p2.y; } return p1.x < p2.x; } bool operator==(const coord_t &p1, const coord_t &p2) { return (p1.x == p2.x) && (p1.y == p2.y); } static int dx[6] = {1, 1, 0, -1, -1, 0}; static int dy[6] = {0, 1, 1, 0, -1, -1}; void make_eggs(string s, int offset, set &result) { int minx = 0, miny = 0; coord_t p; list unnormalized; p.x = p.y = 0; unnormalized.push_back(p); for (int i = 0; i < s.length(); i++) { p.x = p.x + dx[(s[i]+offset-'a') % 6]; p.y = p.y + dy[(s[i]+offset-'a') % 6]; if (minx > p.x) { minx = p.x; } if (miny > p.y) { miny = p.y; } unnormalized.push_back(p); } /* Normalize */ for (list::iterator p = unnormalized.begin(); p != unnormalized.end(); p++) { p->x -= minx; p->y -= miny; } result.insert(unnormalized.begin(), unnormalized.end()); } int main() { int I, N, i, j; string s, st, sh; cin >> N; getline(cin, s); for (I = 0; I < N; I++) { getline(cin, st); getline(cin, sh); getline(cin, s); if (st.length() != sh.length()) { cout << "false" << endl; continue; } bool flag = false; set rt; make_sequence(st, 0, rt); for (i = 0; i < 6; i++) { set rh; make_eggs(sh, i, rh); if (rt == rh) { flag = true; break; } } if (flag) { cout << "true" << endl; } else { cout << "false" << endl; } } return 0; }