#include <iostream>
#include <string>
using namespace std;
int main(){
    int move[][2] = { {0,1},{1,0},{0,-1},{-1,0} };
    
    while(true){
        int sx,sy;
        int x=1,y=1;
        int dir = 0;
        string command;
        cin >> sx >> sy;
        if(sx==0&&sy==0)return 0;
        while(true){
        cin >> command;
        if(command=="RIGHT"){
            dir = dir+1 >=4 ? 0:dir+1; 
        }else if(command=="LEFT"){
            dir = dir-1 < 0 ? 3:dir-1;
        }else if(command=="FORWARD"){
            int k;
            cin >> k;
            x+=move[dir][0]*k;
            y+=move[dir][1]*k;
            x = max(1,x);
            x = min(sx,x);
            y = max(1,y);
            y = min(sy,y);
        }else if(command=="BACKWARD"){
            int k;
            cin >> k;
            x-=move[dir][0]*k;
            y-=move[dir][1]*k;
            x = max(1,x);
            x = min(sx,x);
            y = max(1,y);
            y = min(sy,y);
        }else if(command=="STOP"){
            cout << x << " " << y << endl;
            break;
        }else{
            cout << "!!!!!!!!!!!!!!!" << endl;
            break;
        }
        }
    }
}