#include <bits/stdc++.h>
using namespace std;

using db = double;
using ll = long long;
using vi = vector <int>;
#define op operator
#define pb push_back

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int main() {
	cout << fixed << setprecision(9);
	ios :: sync_with_stdio(0);

	for(int n, m; cin >> n >> m && n && m; ) {
		int x = 1, y = 1, d = 1;
		for(string s; cin >> s && s != "STOP"; ) {
			if(s == "LEFT") d = (d + 1) % 4;
			if(s == "RIGHT") d = (d + 3) % 4;
			if(s == "FORWARD" || s == "BACKWARD") {
				int sgn = (s == "FORWARD" ? 1 : -1);
				int t; cin >> t;
				while(t --) {
					int nx = x + dx[d] * sgn;
					int ny = y + dy[d] * sgn;
					if(nx >= 1 && nx <= n && ny >= 1 && ny <= m) {
						x = nx; y = ny;
					}
				}
			}
		}
		cout << x << ' ' << y << '\n';
	}

	return 0;
}