#include<stdio.h>
#include<string.h>
int main(void)
{
	int degy[4]={1,0,-1,0},degx[4]={0,1,0,-1};
	int i,j,m,n,x,y,deg;
	char s[5][9]={"FORWARD","BACKWARD","RIGHT","LEFT","STOP"};
	int suu;
	char buf[20];
	
	while(1)	{
		scanf("%d %d",&m,&n);
		if(m==0 && n==0)	break;
		x=1;	y=1;	deg=0;
		while(1)	{
			scanf("%s",buf);
			if(strcmp(buf,s[0])==0)	{
				scanf("%d",&suu);
				x=x+degx[deg]*suu;
				if(x>m)	x=m;
				if(x<1)	x=1;
				y=y+degy[deg]*suu;
				if(y>n)	y=n;
				if(y<1)	y=1;
			}
			else if(strcmp(buf,s[1])==0)	{
				scanf("%d",&suu);
				x=x-degx[deg]*suu;
				if(x>m)	x=m;
				if(x<1)	x=1;
				y=y-degy[deg]*suu;
				if(y>n)	y=n;
				if(y<1)	y=1;
			}
			else if(strcmp(buf,s[2])==0)	{
				deg=(deg+1)%4;
			}
			else if(strcmp(buf,s[3])==0)	{
				deg=(deg+3)%4;
			}			
			else if(strcmp(buf,s[4])==0) {
				break;
			}
		}
		printf("%d %d\n",x,y);
	}
	return 0;
}
