from collections import deque

hands = {'a': list(eval(input())),

         'b': list(eval(input())),

         'c': list(eval(input())),

        }

next_hand = hands['a'][0]

while True:

  try:

    next_hand = hands[next_hand].pop(0)

  except:

    break

print((next_hand.upper()))
hands = {char:list(eval(input())) for char in 'abc'} 

next_hand = 'a'

while hands[next_hand]:

  next_hand = hands[next_hand].pop(0)



print((next_hand.upper()))
from collections import deque

hands = {
    "a": list(eval(input())),
    "b": list(eval(input())),
    "c": list(eval(input())),
}
next_hand = hands["a"][0]
while True:
    try:
        next_hand = hands[next_hand].pop(0)
    except:
        break
print((next_hand.upper()))

hands = {char: list(eval(input())) for char in "abc"}
next_hand = "a"
while hands[next_hand]:
    next_hand = hands[next_hand].pop(0)
print((next_hand.upper()))

-from collections import deque - -hands = { -    "a": list(eval(input())), -    "b": list(eval(input())), -    "c": list(eval(input())), -} -next_hand = hands["a"][0] -while True: -    try: -        next_hand = hands[next_hand].pop(0) -    except: -        break +hands = {char: list(eval(input())) for char in "abc"} +next_hand = "a" +while hands[next_hand]: +    next_hand = hands[next_hand].pop(0)