sa = eval(input())

sb = eval(input())

sc = eval(input())

a = [sa[i] for i in range(len(sa))]

b = [sb[i] for i in range(len(sb))]

c = [sc[i] for i in range(len(sc))]



n = 'a'

while True:

  if n == 'a':

    if len(a) == 0:

      print('A')

      exit()

    else:

      n = a.pop(0)

  elif n == 'b':

    if len(b) == 0:

      print('B')

      exit()

    else:

      n = b.pop(0)

  elif n == 'c':

    if len(c) == 0:

      print('C')

      exit()

    else:

      n = c.pop(0)
sa=eval(input())+'a'

sb=eval(input())+'b'

sc=eval(input())+'c'

st='a'

a=0

b=0

c=0

while a<len(sa) and b<len(sb) and c<len(sc):

  if st=='a':

    st=sa[a]

    a+=1

  elif st=='b':

    st=sb[b]

    b+=1

  else:

    st=sc[c]

    c+=1

if a==len(sa):

  print('A')

elif b==len(sb):

  print('B')

else:

  print('C')
sa = eval(input())
sb = eval(input())
sc = eval(input())
a = [sa[i] for i in range(len(sa))]
b = [sb[i] for i in range(len(sb))]
c = [sc[i] for i in range(len(sc))]
n = "a"
while True:
    if n == "a":
        if len(a) == 0:
            print("A")
            exit()
        else:
            n = a.pop(0)
    elif n == "b":
        if len(b) == 0:
            print("B")
            exit()
        else:
            n = b.pop(0)
    elif n == "c":
        if len(c) == 0:
            print("C")
            exit()
        else:
            n = c.pop(0)

sa = eval(input()) + "a"
sb = eval(input()) + "b"
sc = eval(input()) + "c"
st = "a"
a = 0
b = 0
c = 0
while a < len(sa) and b < len(sb) and c < len(sc):
    if st == "a":
        st = sa[a]
        a += 1
    elif st == "b":
        st = sb[b]
        b += 1
    else:
        st = sc[c]
        c += 1
if a == len(sa):
    print("A")
elif b == len(sb):
    print("B")
else:
    print("C")

-sa = eval(input()) -sb = eval(input()) -sc = eval(input()) -a = [sa[i] for i in range(len(sa))] -b = [sb[i] for i in range(len(sb))] -c = [sc[i] for i in range(len(sc))] -n = "a" -while True: -    if n == "a": -        if len(a) == 0: -            print("A") -            exit() -        else: -            n = a.pop(0) -    elif n == "b": -        if len(b) == 0: -            print("B") -            exit() -        else: -            n = b.pop(0) -    elif n == "c": -        if len(c) == 0: -            print("C") -            exit() -        else: -            n = c.pop(0) +sa = eval(input()) + "a" +sb = eval(input()) + "b" +sc = eval(input()) + "c" +st = "a" +a = 0 +b = 0 +c = 0 +while a < len(sa) and b < len(sb) and c < len(sc): +    if st == "a": +        st = sa[a] +        a += 1 +    elif st == "b": +        st = sb[b] +        b += 1 +    else: +        st = sc[c] +        c += 1 +if a == len(sa): +    print("A") +elif b == len(sb): +    print("B") +else: +    print("C")