s = set(range(10)) for _ in range(int(input())): *abcd, r = input().split() t = set(map(int, abcd)) if r == "YES": s &= t else: s -= t print(s.pop())