cups = [1, 0, 0]
while line = gets
    case line.chomp!
    when "A,B", "B,A"
        cups[0], cups[1] = cups[1], cups[0]
    when "A,C", "C,A"
        cups[0], cups[2] = cups[2], cups[0]
    when "B,C", "C,B"
        cups[1], cups[2] = cups[2], cups[1]
    end
end
ABC = "ABC"
puts "ABC"[cups.index{|cup| cup == 1}]