import scala.io.Source.stdin

object Main extends App {
  println {
    stdin.getLines.filter(_!="").map(_.split(",")).foldLeft("A"){ (x,y) =>
      if(x==y(0)) y(1) else if(x==y(1)) y(0) else x
    }
  }
}