def winput(): inp = input().split() if len(inp) == 1: return int(inp[0]) return inp ist = [True]*10 n = winput() for i in range(n): a, b, c, d, r = winput() a, b, c, d = list(map(int, [a, b, c, d])) if r == "NO": for i in [a, b, c, d]: ist[i] = False else: for i in range(10): if not (i in [a, b, c, d]): ist[i] = False for i, b in enumerate(ist): if b: print(i) break