#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <map>
#include <vector>
#include <string>
#include <vector>
#include <cassert>
#include <cmath>
#include <cctype>
#include <queue>
#include <algorithm>
#include <memory>
#include <memory.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P,P> P2;
const int INF = 1 << 30;
const double EPS = 1E-9;

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

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

int main(){
	int w, h;
	while(cin >> w >> h && (w || h)){
		string ord;
		int y = 1;
		int x = 1;
		int d = 0;
		int m = 0;
		bool f = false;
		while(cin >> ord && ord != "STOP"){
			if(ord == "RIGHT"){
				d = (d+1) % 4;
			}else if(ord == "LEFT"){
				d = (d+3)%4;
			}else if(ord == "BACKWARD"){
				cin >> m;
				y -= m * dy[d];
				if(y > h){
					f = true;
					y = h;
				}
				if(y < 1){
					y = 1;
					f = true;
				}
				x -= m * dx[d];
				if(x > w){
					f = true;
					x = w;
				}
				if(x < 1){
					f = true;
					x = 1;
				}
			}else{
				cin >> m;
				y += m * dy[d];
				if(y > h){
					f = true;
					y = h;
				}
				if(y < 1){
					f = true;
					y = 1;
				}
				x += m * dx[d];
				if(x > w){
					f = true;
					x = w;
				}
				if(x < 1){
					f = true;
					x = 1;
				}
			}
		}
		cout << x << " " << y << endl;
	}
	return 0;
}
		