#include<stdio.h>

int main(){
	int x,y;
	int ansx,ansy,ansv;
	char str[20];
	int vector[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
	while(1){
		ansx=0,ansy=0,ansv=0;
		scanf("%d %d",&x,&y);
		if(x==0&&y==0){
			break;
		}
		while(1){
			char cmd[20];
			int b,c=0;
			int value=0;
			
			while(b=getchar()){
				if(b=='\n'){
					break;
				}
				str[c]=(char)b;
				c++;
			}
			str[c]='\0';
			
			if(strcmp("STOP",str)==0){
				break;
			}
			else if(strcmp("RIGHT",str)==0){
				ansv=(ansv+1)%4;
			}
			else if(strcmp("LEFT",str)==0){
				ansv=(ansv+3)%4;
			}
			else{
				sscanf(str,"%s %d",cmd,&value);
				if(strcmp("FORWARD",cmd)==0){
					printf("F v=%d\n",value);
					ansx+=vector[ansv][0]*value;
					ansy+=vector[ansv][1]*value;
				}
				else if(strcmp("BACKWARD",cmd)==0){
					printf("B v=%d\n",value);
					ansx-=vector[ansv][0]*value;
					ansy-=vector[ansv][1]*value;
				}
			}
		}
		printf("%d %d",ansx,ansy);
		
	}
	return 0;
}