human
Give me a Python program to determine the winner of the game given the following:
Alice, Bob and Charlie are playing Card Game for Three, as below:

* At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged.
* The players take turns. Alice goes first.
* If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.)
* If the current player's deck is empty, the game ends and the current player wins the game.


You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way.

Determine the winner of the game.

Constraints

* 1≦|S_A|≦100
* 1≦|S_B|≦100
* 1≦|S_C|≦100
* Each letter in S_A, S_B, S_C is `a`, `b` or `c`.

Input

The input is given from Standard Input in the following format:

S_A
S_B
S_C

Output

If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`.

Examples

Input

aca
accc
ca

Output

A

Input

abcb
aacb
bccc

Output

C
assistant
#Here is Python program to determine the winner of the game.

sa = raw_input()
sb = raw_input()
sc = raw_input()

class Person:
    def __init__(self, name, cards):
        self.name = name
        self.cards = cards

a = Person('A', sa)
b = Person('B', sb)
c = Person('C', sc)

turn = a
while turn.cards:
    if turn.cards[0] == 'a':
        turn.cards = turn.cards.replace('a', '', 1)
        turn = a
    elif turn.cards[0] == 'b':
        turn.cards = turn.cards.replace('b', '',1)
        turn = b
    elif turn.cards[0] == 'c':
        turn.cards = turn.cards.replace('c', '', 1)
        turn = c
print turn.name