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();
  }
}

/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz