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

public class Main {
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        
        Map<Character, String> s = new HashMap<>();
        s.put('a', stdin.nextLine());
        s.put('b', stdin.nextLine());
        s.put('c', stdin.nextLine());
        
        char turn = 'a';
        while (!s.get(turn).isEmpty()) {
            String t = s.get(turn);
            s.put(turn, t.substring(1));
            turn = t.charAt(0);
        }
        
        System.out.println(Character.toUpperCase(turn));
    }
}

/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