N = int(input()) S = set(range(10)) for _ in range(N): *X, R = input().split() X = set(map(int,X)) if R == 'NO': S -= X else: S &= X print(S)