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;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9+7)
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}



int main() {
	int n;
	cin >> n;
	rep(i, n) {
		string order;
		string output;
		string tmp,tmp2;
		cin >> order >> output;
		reverse(all(order));
		rep(o, order.size()) {
			switch (order[o]) {
			case 'J':
				tmp = output.substr(0, output.size() - 1);
				output = output[output.size() - 1] + tmp;
				break;
			case 'C':
				tmp = output.substr(1, output.size() - 1);
				output = tmp+output[0];
				break;
			case 'E':
				tmp = output.substr(0, output.size() / 2);
				tmp2= output.substr((output.size() % 2)? output.size() / 2 +1: output.size() / 2, output.size() / 2 );
				if (output.size() % 2) {
					output = tmp2 + output[output.size() / 2] + tmp;
				}
				else {
					output = tmp2 + tmp;
				}
				break;
			case 'A':
				reverse(all(output));
				break;
			case 'P':
				rep(c , output.size()) {
					if (output[c] >= '1'&&output[c] <= '9') {
						output[c]--;
					}
					else if (output[c] == '0') {
						output[c] = '9';
					}
				}
				break;
			case 'M':
				rep(c, output.size()) {
					if (output[c] >= '0'&&output[c] <= '8') {
						output[c]++;
					}
					else if (output[c] == '9') {
						output[c] = '0';
					}
				}
				break;
			defalt:
				break;
			}
		}
		cout << output << endl;
	}

}

C++: #include <bits/stdc++.h>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

string fj(string arg){
	int n=arg.size();
	char last=arg[n-1];
	for(int i=n-2;i>=0;--i) arg[i+1]=arg[i];
	arg[0]=last;
	return arg;
}

string fc(string arg){
	int n=arg.size();
	char first=arg[0];
	for(int i=0;i<n-1;++i) arg[i]=arg[i+1];
	arg[n-1]=first;
	return arg;
}

string fe(string arg){
	int n=arg.size();
	int odd=n%2;
	for(int i=0;i<n/2;++i)
		swap(arg[i],arg[n/2+odd+i]);
	return arg;
}

string fa(string arg){
	reverse(arg.begin(),arg.end());
	return arg;
}

string fp(string arg){
	int n=arg.size();
	for(int i=0;i<n;++i){
		if(isdigit(arg[i])){
			int d=arg[i]-'0';
			d=(d+9)%10;
			arg[i]=(d+'0');
		}
	}
	return arg;
}

string fm(string arg){
	int n=arg.size();
	for(int i=0;i<n;++i){
		if(isdigit(arg[i])){
			int d=arg[i]-'0';
			d=(d+1)%10;
			arg[i]=(d+'0');
		}
	}
	return arg;
}

int main(void){
	int t;
	cin >> t;
	rep(loop,t){
		string decode,message;
		cin >> decode >> message;
		int n=decode.size();
		for(int i=n-1;i>=0;--i){
			char cur=decode[i];
			switch(cur){
				case 'A':
					message=fa(message);
					break;
				case 'C':
					message=fc(message);
					break;
				case 'E':
					message=fe(message);
					break;
				case 'J':
					message=fj(message);
					break;
				case 'M':
					message=fm(message);
					break;
				case 'P':
					message=fp(message);
					break;
			}
		}
		cout << message << endl;
	}
	return 0;
}