#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int x, y;
string s;

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

int main(){
	while (cin >> x >> y&&x + y){
		int posx = 1, posy = 1, muki = 0;
		while (cin >> s){
			int num;
			if (s == "STOP")break;
			if (s == "FORWARD"){
				cin >> num;
				REP(i, num){
					int ny = posy + dy[muki], nx = posx + dx[muki];
					if (ny >= 1 && ny <= y&&nx >= 1 && nx <= x){
						posy = ny, posx = nx;
					}
				}
			}
			else if (s == "BACKWARD"){
				cin >> num;
				REP(i, num){
					int ny = posy - dy[muki], nx = posx - dx[muki];
					if (ny >= 1 && ny <= y&&nx >= 1 && nx <= x){
						posy = ny, posx = nx;
					}
				}
			}
			else if (s == "RIGHT"){
				muki++;
				if (muki > 3)muki = 0;
			}
			else if (s == "LEFT"){
				muki--;
				if (muki < 0)muki = 3;
			}
		}
		cout << posx << " " << posy << endl;
	}
}