cup = [1,0,0]
while act  = gets
  case act.chomp
  when "A,B" then cup[0], cup[1] = cup[1], cup[0]
  when "A,C" then cup[0], cup[2] = cup[2], cup[0]
  when "B,C" then cup[1], cup[2] = cup[2], cup[1]
  end
  p cup
end

case cup.index(1)
  when 0 then puts "A"
  when 1 then puts "B"
  when 2 then puts "C"
end