#include <iostream>
#include <algorithm>
#include <cctype>
#include <string>
using namespace std;
 
string oom, mes;
 
 
void rJ() {
  const string tmp = mes;
  mes = tmp[tmp.length()-1] + tmp.substr(0, tmp.length()-1);
}
void rC() {
  const string tmp = mes;
  mes = tmp.substr(1) + tmp[0];
}
void rE() {
  string l = mes.substr(0, mes.length()/2);
  string r = mes.substr((mes.length()+1)/2);
  if(mes.length() % 2 != 0) {
    mes = r + mes[mes.length()/2] + l;
  } else {
    mes = r + l;
  }
}
void rA() {
  reverse(mes.begin(), mes.end());
}
 
void rP() {
  for(int i = 0; i < mes.length(); ++i) {
    if(isdigit(mes[i])) {
      mes[i] = (mes[i]-'0'+9)%10+'0';
    }
  }
}
void rM() {
  for(int i = 0; i < mes.length(); ++i) {
    if(isdigit(mes[i])) {
      mes[i] = (mes[i]-'0'+1)%10+'0';
    }
  }
}
 
void solve() {
  reverse(oom.begin(), oom.end());
  for(int i = 0; i < oom.length(); ++i) {
    switch(oom[i]) {
    case 'J': rJ(); break;
    case 'C': rC(); break;
    case 'E': rE(); break;
    case 'A': rA(); break;
    case 'P': rP(); break;
    case 'M': rM(); break;
    }
  }
  cout << mes << endl;
}
 
int main() {
  int n;
  cin >> n;
  for(int i = 0; i < n; ++i) {
    cin >> oom;
    cin >> mes;
    solve();
  }
}