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<cstdio>
#include<string>
#include<iostream>
using namespace std;

string A(string str){
  char tmp;
  for(int i=0,j=str.length()-1;i<j;i++,j--){
    tmp=str[i];
    str[i]=str[j];
    str[j]=tmp;
  }
  return str;
}

string J(string str){
  char tmp;
  tmp=str[str.length()-1];
  for(int i=str.length()-1;i>0;i--)
    str[i]=str[i-1];
  str[0]=tmp;
  return str;
}

string C(string str){
  char tmp;
  tmp=str[0];
  for(int i=0;i<str.length()-1;i++)
    str[i]=str[i+1];

  str[str.length()-1]=tmp;
  return str;
}

string E(string str){
  string tmp,str2;
  if(str.length()%2){
    tmp=str.substr(0,str.length()/2);
    str2.assign(&str[str.length()/2+1],&str[str.length()]);
    str2+=str[str.length()/2];
    str2+=tmp;
  }else{
    tmp=str.substr(0,str.length()/2);
    str2.assign(&str[str.length()/2],&str[str.length()]);
    str2+=tmp;
  }
  return str2;
}

string P(string str){
  string num=("9012345678");
  for(int i=0;i<str.length();i++)
    if(str[i]>=0x30 && str[i]<=0x39)
      str[i]=num[str[i]-0x30];
  return str;
}

string M(string str){
  string num=("1234567890");
  for(int i=0;i<str.length();i++)
    if(str[i]>=0x30 && str[i]<=0x39)
      str[i]=num[str[i]-0x30];
  return str;
}

int main(){
  int n;
  string str1,str2;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    cin>> str1 >>str2;
    for(int i=str1.length()-1;i>=0;i--){
      switch(str1[i]){
      case 'A': str2=A(str2); break;
      case 'J': str2=J(str2); break;
      case 'C': str2=C(str2); break;
      case 'E': str2=E(str2); break;
      case 'P': str2=P(str2); break;
      case 'M': str2=M(str2); break;
      }
    }
    cout<< str2<< endl;
  }
  return 0;
}

C++: #pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using ull=unsigned long long int;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
int t;
cin>>t;
while(t--){
  string q;
  cin>>q;
  string s;
  cin>>s;
  int n=q.size(),m=s.size();
  reverse(all(q));
  for(int i=0;i<n;i++){
    string tmp={};
    if(q[i]=='J'){
      for(int j=0;j<m;j++){
        tmp.push_back(s[(j-1+m)%m]);
      }
      s=tmp;
    }
    if(q[i]=='C'){
      for(int j=0;j<m;j++){
        tmp.push_back(s[(j+1)%m]);
      }
      s=tmp;
    }
    if(q[i]=='E'){
      for(int j=(m+1)/2;j<m;j++){
        tmp.push_back(s[j]);
      }
      if(m%2==1)tmp.push_back(s[m/2]);
      for(int j=0;j<m/2;j++){
        tmp.push_back(s[j]);
      }
      s=tmp;
    }
    if(q[i]=='A'){
      reverse(all(s));
    }
    if(q[i]=='P'){
      for(int j=0;j<m;j++){
        if(int(s[j]-'0')<=10){
          s[j]=char((int(s[j]-'0')+9)%10+'0');
        }
      }
    }
     if(q[i]=='M'){
      for(int j=0;j<m;j++){
        if(int(s[j]-'0')<=10){
          s[j]=char((int(s[j]-'0')+1)%10+'0');
        }
      }
    }
  }
  cout<<s<<"\n";
}
}

C++: #include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main(){

	int n;
	string er, ge;
	char tmp;
	int mid;

	cin >> n;

	while (n--){
		cin >> er;
		cin >> ge;

		for (int i = er.size() - 1; i >= 0; i--){
			if (er[i] == 'J'){
				tmp = ge[ge.size() - 1];
				for (int j = ge.size() - 1; j > 0; j--){
					ge[j] = ge[j - 1];
				}
				ge[0] = tmp;
			}
			else if (er[i] == 'C'){
				tmp = ge[0];
				for (int j = 0; j < ge.size()-1; j++){
					ge[j] = ge[j + 1];
				}
				ge[ge.size()-1] = tmp;
			}
			else if (er[i] == 'E'){
				mid = ge.size() / 2 + ge.size() % 2;
				for (int i = 0; i < ge.size() / 2; i++){
					swap(ge[i], ge[i + mid]);
				}
			}
			else if (er[i] == 'A'){
				for (int i = 0; i < ge.size() / 2; i++){
					swap(ge[i], ge[ge.size()-1-i]);
				}
			}
			else if (er[i] == 'P'){
				for (int i = 0; i < ge.size(); i++){
					if ('0' <= ge[i] && ge[i] <= '9'){
						if (ge[i] == '0') ge[i] = '9';
						else ge[i]--;
					}
				}
			}
			else if (er[i] == 'M'){
				for (int i = 0; i < ge.size(); i++){
					if ('0' <= ge[i] && ge[i] <= '9'){
						if (ge[i] == '9') ge[i] = '0';
						else ge[i]++;
					}
				}
			}
		}
		cout << ge << endl;
	}

	return 0;
}