N=int(input()) O=set(range(10)) for i in range(N): A=input().split() B=set(map(int,A[:4])) if A[4]=='NO':O-=B else:O&=B print(O.pop())