n = int(input()) m = set([str(i) for i in range(10)]) for i in range(n): a, b, c, d , r = input().split() if r == 'YES': m &= {a, b, c, d} else: m -= {a, b, c, d} print(*m)