from collections import deque

a=deque(list(eval(input())))

b=deque(list(eval(input())))

c=deque(list(eval(input())))

tmp=a.popleft()

while 1:

    if tmp=='a':

        if not len(a):

            print('A')

            break

        tmp=a.popleft()

    elif tmp=='b':

        if not len(b):

            print('B')

            break

        tmp=b.popleft()

    else:

        if not len(c):

            print('C')

            break

        tmp=c.popleft()

s={i:list(eval(input())) for i in 'abc'}

tmp='a'

while s[tmp]:

    tmp=s[tmp].pop(0)

print((tmp.upper()))



# (#4130525)
from collections import deque

a = deque(list(eval(input())))
b = deque(list(eval(input())))
c = deque(list(eval(input())))
tmp = a.popleft()
while 1:
    if tmp == "a":
        if not len(a):
            print("A")
            break
        tmp = a.popleft()
    elif tmp == "b":
        if not len(b):
            print("B")
            break
        tmp = b.popleft()
    else:
        if not len(c):
            print("C")
            break
        tmp = c.popleft()

s = {i: list(eval(input())) for i in "abc"}
tmp = "a"
while s[tmp]:
    tmp = s[tmp].pop(0)
print((tmp.upper()))
# (#4130525)

-from collections import deque - -a = deque(list(eval(input()))) -b = deque(list(eval(input()))) -c = deque(list(eval(input()))) -tmp = a.popleft() -while 1: -    if tmp == "a": -        if not len(a): -            print("A") -            break -        tmp = a.popleft() -    elif tmp == "b": -        if not len(b): -            print("B") -            break -        tmp = b.popleft() -    else: -        if not len(c): -            print("C") -            break -        tmp = c.popleft() +s = {i: list(eval(input())) for i in "abc"} +tmp = "a" +while s[tmp]: +    tmp = s[tmp].pop(0) +print((tmp.upper())) +# (#4130525)