Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo()
	defer io.Flush()
	n := io.NextInt()
	for i := 0; i < n; i++ {
		s, t := io.NextLine(), io.NextLine()
		io.Println(f(s, t))
	}
}

func f(s, t string) string {
	for i := len(s) - 1; i >= 0; i-- {
		switch s[i] {
		case 'C':
			t = strings.Join([]string{t[1:], string(t[0])}, "")
		case 'J':
			t = strings.Join([]string{string(t[len(t)-1]), t[:len(t)-1]}, "")
		case 'E':
			if len(t)%2 == 1 {
				t = strings.Join([]string{t[len(t)/2+1:], string(t[len(t)/2]), t[:len(t)/2]}, "")
			} else {
				t = strings.Join([]string{t[len(t)/2:], t[:len(t)/2]}, "")
			}
		case 'A':
			r := []rune(t)
			for i, n := 0, len(r); i < n/2; i++ {
				r[i], r[n-i-1] = r[n-i-1], r[i]
			}
			t = string(r)
		case 'M':
			r := []rune(t)
			for i := 0; i < len(r); i++ {
				if '0' <= r[i] && r[i] < '9' {
					r[i]++
				} else if r[i] == '9' {
					r[i] = '0'
				}
			}
			t = string(r)
		case 'P':
			r := []rune(t)
			for i := 0; i < len(r); i++ {
				if '0' < r[i] && r[i] <= '9' {
					r[i]--
				} else if r[i] == '0' {
					r[i] = '9'
				}
			}
			t = string(r)
		}
	}
	return t
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := make([]interface{}, 0, len(a))
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := make([]interface{}, 0, len(a))
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
void f(string &ss,char c) {
    if(c == 'C') {
        char t = ss[0];
        rep(i,ss.size()-1) ss[i] = ss[i+1];
        ss[ss.size()-1] = t;
    }
    else if(c=='J') {
        char t = ss[ss.size()-1];
        for(int i = ss.size()-1; i>=1; i--) ss[i] = ss[i-1];
        ss[0] = t;
    }
    else if(c=='E') {
        string l = ss.substr(0,ss.size()/2);
        string r = ss.substr((ss.size()+1)/2,ss.size()/2);
        string center = "";
            
        if(ss.size()&1) {
            center = ss[ss.size()/2];

        }
        ss = r + center + l;
    }
    else if(c=='A') {
        reverse(ss.begin(), ss.end());
    }
    else if(c=='M') {
        rep(i,ss.size()) {
            if('0'<=ss[i]&&ss[i]<='9') {
                if('9'==ss[i]) ss[i] = '0';
                else ss[i]++;
            }
        }
    }
    else if(c=='P') {
        rep(i,ss.size()) {
            if('0'<=ss[i]&&ss[i]<='9') {
                if('0'==ss[i]) ss[i] = '9';
                else ss[i]--;
            }
        }

    }
}
int main() {
    int n;
    cin>>n;
    rep(i,n) {
        string ss1,ss2;
        cin>>ss1>>ss2;
        reverse(ss1.begin(),ss1.end());
        rep(j,ss1.size()) f(ss2,ss1[j]);
        cout<<ss2<<endl;
    }

    return 0;
}

C++: #define  _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#pragma comment (linker, "/STACK:526000000")

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(10);
}

#define int ll
string C(string a) {
	REP(q, a.length()-1) {
		swap(a[q], a[q + 1]);
	}
	return a;
}
string J(string a) {
	for (int q = a.length() - 1; q >= 1; --q) {
		swap(a[q], a[q - 1]);
	}
	return a;
}
string E(string a) {
	int hoge = (a.length() + 1) / 2;
	for (int q = 0; q < a.length() / 2; ++q) {
		swap(a[q], a[q + hoge]);
	}
	return a;
}
string A(string a) {
	reverse(ALL(a));
	return a;
}

string P(string a) {
	REP(i, a.length()) {
		if (a[i] >= '0' && a[i] <= '9') {
			if (a[i] == '0') {
				a[i] = '0' + 10;
			}
			a[i]--;
		}
	}
	return a;
}

string M(string a) {
	REP(i, a.length()) {
		if (a[i] >= '0' && a[i] <= '9') {
			if (a[i] == '9') {
				a[i] = '0' -1;
			}
			a[i]++;
		}
	}
	return a;
}
void solve() {
	int n;
	cin >> n;
	REP(i, n) {
		string a, b;
		cin >> a >> b;
		for (int i = a.length() - 1; i >= 0; --i) {
			if (a[i] == 'C') {
				b = C(b);
			}
			else if (a[i] == 'J') {
				b = J(b);
			}
			else if (a[i] == 'E') {
				b = E(b);
			}
			else if (a[i] == 'P') {
				b = P(b);
			}
			else if (a[i] == 'A') {
				b = A(b);
			}
			else {
				b = M(b);
			}
		}
		cout << b << endl;
	}
}
#undef int

int main() {
	init();
	solve();
}

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
	int n;
	cin >> n;
	while (n--)
	{
		string a, b;
		cin >> b >> a;
		reverse(b.begin(),b.end());
		for (int i = 0; i < b.size(); i++)
		{
			if (b[i] == 'A')
				reverse(a.begin(), a.end());
			else if (b[i] == 'C')
			{
				string temp;
				temp = a[0];
				a.erase(a.begin(), a.begin() + 1);
				a += temp;
			}
			else if (b[i] == 'J')
			{
				string temp;
				temp = a[a.size() - 1];
				reverse(a.begin(), a.end());
				a.erase(a.begin(), a.begin() + 1);
				reverse(a.begin(), a.end());
				temp += a;
				a.clear();
				a = temp;
			}
			else if (b[i] == 'E')
			{
				string temp, temp2;
				if (a.size() % 2 == 0)
				{
					temp = a.substr(0, a.size() / 2);
					temp2 = a.substr(a.size() / 2, a.size());
					a.clear();
					a = temp2 + temp;
				}
				else if (a.size() % 2 != 0)
				{
					temp = a.substr(0, a.size() / 2+1);
					temp2 = a.substr(a.size() / 2 + 1, a.size());
					a.clear();
					a.push_back(temp[temp.size() - 1]);
					reverse(temp.begin(), temp.end());
					temp.erase(temp.begin(), temp.begin() + 1);
					reverse(temp.begin(), temp.end());
					temp2 +=a+temp;
					a.clear();
					a = temp2;
				}
			}
			else if (b[i] == 'P')
			{
				for (int i = 0; i < a.size(); i++)
				{
					if (a[i] >= '0' && a[i] <= '9')
					{
						if (a[i] == '9')
							a[i] = '0';
						else if (a[i] == '0')
							a[i] = '9';
						else (int)a[i]--;
					}
				}
			}
			else if (b[i] == 'M')
			{
				for (int i = 0; i < a.size(); i++)
				{
					if (a[i] >= '0' && a[i] <= '9')
					{
						if ((int)a[i] == '0')
							a[i] = '9';
						else if ((int)a[i] == '9')
							a[i] = '0';
						else (int)a[i]++;
					}
				}
			}
		}
		cout << a << endl;
	}

}