import random N,Q=map(int,input().split()) S=input() ABCD = set(["A","B","C","D"]) for _ in range(Q): query = list(input().split()) if not query[2] in ABCD: x = random.randint(1,10) print(x)