#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int dx[]{ 0,1,0,-1 }, dy[]{ 1,0,-1,0 };
int main() {
	int w, h;
	while (scanf("%d%d", &w, &h), w) {
		int x = 1, y = 1, idx = 0;
		while (1) {
			string s; cin >> s;
			if (s == "STOP")break;
			if (s == "RIGHT") {
				idx = (idx + 1) % 4; continue;
			}
			if (s == "LEFT") {
				idx = (idx + 3) % 4; continue;
			}
			int d; scanf("%d", &d);
			if (s == "FORWARD") {
				x+= dx[idx] * d, y+= dy[idx] * d;
				if (x <= 0)x = 1; if (y <= 0)y = 1;
				if (x > w)x = w; if (y > h)y = h;
			}
			else {
				x -= dx[idx] * d, y -= dy[idx] * d;
				if (x <= 0)x = 1; if (y <= 0)y = 1;
				if (x > w)x = w; if (y > h)y = h;
			}
		}
		printf("%d %d\n", x, y);
	}
}