Олимпиадный тренинг

Задача 38491. Cards for three


Antoninus, Balbinus and Caesar play the game "Cards for three", the algorithm of which is as follows:
- first, each of the three players has a deck consisting of a certain number of cards. Each card has the letter a, b or c written on it. The order of cards in decks cannot be changed;
- The players take turns. Antonin goes first;
- if there is at least one card in the current player's deck, he must discard the top card in the deck;
- The next turn goes to the player whose name begins with the letter on the discarded card (a - Antoninus, b - Balbinus, c - Caesar );
- if the current player's deck is empty, the game ends and the current player wins the game.
You are given the starting player decks (Sa, Sb, Sc). The state of Antonin's deck is written in the line Sa, where i-th (\(1<=i<=len(S_a)\ )) character is the letter in the i-th card in the deck. The Balbin string (Sb) and the Caesar string () are described in the same way. 
Determine the winner of the game.

Input
The input is three non-zero strings Sa, Sb  and Sc, each on a new line. The length of each line is no more than 100 characters. Each line consists only of the letters a, b, or c.

Imprint
If Antonin won. then print the letter A, if Balbin - the letter B, if Caesar - the letter C.
 

 

Examples
# Input Output Explanations
1
aca
accc
ca
A
The game will evolve as follows:

Antoninus discards the top card of his deck, a. Antonin makes his next move.
Antoninus discards the top card of his deck, c. Caesar is next.
Caesar discards the top card of his deck, c. Caesar is next.
Caesar discards the top card of his deck: a. Antonin makes his next move.
Antoninus discards the top card of his deck: a. Antonin makes his next move.
Antonin's deck is empty. The game ends and Antonin wins the game.
2
abcb
aacb
bcc
C