import sys

from collections import deque

readline = sys.stdin.buffer.readline

sys.setrecursionlimit(10 ** 8)

INF = float('inf')

MOD = 10 ** 9 + 7



def main():

    SA = readline().decode('utf-8').strip()

    SB = readline().decode('utf-8').strip()

    SC = readline().decode('utf-8')

    A = deque(SA)

    B = deque(SB)

    C = deque(SC)

    next = A.popleft()

    while True:

        if next=='a':

            if not A:

                print('A')

                break

            next = A.popleft()

        elif next=='b':

            if not B:

                print('B')

                break

            next = B.popleft()

        else:

            if not C:

                print('C')

                break

            next = C.popleft()







if __name__ == '__main__':

    main()
import sys

from _collections import deque

readline = sys.stdin.buffer.readline

sys.setrecursionlimit(10 ** 8)

INF = float('inf')

MOD = 10 ** 9 + 7





def main():

    SA = readline().decode('utf-8').strip()

    SB = readline().decode('utf-8').strip()

    SC = readline().decode('utf-8').strip()

    A = deque(SA)

    B = deque(SB)

    C = deque(SC)

    now = A.popleft()

    while True:

        if now=='a':

            if not A:

                print('A')

                break

            else:

                now = A.popleft()

        elif now=='b':

            if not B:

                print('B')

                break

            else:

                now = B.popleft()

        else:

            if not C:

                print('C')

                break

            else:

                now = C.popleft()



if __name__ == '__main__':

    main()
import sys
from collections import deque

readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**8)
INF = float("inf")
MOD = 10**9 + 7


def main():
    SA = readline().decode("utf-8").strip()
    SB = readline().decode("utf-8").strip()
    SC = readline().decode("utf-8")
    A = deque(SA)
    B = deque(SB)
    C = deque(SC)
    next = A.popleft()
    while True:
        if next == "a":
            if not A:
                print("A")
                break
            next = A.popleft()
        elif next == "b":
            if not B:
                print("B")
                break
            next = B.popleft()
        else:
            if not C:
                print("C")
                break
            next = C.popleft()


if __name__ == "__main__":
    main()

import sys
from _collections import deque

readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**8)
INF = float("inf")
MOD = 10**9 + 7


def main():
    SA = readline().decode("utf-8").strip()
    SB = readline().decode("utf-8").strip()
    SC = readline().decode("utf-8").strip()
    A = deque(SA)
    B = deque(SB)
    C = deque(SC)
    now = A.popleft()
    while True:
        if now == "a":
            if not A:
                print("A")
                break
            else:
                now = A.popleft()
        elif now == "b":
            if not B:
                print("B")
                break
            else:
                now = B.popleft()
        else:
            if not C:
                print("C")
                break
            else:
                now = C.popleft()


if __name__ == "__main__":
    main()

-from collections import deque +from _collections import deque -    SC = readline().decode("utf-8") +    SC = readline().decode("utf-8").strip() -    next = A.popleft() +    now = A.popleft() -        if next == "a": +        if now == "a": -            next = A.popleft() -        elif next == "b": +            else: +                now = A.popleft() +        elif now == "b": -            next = B.popleft() +            else: +                now = B.popleft() -            next = C.popleft() +            else: +                now = C.popleft()