N,M = map(int,input().split()) L = [input() for i in range(M)] D = {} D_debt = {} for i in range(N) : D[i+1] = 0 D_debt[i+1] = 0 state = "" debt = 0 reverse = 0 turn = 1 def next() : global turn if reverse == 1 : turn -= 1 else : turn += 1 if turn == 0 : turn = N elif turn == N+1 : turn = 1 return turn def judge(L) : if len(L) == 0 : print(turn, D[turn]-D_debt[turn]) while True : if state == "skip" : state = "" turn = next() elif state == "drawtwo" : if L[0] == "drawtwo" : card = L.pop(0) D[turn] += 1 judge(L) debt += 2 else : D_debt[turn] += debt debt = 0 state = "" turn = next() elif state == "drawfour" : if L[0] == "drawfour" : card = L.pop(0) D[turn] += 1 judge(L) debt += 4 else : D_debt[turn] += debt debt = 0 state = "" turn = next() else : card = L.pop(0) D[turn] += 1 judge(L) if card in ("skip","drawtwo","drawfour") : state = card if card == "drawtwo" : debt = 2 elif card == "drawfour" : debt = 4 elif card == "reverse" : reverse = (reverse + 1) % 2 turn = next() if len(L) == 0 : break