#include <iostream>
using namespace std;

int main(){
  int x, y, direction, val;
  string str;
  int dx[] = {0,1,0,-1}, dy[] = {1,0,-1,0};
  while(cin >> x >> y && x != 0){
    cin >> str;
    int i = 1, j = 1; direction = 0;
    while(str.compare("STOP") != 0){
      if(str.compare("RIGHT") == 0)
	direction = (direction+1)%4;
      else if(str.compare("LEFT") == 0)
	direction = (direction+3)%4;
      else if(str.compare("FORWARD") == 0 || str.compare("BACKWARD") == 0){
	cin >> val;
	if(str.compare("BACKWARD") == 0){
	  i -= val*dx[direction];
	  j -= val*dy[direction];
	}
	else{
	  i += val*dx[direction];
	  j += val*dy[direction];
	}
	if(i<1) i=1;
	if(i>x) i=x;
	if(j<1) j=1;
	if(j>y) j=y;
      }
      cin >> str;
    }
    cout << i << " " << j << endl;
  }
  return 0;
}