def main():

    sa = list(eval(input()))

    sb = list(eval(input()))

    sc = list(eval(input()))



    c = {"a": sa, "b": sb, "c": sc}

    now = "a"

    while True:

        s = c[now]

        if len(s) == 0:

            print((now.upper()))

            break



        now = c[now].pop(0)





if __name__ == '__main__':

    main()

from collections import defaultdict





def main():

    d = {"a": eval(input()), "b": eval(input()), "c": eval(input())}

    now = "a"

    while True:

        if len(d[now]) == 0:

            print((now.upper()))

            break

        nex, d[now] = d[now][0], d[now][1:]

        now = nex





if __name__ == '__main__':

    main()

def main():
    sa = list(eval(input()))
    sb = list(eval(input()))
    sc = list(eval(input()))
    c = {"a": sa, "b": sb, "c": sc}
    now = "a"
    while True:
        s = c[now]
        if len(s) == 0:
            print((now.upper()))
            break
        now = c[now].pop(0)


if __name__ == "__main__":
    main()

from collections import defaultdict


def main():
    d = {"a": eval(input()), "b": eval(input()), "c": eval(input())}
    now = "a"
    while True:
        if len(d[now]) == 0:
            print((now.upper()))
            break
        nex, d[now] = d[now][0], d[now][1:]
        now = nex


if __name__ == "__main__":
    main()

+from collections import defaultdict + + -    sa = list(eval(input())) -    sb = list(eval(input())) -    sc = list(eval(input())) -    c = {"a": sa, "b": sb, "c": sc} +    d = {"a": eval(input()), "b": eval(input()), "c": eval(input())} -        s = c[now] -        if len(s) == 0: +        if len(d[now]) == 0: -        now = c[now].pop(0) +        nex, d[now] = d[now][0], d[now][1:] +        now = nex