let charl_of_string s =
  let rec exp i l =
    if i < 0 then l else exp (i - 1) (s.[i] :: l) in
  exp (String.length s - 1) []

let tabulate n f =
  let rec loop acc cnt =
    if cnt = n then List.rev acc
    else loop (f () :: acc) (cnt + 1)
  in loop [] 0

(* let l = tabulate n (fun () -> Scanf.scanf "%d\n" (fun a -> a)) *)


(* let sl = Str.split (Str.regexp " ") @@ read_line () *)
(* let il = List.map int_of_string sl *)
(* let ar = Array.of_list il *)

(* let a, b = Scanf.scanf "%d %d\n" (fun a b -> a, b) *)
(* let () = Printf.printf "%d %f\n" 2 3.5 *)


let rec calc a b c = function
    'a' -> (
    match a with
      [] -> "A"
    | h :: a' -> calc a' b c h
    )
  | 'b' -> (
      match b with
        [] -> "B"
      | h :: b' -> calc a b' c h
    )
  | 'c' -> (
      match c with
        [] -> "C"
      | h :: c' -> calc a b c' h
    )
  | _ -> "error"


let () =
  let a = charl_of_string @@ read_line () in
  let b = charl_of_string @@ read_line () in
  let c = charl_of_string @@ read_line () in
  print_endline @@ calc a b c 'a'
