#include <iostream>
#include <string>

using namespace std;

int main() {
	int n;
	string a, b;
	string p1 = "98765432109";
	string p2 = "01234567890";
	cin >> n;
	getline(cin, a);
	for (int i = 0; i < n; i++) {
		getline(cin, a);
		getline(cin, b);
		for (int j = a.size()-1; j >= 0; j--) {
			if (a[j] == 'J') {
				string c = "";
				c += b[b.size()-1];
				b = b.substr(0, b.size()-1);
				c += b;
				b = c;
			} else if (a[j] == 'C') {
				string c = "";
				c = b.substr(1);
				c += b[0];
				b = c;
			} else if (a[j] == 'E') {
				string c1 = b.substr(0, b.size()/2);
				if (b.size() % 2 == 0) {
					string c2 = b.substr(b.size()/2);
					b = c2+c1;
				} else {
					string c2 = b.substr(b.size()/2+1);
					string c3 = "";
					c3 += b[b.size()/2];
					b = c2+c3+c1;
				}
			} else if (a[j] == 'A') {
				string c = "";
				for (int k = b.size()-1; k >= 0; k--) {
					c += b[k];
				}
				b = c;
			} else if (a[j] == 'P') {
				for (int k = 0; k < b.size(); k++) {
					if (0 <= b[k]-'0' && b[k]-'0' <= 9) {
						for (int l = 0; l < p1.size()-1; l++) {
							if (b[k] == p1[l]) {
								b[k] = p1[l+1];
								break;
							}
						}
					}
				}
			} else {
				for (int k = 0; k < b.size(); k++) {
					if (0 <= b[k]-'0' && b[k]-'0' <= 9) {
						for (int l = 0; l < p2.size()-1; l++) {
							if (b[k] == p2[l]) {
								b[k] = p2[l+1];
								break;
							}
						}
					}
				}
			}
		}
		cout << b << endl;
	}
	return 0;
}