#include<iostream>
#include<vector>
using namespace std;
enum{BLANK,WALL};
enum{UP,RIGHT,DOWN,LEFT};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};

int main()
{
  int W,H;
  int x,y,d;
  string s;
  int k;
  while(cin>>W>>H,W|H){
    x=y=1;
    d=UP;
    while(cin>>s,s!="STOP"){
      if(s=="FORWARD"){
	cin>>k;
	x+=dx[d]*k;
	y+=dy[d]*k;
      }else if(s=="BACKWARD"){
	cin>>k;
	x-=dx[d]*k;
	y-=dy[d]*k;
      }else if(s=="RIGHT"){
	d++;
      }else if(s=="LEFT"){
	d--;
      }
      d=(d+4)%4;
      if(x>W)x=W;
      if(x<1)x=1;
      if(y>H)y=H;
      if(y<1)y=1;
    }
    cout<<x<<" "<<y<<endl;
  }
}