### constant

DXYS = [[0, 1], [1, 0], [0, -1], [-1, 0]]

### main

loop do
  m, n = gets.split.map(&:to_i)
  break if (m | n) == 0

  x = y = 1
  d = 0
  #p [x, y, d]

  loop do
    cmds = gets.strip.split
    #p cmds

    case cmds[0]
    when 'FORWARD'
      k = cmds[1].to_i
      dx, dy = DXYS[d]
      k.times do
        x0 = x + dx
        y0 = y + dy
        break if x0 < 1 || x0 > m || y0 < 1 || y0 > n
        x = x0
        y = y0
      end
    when 'BACKWARD'
      k = cmds[1].to_i
      dx, dy = DXYS[d]
      k.times do
        x0 = x - dx
        y0 = y - dy
        break if x0 < 1 || x0 > m || y0 < 1 || y0 > n
        x = x0
        y = y0
      end
    when 'LEFT'
      d = (d + 3) % 4
    when 'RIGHT'
      d = (d + 1) % 4
    when 'STOP'
      break
    end
    #p [x, y, d]
  end

  puts [x, y].join(' ')
end