#include <iostream>
#include <string>
using namespace std;
int main()
{
	int w, h, k, x, y, a;
	struct {int x, y;} d[4] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
	string s;
	while (cin >> w >> h, w && h)
	{
		x = y = 1, a = 0;
		while (cin >> s, s != "STOP")
		{
			if (s == "FORWARD")
			{
				cin >> k;
				for (; k > 0; k--)
					if (0 < x+d[a].x && x+d[a].x <= w && 0 < y+d[a].y && y+d[a].y <= h)
						x += d[a].x, y += d[a].y;
					else
						break;
			}
			else if (s == "BACKWARD")
			{
				cin >> k;
				for (; k > 0; k--)
					if (0 < x-d[a].x && x-d[a].x <= w && 0 < y-d[a].y && y-d[a].y <= h)
						x -= d[a].x, y -= d[a].y;
					else
						break;
			}
			else if (s == "RIGHT")
				if (a+1 < 4)
					a++;
				else
					a = 0;
			else if (s == "LEFT")
				if (0 <= a-1)
					a--;
				else
					a = 3;
		}
		cout << x << " " << y << endl;
	}
}