#include <stdio.h>
#include <string.h>

int main()
{
	int direct = 0; // ↑0、→1、↓2、←3
	int x = 1;
	int y = 1;
	char ch[100];
	int num;
	int map_x,map_y;
	scanf("%d %d",&map_x,&map_y); // マップの読み込み
	while(map_x != 0 || map_y != 0){
		scanf("%s", ch); // 命令の読み込み
		
		x = 1;
		y = 1;
		direct = 0;
		num = 0;

		while(strcmp(ch,"STOP")){
	
			// 各命令に対して
	
			if(strcmp(ch,"FORWARD") == 0){
				scanf("%d", &num);
				
				if(direct == 0){
					y += num;
				}if(y > map_y){
					y = map_y;
				}
				if(direct == 1){
					x += num;
				}if(x > map_x){
					x = map_x;
				}
				if(direct == 2){
					y -= num;
				}if(y < 1){
					y = 1;
				}
				if(direct == 3){
					x -= num;
				}if(x < 1){
					x = 1;
				}

				//printf("(%d,%d) direct %d\n",x,y,direct);
			}
			if(strcmp(ch,"BACKWARD") == 0){
				scanf("%d", &num);

				if(direct == 2){
					y += num;
				}if(y > map_y){
					y = map_y;
				}
				if(direct == 3){
					x += num;
				}if(x > map_x){
					x = map_x;
				}
				if(direct == 0){
					y -= num;
				}if(y < 1){
					y = 1;
				}
				if(direct == 1){
					x -= num;
				}if(x < 1){
					x = 1;
				}

				//printf("(%d,%d) direct %d\n",x,y,direct);
			}
			if(strcmp(ch,"RIGHT") == 0){
				direct++;
				if(direct > 3){
					direct = 0;
				}
				//printf("direct %d\n",direct);
			}
			if(strcmp(ch,"LEFT") == 0){
				direct--;
				if(direct < 0){
					direct = 3;
				}
				//printf("direct %d\n",direct);
			}
			scanf("%s", ch); // 命令の読み込み
		}
		printf("%d %d\n",x,y);
		scanf("%d %d",&map_x,&map_y); // マップの読み込み
	}
	return 0;
}