100 atcoder#ABC045B. [ABC045B] 3人でカードゲームイージー

[ABC045B] 3人でカードゲームイージー

Score : 200200 points

Problem Statement

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 SAS_A, SBS_B and SCS_C. The ii-th (1iSA)(1 \leq i \leq |S_A|) letter in SAS_A is the letter on the ii-th card in Alice's initial deck. SBS_B and SCS_C describes Bob's and Charlie's initial decks in the same way.

Determine the winner of the game.

Constraints

  • 1SA1001 \leq |S_A| \leq 100
  • 1SB1001 \leq |S_B| \leq 100
  • 1SC1001 \leq |S_C| \leq 100
  • Each letter in SAS_A, SBS_B, SCS_C is a, b or c.

Input

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

SAS_A

SBS_B

SCS_C

Output

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

aca
accc
ca
A

The game will progress as below:

  • Alice discards the top card in her deck, a. Alice takes the next turn.
  • Alice discards the top card in her deck, c. Charlie takes the next turn.
  • Charlie discards the top card in his deck, c. Charlie takes the next turn.
  • Charlie discards the top card in his deck, a. Alice takes the next turn.
  • Alice discards the top card in her deck, a. Alice takes the next turn.
  • Alice's deck is empty. The game ends and Alice wins the game.
abcb
aacb
bccc
C