import java.util.*;

class Main {
  	static final int INF = Integer.MAX_VALUE;
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in); 
		char[] as = sc.next().toCharArray(), 
			   bs = sc.next().toCharArray(),
			   cs = sc.next().toCharArray();
      
      	int a = 0, b = 0, c = 0;
      	int w = 'a';
      
      	while (true) {
        	switch (w) {
              case 'a':
                if (a == as.length) { System.out.println("A"); return; }
                w = as[a];
                a++;
                break;
              case 'b':
                if (b == bs.length) { System.out.println("B"); return; }
                w = bs[b];
                b++;
                break;
              case 'c':
                if (c == cs.length) { System.out.println("C"); return; }
                w = cs[c];
               	c++;	
                break;
            }
        }
    }
}
/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