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

struct coordinate{
  int x;
  int y;
};

int n,m,dir;
struct coordinate walk(int d,int num,int n,int m,struct coordinate p);

int main(void){
  int i,j,go;
  char order[16];
  struct coordinate point;
  while(scanf("%d %d",&m,&n)&&(n!=0||m!=0)){
    point.x=point.y=1;
    dir=0;
    while(scanf("%s",order)&&order[0]!='S'){
      scanf("%d",&go);
      if(order[0]=='B'){
	dir=(dir+2)%4;
	point=walk(dir,go,n,m,point);
	dir=(dir+2)%4;
      }else if(order[0]=='F') point=walk(dir,go,n,m,point);
      else if(order[0]=='R') dir=(dir+1)%4;
      else if(order[0]=='L') dir=(dir+3)%4;
    }
    printf("%d %d\n",point.x,point.y);
  }
  return 0;
}

struct coordinate walk(int d,int num,int n,int m,struct coordinate p){
  switch(d){
  case 0:
    p.y+=num;
    break;
  case 1:
    p.x+=num;
    break;
  case 2:
    p.y-=num;
    break;
  case 3:
    p.x-=num;
    break;
  }
  if(p.x>m) p.x=m;
  else if(p.x<1) p.x=1;
  if(p.y>n) p.y=n;
  else if(p.y<1) p.y=1;
  return p;
}