#include<iostream>
using namespace std;
int main(){
	int w,h,dx[]={0,1,0,-1},dy[]={1,0,-1,0};
	while(cin>>w>>h,w||h){
		string s;
		int x=1,y=1,n;
		int dir=0;
		while(cin>>s,s!="STOP"){
			if(s=="FORWARD"){
				cin>>n;
				for(int i=0;i<n;i++){
					int nx=dx[dir]+x,ny=dy[dir]+y;
					if(nx>=1&&nx<=w&&ny>=1&&ny<=h){
						x=nx;y=ny;
					}else
						break;
				}
			}else if(s=="RIGHT"){
				dir++;
				dir%=4;
			}else if(s=="LEFT"){
				dir+=3;
				dir%=4;
			}else{
				cin>>n;
				for(int i=0;i<n;i++){
					int nx=dx[(dir+2)%4]+x,ny=dy[(dir+2)%4]+y;
					if(nx>=1&&nx<=w&&ny>=1&&ny<=h){
						x=nx;y=ny;
					}else
						break;
				}
				
			}
		}
		cout<<x<<' '<<y<<endl;
	}
	return 0;
}