while true
    w, h = gets.chomp.split.map(&:to_i)
    break if [w, h] == [0, 0]
    x, y, d = 1, 1, 0
    while true
        command, l = gets.chomp.split
        adds = [[0, 1], [1, 0], [0, -1], [-1, 0]]
        case command
        when "FORWARD"
            x, y = x + adds[d][0] * l.to_i, y + adds[d][1] * l.to_i
        when "BACKWARD"
            x, y = x - adds[d][0] * l.to_i, y - adds[d][1] * l.to_i
        when "RIGHT"
            d = (d + 1) % 4
        when "LEFT"
            d = (d - 1) % 4
        when "STOP"
            break
        end
        x = 1 if x < 1
        x = w if x > w
        y = 1 if y < 1
        y = h if y > h
    end
    puts "#{x} #{y}"
end
