/*

NAME Iulian RADU

SCHOOL Grigore Moisil NCSC

GRADE 10

DIVISION INT5

*/

#include <cstring>

#include <iostream>

#include <cstdio>

 

char x,fct[100],a[100],b[100];

int nr,i,j,y,k,v;

 

using namespace std;

 

int main()

{

    freopen("cells.in","r",stdin);

//    freopen("cells.out","w",stdout);

    for(i=1;i<=5;i++)

    {

        nr=0;

        scanf("%c",&x);

        while(x!=',')

        {

            fct[nr]=x;

            nr++;

            scanf("%c",&x);

        }

        if((fct[0]=='D')||(fct[0]=='A')||(fct[0]=='S'))

        {

            scanf(" ");

            for(j=0;j<=7;j++)

            {

                scanf("%c",&a[j]);

            }

            scanf("\n");

        }

        else

        {

            scanf(" ");

            for(j=0;j<=7;j++)

            {

                scanf("%c",&a[j]);

            }

            scanf(", ");

            for(j=0;j<=7;j++)

            {

                scanf("%c",&b[j]);

            }

            scanf("\n");

        }

        if(fct[0]=='D')

        {

            for(j=1;j<=2;j++)

                printf("%c%c%c%c",a[0],a[1],a[2],a[3]);

            printf(" and ");

            for(j=1;j<=2;j++)

                printf("%c%c%c%c",a[4],a[5],a[6],a[7]);

            printf("\n");

        }

        if(fct[0]=='U')

        {

            printf("%c%c%c%c%c%c%c%c\n",a[4],a[5],a[6],a[7],b[0],b[1],b[2],b[3]);

        }

        if(fct[0]=='I')

        {

            printf("%c%c%c%c%c%c%c%c\n",a[0],a[1],a[6],a[7],b[0],b[1],b[6],b[7]);

        }

        if(fct[0]=='A')

        {

            y=fct[3]-'0';

            for(j=1;j<=2;j++)

            {

                for(k=0;k<y;k++)

                {

                    printf("%c",a[k]);

                }

            }

            for(j=y;j<=7-y;j++)

                printf("%c",a[j]);

            printf("\n");

        }

        if(fct[0]=='S')

        {

            v=fct[8]-'0';

            for(j=v;j<=7;j++)

            {

                printf("%c",a[j]);

            }

            for(j=8-v;j<=7;j++)

            {

                printf("%c",a[j]);

            }

            printf("\n");

        }

    }

    return 0;

}