import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Map<Character, char[]> cardMap = new HashMap<Character, char[]>();
        cardMap.put('a', scanner.nextLine().toCharArray());
        cardMap.put('b', scanner.nextLine().toCharArray());
        cardMap.put('c', scanner.nextLine().toCharArray());
        Map<Character, Integer> indexMap = new HashMap<Character, Integer>();
        indexMap.put('a', 0);
        indexMap.put('b', 0);
        indexMap.put('c', 0);

        System.out.print(play('a', cardMap, indexMap));


    }

    private static char play(char now, Map<Character, char[]> cardMap, Map<Character, Integer> indexMap) {
        char card[] = cardMap.get(now);
        int index = indexMap.get(now);

        if (index >= card.length )
            return Character.toUpperCase(now);

        char next = card[index];
        indexMap.put(now, index+1);
        return play(next, cardMap, indexMap);
    }
}

/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