let get_line () =
    read_line ()
    |> Stream.of_string

let rec play a b c turn =
    let table = function
        | 'a' -> a
        | 'b' -> b
        | 'c' -> c
    in
    let line = table turn in
    match Stream.peek line with
    | Some x -> 
        Stream.junk line;
        play a b c x
    | None ->
        Char.uppercase turn

let () =
    let a = get_line () in
    let b = get_line () in
    let c = get_line () in
    play a b c 'a'
    |> print_char
    |> print_newline
