let a, b, c = Scanf.scanf " %s %s %s" @@ fun a b c -> a, b, c
let is = Array.make 3 0
let g s i x = if is.(i) >= String.length s then (Printf.printf "%c\n" x; exit 0) else (is.(i) <- is.(i) + 1; is.(i) - 1)
let rec f x = match x with 'a' -> f a.[g a 0 'A'] | 'b' -> f b.[g b 1 'B'] | _ -> f c.[g c 2 'C']
let _ = f 'a'