N = input() candidate = set(xrange(10)) for i in xrange(N): A, B, C, D, R = raw_input().split() numbers = map(int, (A, B, C, D)) if R == 'YES': for x in xrange(10): if not x in numbers: candidate.discard(x) else: for x in numbers: candidate.discard(x) print candidate.pop()