N = int(input()) n = [0] * N for i in range(N): n[i] = input().split() ans = set((0, 1, 2, 3, 4, 5, 6, 7, 8, 9)) for i in range(len(n)): m = map(int, n[i][:4]) print(ans) if n[i][4] == 'NO': ans = set(ans) - set(m) if n[i][4] == 'YES': ans = set(ans) & set(m) print(list(ans)[0])