// Aizu 1104: Where's Your Robot?
// 2017.9.12 bal4u@uu

#include <stdio.h>

#define N 0
#define E 1
#define S 2
#define W 3
int r90[4] = { E, S, W, N };
int l90[4] = { W, N, E, S };
int f[4][2] = { {0,1},{1,0},{0,-1},{-1,0} };
int b[4][2] = { {0,-1},{-1,0},{0,1},{1,0} };

int main()
{
	int w, h, r, c, d, r2, c2, k;
	char buf[20], cmd;

	while (scanf("%d%d", &w, &h) && w) {
		r = 1, c = 1, d = N;
		while (1) {
			scanf("%s", buf), cmd = *buf; 
			if      (cmd == 'S') break;
			else if (cmd == 'R') d = r90[d];
			else if (cmd == 'L') d = l90[d];
			else { scanf("%d", &k);
				if (cmd == 'F') r2 = r + k*f[d][1], c2 = c + k*f[d][0];
				else			r2 = r + k*b[d][1], c2 = c + k*b[d][0];
				if (r2 < 1) r2 = 1; if (r2 > h) r2 = h;
				if (c2 < 1) c2 = 1; if (c2 > w) c2 = w;
				r = r2, c = c2;
			}
		}
		printf("%d %d\n", c, r);
	}
	return 0;
}