turn = int(input()) ans_set = set([int(i) for i in "0123456789"]) for t in range(turn): choice = list(map(str,input().split())) num_set = set([int(x) for x in choice[:4]]) if choice[4] == "YES": ans_set = ans_set & num_set elif choice[4] == "NO": ans_set = ans_set - num_set print(list(ans_set)[0])