#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  int n;
  string oom, mkg;
  cin >> n;
  for (int z = 0; z < (int)(n); z++) {
    cin >> oom >> mkg;
    for (int j = oom.size() - 1; j >= 0; j--) {
      char p = oom[j];
      switch (p) {
        case 'J':
          for (int i = (int)mkg.size() - 2; i >= 0; i--)
            swap(mkg[i], mkg[i + 1]);
          break;
        case 'C':
          for (int i = 0; i <= (int)mkg.size() - 2; i++)
            swap(mkg[i], mkg[i + 1]);
          break;
        case 'E': {
          int offset = mkg.size() - mkg.size() / 2;
          for (int i = 0; i < (int)mkg.size() / 2; i++)
            swap(mkg[i], mkg[i + offset]);
          break;
        }
        case 'A':
          for (int i = 0; i < (int)mkg.size() / 2; i++)
            swap(mkg[i], mkg[mkg.size() - 1 - i]);
          break;
        case 'P':
          for (char& c : mkg)
            if (c >= '1' && c <= '9')
              c--;
            else if (c == '0')
              c = '9';
          break;
        case 'M':
          for (char& c : mkg)
            if (c >= '0' && c <= '8')
              c++;
            else if (c == '9')
              c = '0';
          break;
      }
      cout << "--" << mkg << endl;
    }
    cout << mkg << endl;
  }
}
