#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int n;
    cin >> n;

    while(--n >= 0){
        string order, s;
        cin >> order >> s;

        int m = s.size();
        for(int i=order.size()-1; i>=0; --i){
            if(order[i] == 'J'){
                rotate(s.begin(), s.end()-1, s.end());
            }else if(order[i] == 'C'){
                rotate(s.begin(), s.begin()+1, s.end());
            }else if(order[i] == 'E'){
                string s1, s2, s3;
                s1 = s.substr(0, m/2);
                s3 = s.substr((m+1)/2);
                if(m % 2 == 1)
                    s2 = s[m/2];
                s = s3 + s2 + s1;
            }else if(order[i] == 'A'){
                reverse(s.begin(), s.end());
            }else if(order[i] == 'P'){
                for(int j=0; j<m; ++j){
                    if('1' <= s[j] && s[j] <= '9')
                        -- s[j];
                    else if(s[j] == '0')
                        s[j] = '9';
                }
            }else{
                for(int j=0; j<m; ++j){
                    if('0' <= s[j] && s[j] <= '8')
                        ++ s[j];
                    else if(s[j] == '9')
                        s[j] = '0';
                }
            }
        }

        cout << s << endl;
    }

    return 0;
}