box = set() for i in range(1,10): box.add(i) N = int(input()) for i in range(N): A,B,C,D,R = map(str,input().split()) if R=="NO": if int(A) in box: box.remove(int(A)) if int(B) in box: box.remove(int(B)) if int(C) in box: box.remove(int(C)) if int(D) in box: box.remove(int(D)) else: for n in range(1,10): if n !=int(A) and n !=int(B) and n !=int(C) and n !=int(D): if n in box: box.remove(n) print(*box)