N = int(input()) s = {str(i) for i in range(10)} for _ in range(N): a, b, c, d, r = input().split() if r == 'NO': s -= {a, b, c, d} else: s &= {a, b, c, d} print(*s)