#include <stdio.h>
#include <string.h>

int main(){
  int x,y,d,dx,dy,mx,my;
  char str[16];

  while(1){
    scanf("%d %d",&mx,&my);
    if(mx == 0 && my == 0){
      break;
    }

    x = 1;
    y = 1;
    dx = 0;
    dy = 1;
    while(1){
      scanf("%s",str);
      if(!strcmp(str,"FORWARD")){
	scanf("%d",&d);
	x += d*dx;
	y += d*dy;
	if(x > mx){
	  x = mx;
	}
	if(y > my){
	  y = my;
	}
      }else if(!strcmp(str,"BACKWARD")){
	scanf("%d",&d);
	x -= d*dx;
	y -= d*dy;
	if(x < 1){
	  x = 1;
	}
	if(y < 1){
	  y = 1;
	}
      }else if(!strcmp(str,"RIGHT")){
	dx = dy;
	dy -= 1;
	if(dy == -2){
	  dy = 0;
	}
      }else if(!strcmp(str,"LEFT")){
	dy = dx;
	dx -= 1;
	if(dx == -2){
	  dx = 0;
	}
      }else if(!strcmp(str,"STOP")){
	break;
      }
    }

    printf("%d %d\n",x,y);
  }

  return 0;
}