a=eval(input())

b=eval(input())

c=eval(input())

a+="A"

b+="B"

c+="C"

n=a

while True:

  if len(n)>1:

    k=n[0]

    if n==a:

      a=a[1:]

    elif n==b:

      b=b[1:]

    else:

      c=c[1:]

    if k=="a":

      n=a

    elif k=="b":

      n=b

    else:

      n=c

  else:

    print((n[-1]))

    break
A=eval(input())

B=eval(input())

C=eval(input())

moto=A

suji="a"

while True:

  if len(moto)==0:

    if suji=="a":

      print("A")

      exit()

    if suji=="b":

      print("B")

      exit()

    if suji=="c":

      print("C")

      exit()

  s=moto[0]

  if suji=="a":

    A=A[1:]

  if suji=="b":

    B=B[1:]

  if suji=="c":

    C=C[1:]

  if s=="a":

    moto=A

    suji="a"

  if s=="b":

    moto=B

    suji="b"

  if s=="c":

    moto=C

    suji="c"
a = eval(input())
b = eval(input())
c = eval(input())
a += "A"
b += "B"
c += "C"
n = a
while True:
    if len(n) > 1:
        k = n[0]
        if n == a:
            a = a[1:]
        elif n == b:
            b = b[1:]
        else:
            c = c[1:]
        if k == "a":
            n = a
        elif k == "b":
            n = b
        else:
            n = c
    else:
        print((n[-1]))
        break

A = eval(input())
B = eval(input())
C = eval(input())
moto = A
suji = "a"
while True:
    if len(moto) == 0:
        if suji == "a":
            print("A")
            exit()
        if suji == "b":
            print("B")
            exit()
        if suji == "c":
            print("C")
            exit()
    s = moto[0]
    if suji == "a":
        A = A[1:]
    if suji == "b":
        B = B[1:]
    if suji == "c":
        C = C[1:]
    if s == "a":
        moto = A
        suji = "a"
    if s == "b":
        moto = B
        suji = "b"
    if s == "c":
        moto = C
        suji = "c"

-a = eval(input()) -b = eval(input()) -c = eval(input()) -a += "A" -b += "B" -c += "C" -n = a +A = eval(input()) +B = eval(input()) +C = eval(input()) +moto = A +suji = "a" -    if len(n) > 1: -        k = n[0] -        if n == a: -            a = a[1:] -        elif n == b: -            b = b[1:] -        else: -            c = c[1:] -        if k == "a": -            n = a -        elif k == "b": -            n = b -        else: -            n = c -    else: -        print((n[-1])) -        break +    if len(moto) == 0: +        if suji == "a": +            print("A") +            exit() +        if suji == "b": +            print("B") +            exit() +        if suji == "c": +            print("C") +            exit() +    s = moto[0] +    if suji == "a": +        A = A[1:] +    if suji == "b": +        B = B[1:] +    if suji == "c": +        C = C[1:] +    if s == "a": +        moto = A +        suji = "a" +    if s == "b": +        moto = B +        suji = "b" +    if s == "c": +        moto = C +        suji = "c"