n = int(input()) S = set(range(10)) for i in range(n): a, b, c, d, s = input().split() T = set(map(int, [a, b, c, d])) if s == "NO": S = S - T else: S = S & T print(*S)