open System
open System.Collections
open System.Collections.Generic
open System.IO
open System.Linq

let Str() = Console.ReadLine()
let Int() = Str() |> int
let Char() = [for c in Str() -> c]

let rec game p1 p2 p3 cur=
    match cur with
    | 'a' -> if p1<>[] then game p1.Tail p2 p3 p1.Head
             else           'A'
    | 'b' -> if p2<>[] then game p1 p2.Tail p3 p2.Head
             else           'B'
    |  _  -> if p3<>[] then game p1 p2 p3.Tail p3.Head
             else           'C'

[<EntryPoint>]
let main _ = 
    let a = Char()
    let b = Char()
    let c = Char()

    let ans = game a b c 'a'

    printfn "%c" ans

    0
    

