A = list(eval(input()))

B = list(eval(input()))

C = list(eval(input()))



card = A.pop(0)

while True:

    if card == 'a':

        if A:

            card = A.pop(0)

        else:

            print('A')

            exit()

    elif card == 'b':

        if B:

            card = B.pop(0)

        else:

            print('B')

            exit()

    else:

        if C:

            card = C.pop(0)

        else:

            print('C')

            exit()
import sys

stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

from collections import deque



i_i = lambda: int(i_s())

i_l = lambda: list(map(int, stdin.readline().split()))

i_s = lambda: stdin.readline().rstrip()



a = deque(list(i_s()))

b = deque(list(i_s()))

c = deque(list(i_s()))



x = a.popleft()

while True:

    if a and x == 'a':

        x = a.popleft()

    elif not a and x == 'a':

        print('A')

        exit()

    elif b and x == 'b':

        x = b.popleft()

    elif not b and x == 'b':

        print('B')

        exit()

    elif c and x == 'c':

        x = c.popleft()

    elif not c and x == 'c':

        print('C')

        exit()

A = list(eval(input()))
B = list(eval(input()))
C = list(eval(input()))
card = A.pop(0)
while True:
    if card == "a":
        if A:
            card = A.pop(0)
        else:
            print("A")
            exit()
    elif card == "b":
        if B:
            card = B.pop(0)
        else:
            print("B")
            exit()
    else:
        if C:
            card = C.pop(0)
        else:
            print("C")
            exit()

import sys

stdin = sys.stdin
sys.setrecursionlimit(10**7)
from collections import deque

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()
a = deque(list(i_s()))
b = deque(list(i_s()))
c = deque(list(i_s()))
x = a.popleft()
while True:
    if a and x == "a":
        x = a.popleft()
    elif not a and x == "a":
        print("A")
        exit()
    elif b and x == "b":
        x = b.popleft()
    elif not b and x == "b":
        print("B")
        exit()
    elif c and x == "c":
        x = c.popleft()
    elif not c and x == "c":
        print("C")
        exit()

-A = list(eval(input())) -B = list(eval(input())) -C = list(eval(input())) -card = A.pop(0) +import sys + +stdin = sys.stdin +sys.setrecursionlimit(10**7) +from collections import deque + +i_i = lambda: int(i_s()) +i_l = lambda: list(map(int, stdin.readline().split())) +i_s = lambda: stdin.readline().rstrip() +a = deque(list(i_s())) +b = deque(list(i_s())) +c = deque(list(i_s())) +x = a.popleft() -    if card == "a": -        if A: -            card = A.pop(0) -        else: -            print("A") -            exit() -    elif card == "b": -        if B: -            card = B.pop(0) -        else: -            print("B") -            exit() -    else: -        if C: -            card = C.pop(0) -        else: -            print("C") -            exit() +    if a and x == "a": +        x = a.popleft() +    elif not a and x == "a": +        print("A") +        exit() +    elif b and x == "b": +        x = b.popleft() +    elif not b and x == "b": +        print("B") +        exit() +    elif c and x == "c": +        x = c.popleft() +    elif not c and x == "c": +        print("C") +        exit()