/*
AizuOnline A1104
Title
*/
#include <stdio.h>
#include <string.h>
#define min(x,y) (((x)<(y))?(x):(y))
#define max(x,y) (((x)>(y))?(x):(y))

//Global data section
int x,y;
int w,h;
char dir;
char *dd="NESW";
char directive[10];
int operand;
//
main()
{
        while(EOF!=scanf("%d %d",&w,&h) && (w||h))
        {
#ifdef DEBUG
                printf("%d %d\n",w,h);
#endif
                x=1;y=1;dir=0;

                while(1)
                {
                        scanf("%s ",directive);
                        if(0==strcmp("STOP",directive))         
                                break;
                        if(0==strcmp("LEFT",directive))
                                dir=(dir+3)%4;
                        if(0==strcmp("RIGHT",directive))
                                dir=(dir+1)%4;
                        if(0==strcmp("FORWARD",directive))
                        {
                                scanf("%d",&operand);
#ifdef DEBUG
                        printf("%s %d\n",directive,operand);
#endif
                                switch( dir)
                                {
                                case 0:
                                        y=min(y+operand,h);
                                        break;
                                case 1:
                                        x=min(x+operand,w);
                                        break;
                                case 2:
                                        y=max(y-operand,1);
                                        break;
                                case 3:
                                        x=max(x-operand,1);
                                        break;
                                }
#ifdef DEBUG
                                printf("%d %d %d\n",dir,x,y);
#endif

                        }
                        if(0==strcmp("BACKWARD",directive))
                        {
                                scanf("%d",&operand);
#ifdef DEBUG
                        printf("%s %d\n",directive,operand);
#endif
                                switch( dir)
                                {
                                case 2:
                                        y=min(y+operand,h);
                                        break;
                                case 3:
                                        x=min(x+operand,w);
                                        break;
                                case 0:
                                        y=max(y-operand,1);
                                        break;
                                case 1:
                                        x=max(x-operand,1);
                                        break;
                                }
#ifdef DEBUG
                                printf("%d %d %d\n",dir,x,y);
#endif
                        }
                }
                printf("%d %d\n",x,y);
        }

return(0);
}