import java.util.Scanner;

import java.util.*;


public class Main {

    public static void main(String[] args) {

      Scanner scanner = new Scanner(System.in);
 
      String as = scanner.nextLine();
      String bs = scanner.nextLine();
      String cs = scanner.nextLine();

      Map<Character, char[]> members = new HashMap<>();
      members.put(Character.valueOf('a'), as.toCharArray());
      members.put(Character.valueOf('b'), bs.toCharArray());
      members.put(Character.valueOf('c'), cs.toCharArray());

      char current = 'a';

      while(true) {
        char[] cards = members.get(current);
        if (cards.length == 0) {
          System.out.println(String.valueOf(current).toUpperCase());
          break;
        }

        char prev = current;
        current = cards[0];

        char[] tmpCards = new char[cards.length - 1];
        for (int i = 0; i < cards.length - 1; i++){
          tmpCards[i] = cards[i + 1];
        }

        members.put(Character.valueOf(prev), tmpCards);
      }

      scanner.close();
  }
} import java.util.Scanner; Scanner java.util import java.util.*; util.* java public class Main {

    public static void main(String[] args) {

      Scanner scanner = new Scanner(System.in);
 
      String as = scanner.nextLine();
      String bs = scanner.nextLine();
      String cs = scanner.nextLine();

      Map<Character, char[]> members = new HashMap<>();
      members.put(Character.valueOf('a'), as.toCharArray());
      members.put(Character.valueOf('b'), bs.toCharArray());
      members.put(Character.valueOf('c'), cs.toCharArray());

      char current = 'a';

      while(true) {
        char[] cards = members.get(current);
        if (cards.length == 0) {
          System.out.println(String.valueOf(current).toUpperCase());
          break;
        }

        char prev = current;
        current = cards[0];

        char[] tmpCards = new char[cards.length - 1];
        for (int i = 0; i < cards.length - 1; i++){
          tmpCards[i] = cards[i + 1];
        }

        members.put(Character.valueOf(prev), tmpCards);
      }

      scanner.close();
  }
} Main public static void main(String[] args) {

      Scanner scanner = new Scanner(System.in);
 
      String as = scanner.nextLine();
      String bs = scanner.nextLine();
      String cs = scanner.nextLine();

      Map<Character, char[]> members = new HashMap<>();
      members.put(Character.valueOf('a'), as.toCharArray());
      members.put(Character.valueOf('b'), bs.toCharArray());
      members.put(Character.valueOf('c'), cs.toCharArray());

      char current = 'a';

      while(true) {
        char[] cards = members.get(current);
        if (cards.length == 0) {
          System.out.println(String.valueOf(current).toUpperCase());
          break;
        }

        char prev = current;
        current = cards[0];

        char[] tmpCards = new char[cards.length - 1];
        for (int i = 0; i < cards.length - 1; i++){
          tmpCards[i] = cards[i + 1];
        }

        members.put(Character.valueOf(prev), tmpCards);
      }

      scanner.close();
  } main {

      Scanner scanner = new Scanner(System.in);
 
      String as = scanner.nextLine();
      String bs = scanner.nextLine();
      String cs = scanner.nextLine();

      Map<Character, char[]> members = new HashMap<>();
      members.put(Character.valueOf('a'), as.toCharArray());
      members.put(Character.valueOf('b'), bs.toCharArray());
      members.put(Character.valueOf('c'), cs.toCharArray());

      char current = 'a';

      while(true) {
        char[] cards = members.get(current);
        if (cards.length == 0) {
          System.out.println(String.valueOf(current).toUpperCase());
          break;
        }

        char prev = current;
        current = cards[0];

        char[] tmpCards = new char[cards.length - 1];
        for (int i = 0; i < cards.length - 1; i++){
          tmpCards[i] = cards[i + 1];
        }

        members.put(Character.valueOf(prev), tmpCards);
      }

      scanner.close();
  } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) String as = scanner.nextLine(); as scanner.nextLine() scanner.nextLine scanner String bs = scanner.nextLine(); bs scanner.nextLine() scanner.nextLine scanner String cs = scanner.nextLine(); cs scanner.nextLine() scanner.nextLine scanner Map<Character, char[]> members = new HashMap<>(); members new HashMap<>() members.put(Character.valueOf('a'), as.toCharArray()) members.put members Character.valueOf('a') Character.valueOf Character 'a' as.toCharArray() as.toCharArray as members.put(Character.valueOf('b'), bs.toCharArray()) members.put members Character.valueOf('b') Character.valueOf Character 'b' bs.toCharArray() bs.toCharArray bs members.put(Character.valueOf('c'), cs.toCharArray()) members.put members Character.valueOf('c') Character.valueOf Character 'c' cs.toCharArray() cs.toCharArray cs char current = 'a'; current 'a' while(true) {
        char[] cards = members.get(current);
        if (cards.length == 0) {
          System.out.println(String.valueOf(current).toUpperCase());
          break;
        }

        char prev = current;
        current = cards[0];

        char[] tmpCards = new char[cards.length - 1];
        for (int i = 0; i < cards.length - 1; i++){
          tmpCards[i] = cards[i + 1];
        }

        members.put(Character.valueOf(prev), tmpCards);
      } true {
        char[] cards = members.get(current);
        if (cards.length == 0) {
          System.out.println(String.valueOf(current).toUpperCase());
          break;
        }

        char prev = current;
        current = cards[0];

        char[] tmpCards = new char[cards.length - 1];
        for (int i = 0; i < cards.length - 1; i++){
          tmpCards[i] = cards[i + 1];
        }

        members.put(Character.valueOf(prev), tmpCards);
      } char[] cards = members.get(current); cards members.get(current) members.get members current if (cards.length == 0) {
          System.out.println(String.valueOf(current).toUpperCase());
          break;
        } cards.length == 0 cards.length cards cards.length 0 {
          System.out.println(String.valueOf(current).toUpperCase());
          break;
        } System.out.println(String.valueOf(current).toUpperCase()) System.out.println System.out System System.out String.valueOf(current).toUpperCase() String.valueOf(current).toUpperCase String.valueOf(current) String.valueOf String current break; char prev = current; prev current current = cards[0] current cards[0] cards 0 char[] tmpCards = new char[cards.length - 1]; tmpCards new char[cards.length - 1] cards.length - 1 cards.length cards cards.length 1 for (int i = 0; i < cards.length - 1; i++){
          tmpCards[i] = cards[i + 1];
        } int i = 0; int i = 0; i 0 i < cards.length - 1 i cards.length - 1 cards.length cards cards.length 1 i++ i++ i {
          tmpCards[i] = cards[i + 1];
        } {
          tmpCards[i] = cards[i + 1];
        } tmpCards[i] = cards[i + 1] tmpCards[i] tmpCards i cards[i + 1] cards i + 1 i 1 members.put(Character.valueOf(prev), tmpCards) members.put members Character.valueOf(prev) Character.valueOf Character prev tmpCards scanner.close() scanner.close scanner String[] args args public class Main {

    public static void main(String[] args) {

      Scanner scanner = new Scanner(System.in);
 
      String as = scanner.nextLine();
      String bs = scanner.nextLine();
      String cs = scanner.nextLine();

      Map<Character, char[]> members = new HashMap<>();
      members.put(Character.valueOf('a'), as.toCharArray());
      members.put(Character.valueOf('b'), bs.toCharArray());
      members.put(Character.valueOf('c'), cs.toCharArray());

      char current = 'a';

      while(true) {
        char[] cards = members.get(current);
        if (cards.length == 0) {
          System.out.println(String.valueOf(current).toUpperCase());
          break;
        }

        char prev = current;
        current = cards[0];

        char[] tmpCards = new char[cards.length - 1];
        for (int i = 0; i < cards.length - 1; i++){
          tmpCards[i] = cards[i + 1];
        }

        members.put(Character.valueOf(prev), tmpCards);
      }

      scanner.close();
  }
} public class Main {

    public static void main(String[] args) {

      Scanner scanner = new Scanner(System.in);
 
      String as = scanner.nextLine();
      String bs = scanner.nextLine();
      String cs = scanner.nextLine();

      Map<Character, char[]> members = new HashMap<>();
      members.put(Character.valueOf('a'), as.toCharArray());
      members.put(Character.valueOf('b'), bs.toCharArray());
      members.put(Character.valueOf('c'), cs.toCharArray());

      char current = 'a';

      while(true) {
        char[] cards = members.get(current);
        if (cards.length == 0) {
          System.out.println(String.valueOf(current).toUpperCase());
          break;
        }

        char prev = current;
        current = cards[0];

        char[] tmpCards = new char[cards.length - 1];
        for (int i = 0; i < cards.length - 1; i++){
          tmpCards[i] = cards[i + 1];
        }

        members.put(Character.valueOf(prev), tmpCards);
      }

      scanner.close();
  }
} Main
import java.util.Scanner;

import java.util.*;


public class Main {

    public static void main(String[] args) {

      Scanner scanner = new Scanner(System.in);
 
      String as = scanner.nextLine();
      String bs = scanner.nextLine();
      String cs = scanner.nextLine();

      Map<Character, char[]> members = new HashMap<>();
      members.put(Character.valueOf('a'), as.toCharArray());
      members.put(Character.valueOf('b'), bs.toCharArray());
      members.put(Character.valueOf('c'), cs.toCharArray());

      char current = 'a';

      while(true) {
        char[] cards = members.get(current);
        if (cards.length == 0) {
          System.out.println(String.valueOf(current).toUpperCase());
          break;
        }

        char prev = current;
        current = cards[0];

        char[] tmpCards = new char[cards.length - 1];
        for (int i = 0; i < cards.length - 1; i++){
          tmpCards[i] = cards[i + 1];
        }

        members.put(Character.valueOf(prev), tmpCards);
      }

      scanner.close();
  }
}
