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 endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    for(int i=0; i<N; i++){
        string order,S;
        cin >> order >> S;
        reverse(order.begin(),order.end());
        for(int j=0; j<order.size(); j++){
            char now = order[j];
            if(now == 'J'){
                S = S.back() + S;
                S.pop_back();
            }else if(now == 'C'){
                S += S[0];
                S.erase(S.begin());
            }else if(now == 'E'){
                if(S.size()%2){
                    S = S.substr(S.size()/2+1) + S[S.size()/2] + S.substr(0,S.size()/2);
                }else{
                    S = S.substr(S.size()/2) + S.substr(0,S.size()/2);
                }
            }else if(now == 'A'){
                reverse(S.begin(),S.end());
            }else if(now == 'M'){
                for(int k=0; k<S.size(); k++){
                    if('0'<=S[k] and S[k]<='9'){
                        S[k] = (S[k]-'0'+1)%10 + '0';
                    }
                }
            }else{
                for(int k=0; k<S.size(); k++){
                    if('0'<=S[k] and S[k]<='9'){
                        S[k] = (S[k]-'0'-1+10)%10 + '0';
                    }
                }
            }
        }
        cout << S << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
void conv(string &S, char c){
  if (c == 'J'){
    S = S.back() + S.substr(0, S.size() - 1);
  }
  if (c == 'C'){
    S =  S.substr(1) + S[0];
  }
  if (c == 'E'){
    if (S.size() % 2 == 0){
      S = S.substr(S.size() / 2) + S.substr(0, S.size() / 2);
    } else {
      S = S.substr(S.size() / 2 + 1) + S[S.size() / 2] + S.substr(0, S.size() / 2);
    }
  }
  if (c == 'A'){
    reverse(S.begin(), S.end());
  }
  if (c == 'P'){
    for (int i = 0; i < S.size(); i++){
      if (S[i] == '0'){
        S[i] = '9';
      } else if ('1' <= S[i] && S[i] <= '9'){
        S[i]--;
      }
    }
  }
  if (c == 'M'){
    for (int i = 0; i < S.size(); i++){
      if (S[i] == '9'){
        S[i] = '0';
      } else if ('0' <= S[i] && S[i] <= '8'){
        S[i]++;
      }
    }
  }
}
int main(){
  int n;
  cin >> n;
  for (int i = 0; i < n; i++){
    string S;
    cin >> S;
    string T;
    cin >> T;
    int m = S.size();
    for (int j = m - 1; j >= 0; j--){
      conv(T, S[j]);
    }
    cout << T << endl;
  }
}

C++: #include <iostream>
#include <string>
#include <deque>
#include <algorithm>
#include <cctype>
using namespace std;

int main(){
	int n, m;
	for(cin >> n; n--; ){
		string cmd, msgstr;
		cin >> cmd >> msgstr;
		
		deque<char> msg(msgstr.begin(), msgstr.end());
		deque<char>::iterator it1, it2;
		
		for(int i = cmd.size() - 1; i >= 0; --i){
			switch(cmd[i]){
				case 'J':
					msg.push_front( msg.back() );
					msg.pop_back();
					break;
				case 'C':
					msg.push_back( msg.front() );
					msg.pop_front();
					break;
				case 'E':
					m = msg.size() / 2;
					it1 = msg.begin();
					it2 = msg.end() - m;
					while( m-- ){
						swap( *it1++, *it2++ );
					}
					break;
				case 'A':
					reverse(msg.begin(), msg.end());
					break;
				case 'P':
					for(it1 = msg.begin(); it1 != msg.end(); ++it1){
						if( isdigit(*it1) ){
							*it1 = (*it1 == '0' ? '9' : *it1 - 1);
						}
					}
					break;
				case 'M':
					for(it1 = msg.begin(); it1 != msg.end(); ++it1){
						if( isdigit(*it1) ){
							*it1 = (*it1 == '9' ? '0' : *it1 + 1);
						}
					}
					break;
			}
		}
		
		cout << string(msg.begin(), msg.end()) << '\n';
	}
}