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

int dir[4][2]={{-1,0},{0,1},{1,0},{0,-1}};
int w,h;

void goStraight(int *x,int *y,int d,int dist){
  *x += dir[d][1]*dist;
  *y += dir[d][0]*dist;

  if(*x<0) *x=0;
  if(*x>=w) *x=w-1;
  if(*y<0) *y=0;
  if(*y>=h) *y=h-1;
}

int changeDir(int d,int LR){
  if(LR==0){
    d--;
    if(d<0) d=3;
  }
  else{
    d++;
    if(d>3) d=0;
  }
  return d;
}

int main(void){
  int x,y,d,dist;
  char op[9];

  while(1){
    scanf("%d%d",&w,&h);
    if(!w && !h) break;

    x = y = 0;
    d = 2;
    while(1){
      scanf("%s",op);
      if(!strcmp(op,"STOP")) break;

      if(!strcmp(op,"FORWARD")){
	scanf("%d",&dist);
	goStraight(&x,&y,d,dist);
      }
      else if(!strcmp(op,"BACKWARD")){
	scanf("%d",&dist);
	goStraight(&x,&y,d,-dist);
      }
      else if(!strcmp(op,"RIGHT")){
	d = changeDir(d,0);
      }
      else{
	d = changeDir(d,1);
      }
    }
    printf("%d %d\n",x+1,y+1);
  }

  return 0;
}