#include<iostream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cctype>

using namespace std;

string revJ(string t){
ÃÂ ÃÂ string ret = t;
ÃÂ ÃÂ ret.insert(ret.begin(),t[t.length()-1]);
ÃÂ ÃÂ ret.erase(ret.end()-1);
ÃÂ ÃÂ return ret;
}
string revC(string t){
ÃÂ ÃÂ string ret = t;
ÃÂ ÃÂ ret += t[0];
ÃÂ ÃÂ ret.erase(ret.begin());
ÃÂ ÃÂ return ret;
}
string revE(string t){
ÃÂ ÃÂ char c=0;
ÃÂ ÃÂ if(t.length()==1)return t;
ÃÂ ÃÂ if(t.length()%2){
ÃÂ ÃÂ  ÃÂ c = t[t.length()/2];
ÃÂ ÃÂ  ÃÂ t.erase(t.begin()+t.length()/2);
ÃÂ ÃÂ }
ÃÂ ÃÂ string l = t.substr(0,t.length()/2);
ÃÂ ÃÂ string r = t.substr(t.length()/2,t.length()-t.length()/2);
ÃÂ ÃÂ if(c){
ÃÂ ÃÂ  ÃÂ return r+c+l;
ÃÂ ÃÂ }else return r+l;
}
string revA(string t){
ÃÂ ÃÂ string ret = t;
ÃÂ ÃÂ reverse(ret.begin(),ret.end());
ÃÂ ÃÂ return ret;
}
string revP(string t){
ÃÂ ÃÂ //dec
ÃÂ ÃÂ string ret = t;
ÃÂ ÃÂ for(int i = 0; i < (signed)ret.length(); ++i){
ÃÂ ÃÂ  ÃÂ if( isdigit(ret[i]) ){
ÃÂ ÃÂ  ÃÂ  ÃÂ ret[i]--;
ÃÂ ÃÂ  ÃÂ  ÃÂ if(ret[i]<'0')ret[i]='9';
ÃÂ ÃÂ  ÃÂ }
ÃÂ ÃÂ }
ÃÂ ÃÂ return ret;
}
string revM(string t){
ÃÂ ÃÂ //inc
ÃÂ ÃÂ string ret = t;
ÃÂ ÃÂ for(int i = 0; i < (signed)ret.length(); ++i){
ÃÂ ÃÂ  ÃÂ if( isdigit(ret[i]) ){
ÃÂ ÃÂ  ÃÂ  ÃÂ ret[i]++;
ÃÂ ÃÂ  ÃÂ  ÃÂ if(ret[i]>'9')ret[i]='0';
ÃÂ ÃÂ  ÃÂ }
ÃÂ ÃÂ }
ÃÂ ÃÂ return ret;
}

int main()
{
ÃÂ ÃÂ int n;
ÃÂ ÃÂ cin >> n;
ÃÂ ÃÂ for(int i = 0; i < n; ++i){
ÃÂ ÃÂ  ÃÂ string order;
ÃÂ ÃÂ  ÃÂ string msg;
ÃÂ ÃÂ  ÃÂ cin >> order >> msg;
ÃÂ ÃÂ  ÃÂ for(int i = (int)order.length()-1; i>=0; --i){
ÃÂ ÃÂ  ÃÂ  ÃÂ if( order[i] == 'J' ){
	msg = revJ( msg );
ÃÂ ÃÂ  ÃÂ  ÃÂ }
ÃÂ ÃÂ  ÃÂ  ÃÂ if( order[i] == 'C' ){
	msg = revC( msg );
ÃÂ ÃÂ  ÃÂ  ÃÂ }
ÃÂ ÃÂ  ÃÂ  ÃÂ if( order[i] == 'E' ){
	msg = revE( msg );
ÃÂ ÃÂ  ÃÂ  ÃÂ }
ÃÂ ÃÂ  ÃÂ  ÃÂ if( order[i] == 'A' ){
	msg = revA( msg );
ÃÂ ÃÂ  ÃÂ  ÃÂ }
ÃÂ ÃÂ  ÃÂ  ÃÂ if( order[i] == 'P' ){
	msg = revP( msg );
ÃÂ ÃÂ  ÃÂ  ÃÂ }
ÃÂ ÃÂ  ÃÂ  ÃÂ if( order[i] == 'M' ){
	msg = revM( msg );
ÃÂ ÃÂ  ÃÂ  ÃÂ }
ÃÂ ÃÂ  ÃÂ }
ÃÂ ÃÂ  ÃÂ cout << msg << endl;
ÃÂ ÃÂ }
ÃÂ ÃÂ return 0;
}