import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);for(int t=s.nextInt(),l,i,j,c,d;t-->0;){String o=s.next();char[]a=s.next().toCharArray(),b;l=a.length;for(i=o.length();i-->0;){b=a.clone();c=o.charAt(i);if(c!=69)for(j=0;j<l;++j)if(c==80||c==77)a[j]=(char)(47<(d=b[j])&&d<58?c>77?d-1<48?57:d-1:d+1>57?48:d+1:d);else a[j]=b[c<67?l-j-1:c<74?(j+1)%l:(j+l-1)%l];else for(j=0;j<l/2;a[j+l/2+(l%2<1?0:1)]=b[j++])a[j]=b[j+l/2+(l%2<1?0:1)];}System.out.println(new String(a));}}}