#include <stdio.h>
int H, W, e; char buf[8];
int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
int main() {
	while (scanf("%d%d", &W, &H), H) {
		int x = 1, y = 1, d = 0;
		while (scanf("%s", buf), buf[0] != 'S') {
			scanf("%d", &e);
			switch (buf[0]) {
			case 'F': x += dx[d] * e, y += dy[d] * e; break;
			case 'B': x -= dx[d] * e, y -= dy[d] * e; break;
			case 'R': d = (d + 1) % 4; break;
			case 'L': d = (d + 3) % 4; break;
			}
			if (x < 1) x = 1; if (x > W) x = W;
			if (y < 1) y = 1; if (y > H) y = H;
		}
		printf("%d %d\n", x, y);
	}
	return 0;
}