let head str = str.[0]

let tail str =
    if String.length str = 1 then
        ""
    else
        String.sub str 1 (String.length str - 1)

let rec play a b c turn =
    match turn with
    | 'a' when a <> "" -> 
        play (tail a) b c (head a)
    | 'b' when b <> "" ->
        play a (tail b) c (head b)
    | 'c' when c <> "" ->
        play a b (tail c) (head c)
    | x ->
        x

let () =
    let a = read_line () in
    let b = read_line () in
    let c = read_line () in
    play a b c 'a'
    |> Char.uppercase
    |> print_char;
    print_newline ()
