N = int(input()) f = set([1,2,3,4,5,6,7,8,9,0]) n = set() y = set() for i in range(N): K = input().split() A = set(map(int, K[0:4])) R = K[4] if R == "YES": if len(y) == 0: y = A else: y = (y & A) - n else: n.update(A) if len(y - n) == 1: print(str(y - n)[1]) else: print(str(f - n)[1])