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.
S= [input() for i in range(3)]
a, b, c = S[0], S[1], S[2]
p = 'a'
a_counter = 0
b_counter = 0
c_counter = 0
for i in range(len(a)+len(b)+len(c)):
  if p == 'a':
    if len(a) == 0:
      print('a')
      break
    else:
      p = a[0]
      a = a[1:]
      pass
  elif p == 'b':
    if len(b) == 0:
      print('b')
      break
    else:
      p = b[0]
      b = b[1:]
      pass
  else :
    if len(c) == 0:
      print('c')
      break
    else:
      p = c[0]
      c = c[1:]
      pass

S= [input() for i in range(3)]
a, b, c = S[0], S[1], S[2]
p = 'a'
a_counter = 0
b_counter = 0
c_counter = 0
for i in range(len(a)+len(b)+len(c)):
  if p == 'a':
    if len(a) == 0:
      print('A')
      break
    else:
      p = a[0]
      a = a[1:]
      pass
  elif p == 'b':
    if len(b) == 0:
      print('B')
      break
    else:
      p = b[0]
      b = b[1:]
      pass
  else :
    if len(c) == 0:
      print('C')
      break
    else:
      p = c[0]
      c = c[1:]
      pass
