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>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
void chmes(string &s,char me){
  if(me == 'C'){
    string tmp="";
    for(int i=1;i<s.size();i++){
      tmp+=s[i];
    }
    tmp += s[0];
    s = tmp;
  }else if(me == 'J'){
    string tmp="";
    tmp+=s.back();
    for(int i=0;i<s.size()-1;i++){
      tmp+=s[i];
    }
    s = tmp;
  }else if(me == 'E'){
    if(s.size()%2 == 1){
      string tmp1="",tmp2="";
      for(int i=0;i<s.size()/2;i++){
	tmp1+=s[i];
	tmp2+=s[s.size()/2+i+1];
      }
      char hge = s[s.size()/2];
      s = tmp2;
      s+= hge;
      s += tmp1;
    }else{
      string tmp1="",tmp2="";
      for(int i=0;i<s.size()/2;i++){
	tmp1+=s[i];
	tmp2+=s[s.size()/2+i];
      }
      s = tmp2+tmp1;
      // cout<<"!"<<s<<endl;
    }
  }else if(me == 'A'){
    reverse(ALL(s));
  }else if(me == 'M'){
    for(int i=0;i<s.size();i++){
      if(isdigit(s[i])){
	s[i] = (char)('0'+(s[i]-'0'+1)%10);
      }
    }
  }else{
    for(int i=0;i<s.size();i++){
      if(isdigit(s[i])){
	s[i] = (char)('0'+(s[i]-'0'+9)%10);
      }
    }
  }
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  for(int i=0;i<n;i++){
    string s,ss;
    cin>>s>>ss;
    reverse(ALL(s));
    for(auto a:s){
      chmes(ss,a);
    }
    cout<<ss<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

int main(void) {
  ll N;
  cin >> N;
  vector<string> order(N), message(N);
  REP(i, 0, N) cin >> order[i] >> message[i];

  REP(i, 0, N) {
    string s(message[i]);
    ll l = message[i].length();

    REP(j, 0, order[i].size()) {
      char c = order[i][order[i].size() - j - 1];
      string t(s);

      if(c == 'J') {
        REP(k, 0, l) t[(k + 1 + l) % l] = s[k];
      }
      if(c == 'C') {
        REP(k, 0, l) t[(k - 1 + l) % l] = s[k];
      }
      if(c == 'E') {
        REP(k, 0, l / 2) swap(t[k], t[k + l / 2 + l % 2]);
      }
      if(c == 'A') {
        reverse(t.begin(), t.end());
      }
      if(c == 'P') {
        REP(k, 0, l) if('0' <= t[k] && t[k] <= '9') {
          t[k] = (t[k] - 1 - '0' + 10) % 10 + '0';
        }
      }
      if(c == 'M') {
        REP(k, 0, l) if('0' <= t[k] && t[k] <= '9') {
          t[k] = (t[k] + 1 - '0' + 10) % 10 + '0';
        }
      }

      swap(s, t);
    }

    cout << s << endl;
  }
}

C++: #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;
}