let abc = Array.init 3 @@ fun _ -> read_line ()
let is = Array.make 3 0
let g s i = if is.(i) >= String.length s then (Printf.printf "%c\n" @@ Char.chr @@ Char.code 'A' + i; exit 0) else (is.(i) <- is.(i) + 1; is.(i) - 1)
let rec f i = f @@ Char.code abc.(i).[g abc.(i) i] - Char.code 'a'
let _ = f 0