# yukicoder No.24 数当てゲーム N = int(input()) exist = {str(i) for i in range(10)} for _ in range(N): A, B, C, D, R = input().split() if R == "YES": exist = exist & {A, B, C, D} else: exist = exist - {A, B, C, D} print(*exist)