let rec read () = 
  try
    let t = Scanf.scanf "%c,%c\n" (fun x y -> (x, y)) in t :: read ()
  with
    End_of_file -> []

let _ = 
  let lst = read () in
  Printf.printf "%c\n" (List.fold_left (fun c (x, y) -> 
                                       if c = x then y else if c = y then x else c) 'A' lst)