s=set(str(i) for i in range(10)) for _ in range(int(input())): a,b,c,d,e=input().split() if e=="YES": s&={a,b,c,d} else: s-={a,b,c,d} print(s.pop())