let list_of_str s = let rec f i = if i >= String.length s then [] else s.[i] :: f (i+1) in f 0
let rec solve t xs ys zs =
  if t = 'a'      then match xs with [] -> "A" | (x::xs') -> solve x xs' ys zs
  else if t = 'b' then match ys with [] -> "B" | (y::ys') -> solve y xs ys' zs
  else                 match zs with [] -> "C" | (z::zs') -> solve z xs ys zs'
let () = Scanf.scanf "%s %s %s" (fun a b c ->
  solve 'a' (list_of_str a) (list_of_str b) (list_of_str c)) |> print_endline
