#include <iostream>
using namespace std;

// right -> turn 90 deg. right;
// left  -> turn 90 deg. left;

int map[101][101];


int main(){
    int m, n;
    while (1){
	int x = 1, y = 1, dir = 0;
	cin >> m >> n;
	if (m == 0 && n == 0) break;
	string command;
	while (1){
	    cin >> command;
	    if (command == "STOP") break;

	    if (command == "RIGHT"){
		dir++;
		if (dir == 4) dir = 0;
	    }
	    else if (command == "LEFT"){
		dir--;
		if (dir == -1) dir = 3;
	    }

	    else {
		int w;
		cin >> w;
		if (command == "FORWARD"){
		    switch (dir){
		    case 0: y += w; break;
		    case 1: x += w; break;
		    case 2: y -= w; break;
		    case 3: x -= w; break;
		    }
		    if (x > m) x = m;
		    if (y > n) y = n;
		    if (x < 1) x = 1;
		    if (y < 1) y = 1;
		}
		else if (command == "BACKWARD"){
		    switch (dir){
		    case 0: y -= w; break;
		    case 1: x -= w; break;
		    case 2: y += w; break;
		    case 3: x += w; break;
		    }
		    if (x > m) x = m;
		    if (y > n) y = n;
		    if (x < 1) x = 1;
		    if (y < 1) y = 1;
		}
//		cout << x << " " << y << " " << dir << " " << w << endl;;
	    }

	}
	
	cout << x << " " << y << endl;
    }
}