import collections



S=[eval(input()) for _ in range(3)]

#print(S)



S=list([x.replace("a","0").replace("b","1").replace("c","2") for x in S])

#print(S)



S=list([collections.deque(list(x)) for x in S])

#print(S)



i=0

while 1:

  if len(S[i])==0:

    break

  i=int(S[i].popleft())

  #print(S,i)

print((chr(i+65)))
S = [[{"a": 0, "b": 1, "c": 2}[s] for s in input()[::-1]]for _ in range(3)]

T = {0: "A", 1: "B", 2: "C"}



c = 0

while 1:

    c = S[c].pop()

    if not S[c]:

        print((T[c]))

        exit()
import collections

S = [eval(input()) for _ in range(3)]
# print(S)
S = list([x.replace("a", "0").replace("b", "1").replace("c", "2") for x in S])
# print(S)
S = list([collections.deque(list(x)) for x in S])
# print(S)
i = 0
while 1:
    if len(S[i]) == 0:
        break
    i = int(S[i].popleft())
    # print(S,i)
print((chr(i + 65)))

S = [[{"a": 0, "b": 1, "c": 2}[s] for s in input()[::-1]] for _ in range(3)]
T = {0: "A", 1: "B", 2: "C"}
c = 0
while 1:
    c = S[c].pop()
    if not S[c]:
        print((T[c]))
        exit()

-import collections - -S = [eval(input()) for _ in range(3)] -# print(S) -S = list([x.replace("a", "0").replace("b", "1").replace("c", "2") for x in S]) -# print(S) -S = list([collections.deque(list(x)) for x in S]) -# print(S) -i = 0 +S = [[{"a": 0, "b": 1, "c": 2}[s] for s in input()[::-1]] for _ in range(3)] +T = {0: "A", 1: "B", 2: "C"} +c = 0 -    if len(S[i]) == 0: -        break -    i = int(S[i].popleft()) -    # print(S,i) -print((chr(i + 65))) +    c = S[c].pop() +    if not S[c]: +        print((T[c])) +        exit()