uni = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'} for _ in range(int(input())): line = input().split() uni = getattr(uni, ['difference', 'intersection'][line.pop() == 'YES'])(set(line)) print(uni.pop())