from collections import defaultdict m = defaultdict(set) m["YES"] = set("0123456789") for _ in range(int(input())): a, b, c, d, r = input().split() if r == "YES": m["YES"] &= {a, b, c, d} if r == "NO": m["NO"] |= {a, b, c, d} print((m["YES"] - m["NO"]).pop())