# -*- coding: utf-8 -*-



SA,SB,SC = [input().strip() for _ in range(3)]



ia,ib,ic=0,0,0

turn="a"



while True:

  if turn == "a":

    if SA == "":

      print("A")

      break

    

    turn = SA[0]

    SA = SA[1:]



  if turn == "b":

    if SB == "":

      print("B")

      break

    

    turn = SB[0]

    SB = SB[1:]



  if turn == "c":

    if SC == "":

      print("C")

      break

    

    turn = SC[0]

    SC = SC[1:]

# -*- coding: utf-8 -*-



SA,SB,SC = [input().strip() for _ in range(3)]



S_dic={}

S_dic['a']=SA

S_dic['b']=SB

S_dic['c']=SC



turn="a"

while True:

    if S_dic[turn] == "":

      print((turn.upper()))

      break

    

    next_turn = S_dic[turn][0]

    S_dic[turn] = S_dic[turn][1:]

    turn = next_turn

# -*- coding: utf-8 -*-
SA, SB, SC = [input().strip() for _ in range(3)]
ia, ib, ic = 0, 0, 0
turn = "a"
while True:
    if turn == "a":
        if SA == "":
            print("A")
            break
        turn = SA[0]
        SA = SA[1:]
    if turn == "b":
        if SB == "":
            print("B")
            break
        turn = SB[0]
        SB = SB[1:]
    if turn == "c":
        if SC == "":
            print("C")
            break
        turn = SC[0]
        SC = SC[1:]

# -*- coding: utf-8 -*-
SA, SB, SC = [input().strip() for _ in range(3)]
S_dic = {}
S_dic["a"] = SA
S_dic["b"] = SB
S_dic["c"] = SC
turn = "a"
while True:
    if S_dic[turn] == "":
        print((turn.upper()))
        break
    next_turn = S_dic[turn][0]
    S_dic[turn] = S_dic[turn][1:]
    turn = next_turn

-ia, ib, ic = 0, 0, 0 +S_dic = {} +S_dic["a"] = SA +S_dic["b"] = SB +S_dic["c"] = SC -    if turn == "a": -        if SA == "": -            print("A") -            break -        turn = SA[0] -        SA = SA[1:] -    if turn == "b": -        if SB == "": -            print("B") -            break -        turn = SB[0] -        SB = SB[1:] -    if turn == "c": -        if SC == "": -            print("C") -            break -        turn = SC[0] -        SC = SC[1:] +    if S_dic[turn] == "": +        print((turn.upper())) +        break +    next_turn = S_dic[turn][0] +    S_dic[turn] = S_dic[turn][1:] +    turn = next_turn