#include<iostream>
#include<string>
using namespace std;
int main(){
	int w,h;
	int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
	while(true){
	cin>>w>>h;
	if(w==0&&h==0)break;
	string a;
	int s=0;
	int x=1,y=1,z;
	while(true){
		cin>>a;
		if(a=="STOP")break;
		if(a=="RIGHT")s=(s+1)%4;
		if(a=="LEFT")s=(s+3)%4;
		if(a=="FORWARD"){
			cin>>z;
			x+=dx[s]*z,y+=dy[s]*z;
			if(x<1)x=1;if(x>w)x=w;
			if(y<1)y=1;if(y>h)y=h;
		}
		if(a=="BACKWARD"){
			cin>>z;
			x-=dx[s]*z,y-=dy[s]*z;
			if(x<1)x=1;if(x>w)x=w;
			if(y<1)y=1;if(y>h)y=h;
		}
	}
	cout<<x<<" "<<y<<endl;
	}
	return 0;
}