import string



alphabets = string.ascii_uppercase



players_cards = {}

for i in range(3):

    players_cards[alphabets[i]] = [letter for letter in eval(input())]



first_player = 'A'



next_player = first_player

while True:

    current_player = next_player

    current_player_cards = players_cards[current_player]

    if current_player_cards:

        next_player = current_player_cards[0].upper()

        current_player_cards.pop(0)

    else:

        winner = current_player

        print(winner)

        exit()
import sys

from collections import deque



a, b, c = sys.stdin.read().split()



def main():

    deck = dict([('a', deque(a)), ('b', deque(b)), ('c', deque(c))])



    p = 'a'

    while True:

        if deck[p]:

            p = deck[p].popleft()

        else:

            return p.upper()



if __name__ == '__main__':

    ans = main()

    print(ans)
import string

alphabets = string.ascii_uppercase
players_cards = {}
for i in range(3):
    players_cards[alphabets[i]] = [letter for letter in eval(input())]
first_player = "A"
next_player = first_player
while True:
    current_player = next_player
    current_player_cards = players_cards[current_player]
    if current_player_cards:
        next_player = current_player_cards[0].upper()
        current_player_cards.pop(0)
    else:
        winner = current_player
        print(winner)
        exit()

import sys
from collections import deque

a, b, c = sys.stdin.read().split()


def main():
    deck = dict([("a", deque(a)), ("b", deque(b)), ("c", deque(c))])
    p = "a"
    while True:
        if deck[p]:
            p = deck[p].popleft()
        else:
            return p.upper()


if __name__ == "__main__":
    ans = main()
    print(ans)

-import string +import sys +from collections import deque -alphabets = string.ascii_uppercase -players_cards = {} -for i in range(3): -    players_cards[alphabets[i]] = [letter for letter in eval(input())] -first_player = "A" -next_player = first_player -while True: -    current_player = next_player -    current_player_cards = players_cards[current_player] -    if current_player_cards: -        next_player = current_player_cards[0].upper() -        current_player_cards.pop(0) -    else: -        winner = current_player -        print(winner) -        exit() +a, b, c = sys.stdin.read().split() + + +def main(): +    deck = dict([("a", deque(a)), ("b", deque(b)), ("c", deque(c))]) +    p = "a" +    while True: +        if deck[p]: +            p = deck[p].popleft() +        else: +            return p.upper() + + +if __name__ == "__main__": +    ans = main() +    print(ans)