
#include<stdio.h>

int main(void){
  unsigned int n,m,x,y;
  char Order[16];
  int ret,Dir=0;//ROBO's DIRECTION
  
  while(1){
    Dir=0;//heading to North
    Order[0]='0';
    x=1;
    y=1;

    //printf("Please type Field Size; x(to East),y(to North) in order\n");
    scanf("%u %u%*c",&m,&n);
    ret=feof(stdin);
    if(ret) return 0;

    for(;(strcmp(Order,"STOP"));){
      scanf("%15s%*c",Order);
      if(!strcmp(Order,"LEFT")){
	Dir++;
	Dir %= 4;
      }else if(!strcmp(Order,"RIGHT")){
	Dir += 3;
	Dir %= 4;
      }else if(!strcmp(Order,"FORWARD")){
	if(Dir==0) if( y<n ) y++;
	if(Dir==1) if( x>1 ) x--;
	if(Dir==2) if( y>1 ) y--;
	if(Dir==3) if( x<m ) x++;
      }else if(!strcmp(Order,"BACKWARD")){
	if(Dir==2) if( y<n ) y++;
	if(Dir==3) if( x>1 ) x--;
	if(Dir==0) if( y>1 ) y--;
	if(Dir==1) if( x<m ) x++;
      }else if(!strcmp(Order,"STOP")){
	  printf("%u %u\n",x,y);
      }
    }
    // printf("Type 'Ctr + d' if you want exil; or else type any other key...\n");
  }
  return 0;
}