N, *L = open(0).read().split() S = set(map(str, range(10))) for a, b, c, d, r in zip(*[iter(L)] * 5): if r == "YES": S &= {a, b, c, d} else: S -= {a, b, c, d} print(S.pop())