#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int x, y;
int m, n;
int dirx, diry;

void process_command(char *buf);
void forward(int k);
void backward(int k);
void right(void);
void left(void);

int main()
{
    char buf[64];
    while(1){
        fgets(buf, sizeof(buf), stdin);
        sscanf(buf, "%d %d", &m, &n);
        if(m == 0) break;
        x = 1; y = 1;
        dirx = 0; diry = 1;
        while(strstr(fgets(buf, sizeof(buf), stdin), "STOP") == NULL){
            process_command(buf);
        }
        printf("%d %d\n", x, y);
    }
    return 0;
}

void process_command(char *buf)
{
    char *p;

    if((p = strstr(buf, "FORWARD")) != NULL)
        forward(atoi(p+strlen("FORWARD")));
    else if((p = strstr(buf, "BACKWARD")) != NULL)
        backward(atoi(p+strlen("BACKWARD")));
    else if(strstr(buf, "RIGHT") != NULL)
        right();
    else if(strstr(buf, "LEFT") != NULL)
        left();
}

void forward(int k)
{
    x += dirx * k;
    y += diry * k;
    if(x < 1) x = 1;
    else if(x > m) x = m;
    else if(y < 1) y = 1;
    else if(y > n) y = n;
}

void backward(int k)
{
    x -= dirx * k;
    y -= diry * k;
    if(x < 1) x = 1;
    else if(x > m) x = m;
    else if(y < 1) y = 1;
    else if(y > n) y = n;
}

void left()
{
    int tmp = diry;
    diry = dirx;
    dirx = -tmp;
}

void right()
{
    int tmp = dirx;
    dirx = diry;
    diry = -tmp;
}

