let () =
  let sa = read_line () in
  let sb = read_line () in
  let sc = read_line () in
  let la = String.length sa in
  let lb = String.length sb in
  let lc = String.length sc in
  let rec iter ia ib ic t =
    match t with
      0 -> if ia = la then "A" else begin
               match sa.[ia] with
                 'a' -> iter (ia+1) ib ic 0
               | 'b' -> iter (ia+1) ib ic 1
               | _ -> iter (ia+1) ib ic 2
             end
    | 1 -> if ib = lb then "B" else begin
               match sb.[ib] with
                 'a' -> iter ia (ib+1) ic 0
               | 'b' -> iter ia (ib+1) ic 1
               | _ -> iter ia (ib+1) ic 2
             end
    | _ -> if ic = lc then "C" else begin
               match sc.[ic] with
                 'a' -> iter ia ib (ic+1) 0
               | 'b' -> iter ia ib (ic+1) 1
               | _ -> iter ia ib (ic+1) 2
             end
  in
  iter 0 0 0 0 |> print_endline
