ac::String->String->String->Char->Char
ac a b c w = case w of 'a' -> if null a then "A" else ac (tail a) b c (head a)
                       'b' -> if null b then "B" else ac a (tail b) c (head b)
                       'c' -> if null c then "C" else ac a b (tail c) (head c)
main=do
 [a,b,c]<-sequence[getLine,getLine,getLine]
 putStrLn$ac a b c 'a' 