from collections import Counter,defaultdict,deque

from heapq import heappop,heappush,heapify

import sys,bisect,math,itertools

sys.setrecursionlimit(10**8)

mod = 10**9+7

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))



s = [list(eval(input())) for i in range(3)]

t = [[],[],[]]

for i in range(3):

    for j in range(len(s[i])):

        if s[i][j] == 'a':

            t[i].append(0)

        elif s[i][j] == 'b':

            t[i].append(1)

        else:

            t[i].append(2)

# print(s)

now = 0

while True:

    tmp = t[now][0]

    del t[now][0]

    now = tmp

    if not len(t[now]):

        break

if now == 0:

    print('A')

elif now == 1:

    print('B')

else:

    print('C')

from collections import Counter,defaultdict,deque

from heapq import heappop,heappush,heapify

from bisect import bisect_left,bisect_right 

import sys,math,itertools,fractions,pprint

sys.setrecursionlimit(10**8)

mod = 10**9+7

INF = float('inf')

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))



s = [deque() for i in range(3)]

for i in range(3):

    a = eval(input())

    for t in a:

        tmp = ord(t)-ord('a')

        s[i].append(tmp)

now = 0

while True:

    if s[now]:

        now = s[now].popleft()

    else:

        print((chr(ord('A') + now)))

        break

from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools

sys.setrecursionlimit(10**8)
mod = 10**9 + 7


def inp():
    return int(sys.stdin.readline())


def inpl():
    return list(map(int, sys.stdin.readline().split()))


def inpln(n):
    return list(int(sys.stdin.readline()) for i in range(n))


s = [list(eval(input())) for i in range(3)]
t = [[], [], []]
for i in range(3):
    for j in range(len(s[i])):
        if s[i][j] == "a":
            t[i].append(0)
        elif s[i][j] == "b":
            t[i].append(1)
        else:
            t[i].append(2)
# print(s)
now = 0
while True:
    tmp = t[now][0]
    del t[now][0]
    now = tmp
    if not len(t[now]):
        break
if now == 0:
    print("A")
elif now == 1:
    print("B")
else:
    print("C")

from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
from bisect import bisect_left, bisect_right
import sys, math, itertools, fractions, pprint

sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")


def inp():
    return int(sys.stdin.readline())


def inpl():
    return list(map(int, sys.stdin.readline().split()))


s = [deque() for i in range(3)]
for i in range(3):
    a = eval(input())
    for t in a:
        tmp = ord(t) - ord("a")
        s[i].append(tmp)
now = 0
while True:
    if s[now]:
        now = s[now].popleft()
    else:
        print((chr(ord("A") + now)))
        break

-import sys, bisect, math, itertools +from bisect import bisect_left, bisect_right +import sys, math, itertools, fractions, pprint +INF = float("inf") -def inpln(n): -    return list(int(sys.stdin.readline()) for i in range(n)) - - -s = [list(eval(input())) for i in range(3)] -t = [[], [], []] +s = [deque() for i in range(3)] -    for j in range(len(s[i])): -        if s[i][j] == "a": -            t[i].append(0) -        elif s[i][j] == "b": -            t[i].append(1) -        else: -            t[i].append(2) -# print(s) +    a = eval(input()) +    for t in a: +        tmp = ord(t) - ord("a") +        s[i].append(tmp) -    tmp = t[now][0] -    del t[now][0] -    now = tmp -    if not len(t[now]): +    if s[now]: +        now = s[now].popleft() +    else: +        print((chr(ord("A") + now))) -if now == 0: -    print("A") -elif now == 1: -    print("B") -else: -    print("C")