Editorial
Fix any total order of the characters. For example, let the character that appears earlier in the input always win.
If character wins against character , then appears earlier than in the input. If character wins against character , then appears earlier than . Therefore also appears earlier than , so wins against .
Thus, printing the earlier character in input order for every query always satisfies the condition.
Store the input index of each name, and for each query print the name with the smaller index. If the two names are equal, print that name.
The time complexity is , where is the sum of the lengths of the given character names.