n, m = read_line.split.map &.to_i index, reverse = 0, 1 draw_kind, draw_count = -1, 0 count = [0] * n m.times do |time| l = read_line if draw_kind != -1 && [l, draw_kind] != ["drawtwo", 2] && [l, draw_kind] != ["drawfour", 4] count[index] -= draw_count draw_kind, draw_count = -1, 0 index = (index + reverse) % n end # p! [l, index + 1, reverse, draw_kind, draw_count, count] reverse = 0 if time == m - 1 case l when "number" count[index] += 1 index = (index + reverse) % n when "drawtwo" if draw_kind == 2 count[index] += 1 draw_count += 2 else count[index] += 1 draw_kind, draw_count = 2, 2 end index = (index + reverse) % n when "drawfour" if draw_kind == 4 count[index] += 1 draw_count += 4 else count[index] += 1 draw_kind, draw_count = 4, 4 end index = (index + reverse) % n when "skip" count[index] += 1 index = (index + reverse * 2) % n when "reverse" count[index] += 1 reverse *= -1 index = (index + reverse) % n end end puts [index + 1, count[index]].join(' ')