B - Card Game for Three (ABC Edit) Editorial /

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 200

問題文

A さん、B さん、C さんの 3 人が以下のようなカードゲームをプレイしています。

  • 最初、3 人はそれぞれ abc いずれかの文字が書かれたカードを、何枚か持っている。これらは入力で与えられた順番に持っており、途中で並べ替えたりしない。
  • A さんのターンから始まる。
  • 現在自分のターンである人がカードを 1 枚以上持っているならば、そのうち先頭のカードを捨てる。その後、捨てられたカードに書かれているアルファベットと同じ名前の人 (例えば、カードに a と書かれていたならば A さん) のターンとなる。
  • 現在自分のターンである人がカードを 1 枚も持っていないならば、その人がゲームの勝者となり、ゲームは終了する。

3 人が最初に持っているカードがそれぞれ先頭から順に与えられます。 具体的には、文字列 S_AS_BS_C が与えられます。文字列 S_Ai 文字目 ( 1 \leq i \leq |S_A| ) に書かれている文字が、A さんの持っている中で先頭から i 番目のカードに 書かれている文字です。文字列 S_BS_C についても同様です。

最終的に誰がこのゲームの勝者となるかを求めてください。

制約

  • 1 \leq |S_A| \leq 100
  • 1 \leq |S_B| \leq 100
  • 1 \leq |S_C| \leq 100
  • S_AS_BS_C に含まれる文字はそれぞれ abc のいずれか

入力

入力は以下の形式で標準入力から与えられる。

S_A
S_B
S_C

出力

A さんが勝つなら A、B さんが勝つなら B、C さんが勝つなら C と出力せよ。


入力例 1

aca
accc
ca

出力例 1

A

ゲームは以下のように進行します。

  • A さんが、持っている中で最初のカード a を捨てる。次は A さんの番となる。
  • A さんが、持っている中で最初のカード c を捨てる。次は C さんの番となる。
  • C さんが、持っている中で最初のカード c を捨てる。次は C さんの番となる。
  • C さんが、持っている中で最初のカード a を捨てる。次は A さんの番となる。
  • A さんが、持っている中で最初のカード a を捨てる。次は A さんの番となる。
  • A さんはもう持っているカードがない。よって A さんの勝利となり、ゲームは終了する。

入力例 2

abcb
aacb
bccc

出力例 2

C

Score : 200 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 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.


Sample Input 1

aca
accc
ca

Sample Output 1

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.

Sample Input 2

abcb
aacb
bccc

Sample Output 2

C