# -*- coding: utf-8 -*- def main(): N = int(input()) nums = list(range(10)) for i in range(N): t = list(input().split()) if t[4] == "YES": nums = list(set(nums) & set(map(int, t[:4]))) elif t[4] == "NO": nums = list(set(nums) - set(map(int, t[:4]))) print(str(nums[0]) + "\n") if __name__ == '__main__': main()