#encoding:utf-8 No.0047 2014.10.6
cups = {"A"=>"ball","B"=>nil,"C"=>nil}
change = []

while gets
  change.push $_.chomp.split(/,/)
end

change.length.times do |i|
  cups[change[i][0]],cups[change[i][1]] = cups[change[i][1]],cups[change[i][0]]
end

cups.each{|key,value|
  puts key if value == "ball"
}