#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s, t;
    cin >> t >> s;
    int sz = s.size();
    for (int j = t.size() - 1; j >= 0; j--) {
      string ns;
      if (t[j] == 'J') {
        ns += s[sz - 1];
        ns += s.substr(0, sz - 1);
      }
      if (t[j] == 'C') {
        ns += s.substr(1, sz - 1);
        ns += s[0];
      }
      if (t[j] == 'E') {
        int hf = sz / 2;
        ns += s.substr((sz + 1) / 2, hf);
        if (sz % 2) ns += s[hf];
        ns += s.substr(0, hf);
      }
      if (t[j] == 'A') {
        reverse(s.begin(), s.end());
        ns = s;
      }
      if (t[j] == 'P') {
        for (int k = 0; k < sz; k++) {
          if (s[k] >= '0' && s[k] <= '9') {
            if (s[k] == '0') {
              s[k] = '9';
            } else {
              s[k]--;
            }
          }
        }
        ns = s;
      }
      if (t[j] == 'M') {
        for (int k = 0; k < sz; k++) {
          if (s[k] >= '0' && s[k] <= '9') {
            if (s[k] == '9') {
              s[k] = '0';
            } else {
              s[k]++;
            }
          }
        }
        ns = s;
      }
      s = ns;
      cout << t[j] << endl;
      cout << s << endl;
    }
  }
  return 0;
}
