while gets
  n, m = $_.split.map(&:to_i)
  break if n == 0 && m == 0
  x = y = 1
  rotate = [0,1]
  loop do
    str = gets.split
    case str[0]
    when "FORWARD"
      d = str[1].to_i
      x += rotate[0]*d
      y += rotate[1]*d
      x = n if x > n; x = 1 if x < 1
      y = m if y > m; y = 1 if y < 1
    when "BACKWARD"
      d = str[1].to_i
      x -= rotate[0]*d
      y -= rotate[1]*d
      x = n if x > n; x = 1 if x < 1
      y = m if y > m; y = 1 if y < 1
    when "RIGHT"
      rotate = [rotate[1], -rotate[0]]
    when "LEFT"
      rotate = [-rotate[1], rotate[0]]
    when "STOP"
      puts "#{x} #{y}"
      break
    end
  end
end