N = int(input()) numbers = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'} for i in range(N): A, B, C, D, R = input().split() if R == 'YES': numbers = numbers & {A, B, C, D} else: numbers = numbers - {A, B, C, D} result = list(numbers) print(result[0])