#include <stdio.h>

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  for ( ; ; )
  {
    int x = 1, y = 1;
    int vx = 0, vy = 1;
    int m, n;

    scanf ( " %d %d", &m, &n );
    if ( !( m | n ) ) break ;

    for ( ; ; )
    {
      char cmd[ 16 ];
      int d;

      scanf ( " %s", cmd );
      if ( *cmd == 'S' )  break ;

      switch ( *cmd )
      {
        case 'F':
        case 'B':
          scanf ( "%d", &d );
          x += ( *cmd == 'F' ? 1 : -1 ) * vx * d;
          if ( x < 1 ) x = 1; else if ( x > m ) x = m;
          y += ( *cmd == 'F' ? 1 : -1 ) * vy * d;
          if ( y < 1 ) y = 1; else if ( y > n ) y = n;
          break ;
        case 'L':
          d  = vx;
          vx = -vy;
          vy = d;
          break ;
        case 'R':
          d  = vx;
          vx = vy;
          vy = -d;
          break ;
      }
    }

    printf ( "%d %d\n", x, y );
  }

  return ( 0 );
}