#include #include #include using namespace std; main() { int loop; cin >> loop; while (loop--){ string command, s; cin >> command >> s; reverse(command.begin(), command.end()); for (string::iterator it = command.begin(); it != command.end(); ++it){ if (*it == 'J'){ rotate(s.begin(), s.end() - 1, s.end()); } else if (*it == 'C'){ rotate(s.begin(), s.begin() + 1, s.end()); } else if (*it == 'E'){ string s1 = s.substr(0, s.size() / 2); string s2 = s.substr(s.size() / 2, s.size() % 2); string s3 = s.substr(s.size() - s.size() / 2, s.size()); s = s3 + s2 + s1; } else if (*it == 'A'){ reverse(s.begin(), s.end()); } else if (*it == 'P'){ for (string::iterator it = s.begin(); it != s.end(); ++it){ if (isdigit(*it)){ int i = *it - '0'; if (--i < 0){ i += 10; } *it = (char)i + '0'; } } } else if (*it == 'M'){ for (string::iterator it = s.begin(); it != s.end(); ++it){ if (isdigit(*it)){ int i = *it - '0'; ++i; i %= 10; *it = (char)i + '0'; } } } } cout << s << endl; } }