from collections import deque



sa = deque(list(eval(input())))

sb = deque(list(eval(input())))

sc = deque(list(eval(input())))

turn = 1



for i in range(10**10):

  

  if turn == 1:

    if len(sa) == 0:

      print('A')

      exit()

    tmp =sa.popleft()

      

    if tmp == 'b':

      turn = 2

    elif tmp == 'c':

      turn = 3

      

  if turn == 2:

    if len(sb) == 0:

      print('B')

      exit()

    tmp =sb.popleft()

      

    if tmp == 'a':

      turn = 1

    elif tmp == 'c':

      turn = 3

      

  if turn == 3:

    if len(sc) == 0:

      print('C')

      exit()

    tmp =sc.popleft()

      

    if tmp == 'a':

      turn = 1

    elif tmp == 'b':

      turn = 2
sa = [i for i in eval(input())]

sb = [i for i in eval(input())]

sc = [i for i in eval(input())]

d = {"a":sa, "b":sb, "c":sc}#おのおのの手札をdictで表す

turn = "a"

while(True):#breakするまで続く

    if len(d[turn]) == 0:

        break

    turn = d[turn].pop(0)#一枚減らしつつ，turn替え

print((turn.upper()))#upperは大文字にするやつ
from collections import deque

sa = deque(list(eval(input())))
sb = deque(list(eval(input())))
sc = deque(list(eval(input())))
turn = 1
for i in range(10**10):
    if turn == 1:
        if len(sa) == 0:
            print("A")
            exit()
        tmp = sa.popleft()
        if tmp == "b":
            turn = 2
        elif tmp == "c":
            turn = 3
    if turn == 2:
        if len(sb) == 0:
            print("B")
            exit()
        tmp = sb.popleft()
        if tmp == "a":
            turn = 1
        elif tmp == "c":
            turn = 3
    if turn == 3:
        if len(sc) == 0:
            print("C")
            exit()
        tmp = sc.popleft()
        if tmp == "a":
            turn = 1
        elif tmp == "b":
            turn = 2

sa = [i for i in eval(input())]
sb = [i for i in eval(input())]
sc = [i for i in eval(input())]
d = {"a": sa, "b": sb, "c": sc}  # おのおのの手札をdictで表す
turn = "a"
while True:  # breakするまで続く
    if len(d[turn]) == 0:
        break
    turn = d[turn].pop(0)  # 一枚減らしつつ，turn替え
print((turn.upper()))  # upperは大文字にするやつ

-from collections import deque - -sa = deque(list(eval(input()))) -sb = deque(list(eval(input()))) -sc = deque(list(eval(input()))) -turn = 1 -for i in range(10**10): -    if turn == 1: -        if len(sa) == 0: -            print("A") -            exit() -        tmp = sa.popleft() -        if tmp == "b": -            turn = 2 -        elif tmp == "c": -            turn = 3 -    if turn == 2: -        if len(sb) == 0: -            print("B") -            exit() -        tmp = sb.popleft() -        if tmp == "a": -            turn = 1 -        elif tmp == "c": -            turn = 3 -    if turn == 3: -        if len(sc) == 0: -            print("C") -            exit() -        tmp = sc.popleft() -        if tmp == "a": -            turn = 1 -        elif tmp == "b": -            turn = 2 +sa = [i for i in eval(input())] +sb = [i for i in eval(input())] +sc = [i for i in eval(input())] +d = {"a": sa, "b": sb, "c": sc}  # おのおのの手札をdictで表す +turn = "a" +while True:  # breakするまで続く +    if len(d[turn]) == 0: +        break +    turn = d[turn].pop(0)  # 一枚減らしつつ，turn替え +print((turn.upper()))  # upperは大文字にするやつ