import java.util.*;
 
public class Main{
 
	public static void main(String[] args){
 
		Scanner sc = new Scanner(System.in);
        String ss[] = {sc.next(),sc.next(),sc.next()};
      	int counts[] = {0,0,0};
      	boolean game = true;
      	int istack;
      	char cstack;
      	Map<Character, Integer> pMap1 = new HashMap<Character, Integer>();
		pMap1.put('a',0);
      	pMap1.put('b',1);
      	pMap1.put('c',2);
      	Map<Integer,Character> pMap2 = new HashMap<Integer,Character>();
		pMap2.put(0,'A');
      	pMap2.put(1,'B');
      	pMap2.put(2,'C');
      	
      	cstack = ss[0].charAt(0);
      	counts[0]++;
      	istack = istack = pMap1.get(cstack);
       	while(game){
          	if(counts[istack] == ss[istack].length()) {
              System.out.println(pMap2.get(istack));
              game = false;
            } else{            	              	
              	cstack = ss[istack].charAt(counts[istack]); 
                counts[istack]++;
              	istack = pMap1.get(cstack);         }
        }
   }
} import java.util.*; util.* java public class Main{
 
	public static void main(String[] args){
 
		Scanner sc = new Scanner(System.in);
        String ss[] = {sc.next(),sc.next(),sc.next()};
      	int counts[] = {0,0,0};
      	boolean game = true;
      	int istack;
      	char cstack;
      	Map<Character, Integer> pMap1 = new HashMap<Character, Integer>();
		pMap1.put('a',0);
      	pMap1.put('b',1);
      	pMap1.put('c',2);
      	Map<Integer,Character> pMap2 = new HashMap<Integer,Character>();
		pMap2.put(0,'A');
      	pMap2.put(1,'B');
      	pMap2.put(2,'C');
      	
      	cstack = ss[0].charAt(0);
      	counts[0]++;
      	istack = istack = pMap1.get(cstack);
       	while(game){
          	if(counts[istack] == ss[istack].length()) {
              System.out.println(pMap2.get(istack));
              game = false;
            } else{            	              	
              	cstack = ss[istack].charAt(counts[istack]); 
                counts[istack]++;
              	istack = pMap1.get(cstack);         }
        }
   }
} Main public static void main(String[] args){
 
		Scanner sc = new Scanner(System.in);
        String ss[] = {sc.next(),sc.next(),sc.next()};
      	int counts[] = {0,0,0};
      	boolean game = true;
      	int istack;
      	char cstack;
      	Map<Character, Integer> pMap1 = new HashMap<Character, Integer>();
		pMap1.put('a',0);
      	pMap1.put('b',1);
      	pMap1.put('c',2);
      	Map<Integer,Character> pMap2 = new HashMap<Integer,Character>();
		pMap2.put(0,'A');
      	pMap2.put(1,'B');
      	pMap2.put(2,'C');
      	
      	cstack = ss[0].charAt(0);
      	counts[0]++;
      	istack = istack = pMap1.get(cstack);
       	while(game){
          	if(counts[istack] == ss[istack].length()) {
              System.out.println(pMap2.get(istack));
              game = false;
            } else{            	              	
              	cstack = ss[istack].charAt(counts[istack]); 
                counts[istack]++;
              	istack = pMap1.get(cstack);         }
        }
   } main {
 
		Scanner sc = new Scanner(System.in);
        String ss[] = {sc.next(),sc.next(),sc.next()};
      	int counts[] = {0,0,0};
      	boolean game = true;
      	int istack;
      	char cstack;
      	Map<Character, Integer> pMap1 = new HashMap<Character, Integer>();
		pMap1.put('a',0);
      	pMap1.put('b',1);
      	pMap1.put('c',2);
      	Map<Integer,Character> pMap2 = new HashMap<Integer,Character>();
		pMap2.put(0,'A');
      	pMap2.put(1,'B');
      	pMap2.put(2,'C');
      	
      	cstack = ss[0].charAt(0);
      	counts[0]++;
      	istack = istack = pMap1.get(cstack);
       	while(game){
          	if(counts[istack] == ss[istack].length()) {
              System.out.println(pMap2.get(istack));
              game = false;
            } else{            	              	
              	cstack = ss[istack].charAt(counts[istack]); 
                counts[istack]++;
              	istack = pMap1.get(cstack);         }
        }
   } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String ss[] = {sc.next(),sc.next(),sc.next()}; ss {sc.next(),sc.next(),sc.next()} sc.next() sc.next sc sc.next() sc.next sc sc.next() sc.next sc int counts[] = {0,0,0}; counts {0,0,0} 0 0 0 boolean game = true; game true int istack; istack char cstack; cstack Map<Character, Integer> pMap1 = new HashMap<Character, Integer>(); pMap1 new HashMap<Character, Integer>() pMap1.put('a',0) pMap1.put pMap1 'a' 0 pMap1.put('b',1) pMap1.put pMap1 'b' 1 pMap1.put('c',2) pMap1.put pMap1 'c' 2 Map<Integer,Character> pMap2 = new HashMap<Integer,Character>(); pMap2 new HashMap<Integer,Character>() pMap2.put(0,'A') pMap2.put pMap2 0 'A' pMap2.put(1,'B') pMap2.put pMap2 1 'B' pMap2.put(2,'C') pMap2.put pMap2 2 'C' cstack = ss[0].charAt(0) cstack ss[0].charAt(0) ss[0].charAt ss[0] ss 0 0 counts[0]++ counts[0] counts 0 istack = istack = pMap1.get(cstack) istack istack = pMap1.get(cstack) istack pMap1.get(cstack) pMap1.get pMap1 cstack while(game){
          	if(counts[istack] == ss[istack].length()) {
              System.out.println(pMap2.get(istack));
              game = false;
            } else{            	              	
              	cstack = ss[istack].charAt(counts[istack]); 
                counts[istack]++;
              	istack = pMap1.get(cstack);         }
        } game {
          	if(counts[istack] == ss[istack].length()) {
              System.out.println(pMap2.get(istack));
              game = false;
            } else{            	              	
              	cstack = ss[istack].charAt(counts[istack]); 
                counts[istack]++;
              	istack = pMap1.get(cstack);         }
        } if(counts[istack] == ss[istack].length()) {
              System.out.println(pMap2.get(istack));
              game = false;
            } else{            	              	
              	cstack = ss[istack].charAt(counts[istack]); 
                counts[istack]++;
              	istack = pMap1.get(cstack);         } counts[istack] == ss[istack].length() counts[istack] counts istack ss[istack].length() ss[istack].length ss[istack] ss istack {
              System.out.println(pMap2.get(istack));
              game = false;
            } System.out.println(pMap2.get(istack)) System.out.println System.out System System.out pMap2.get(istack) pMap2.get pMap2 istack game = false game false {            	              	
              	cstack = ss[istack].charAt(counts[istack]); 
                counts[istack]++;
              	istack = pMap1.get(cstack);         } cstack = ss[istack].charAt(counts[istack]) cstack ss[istack].charAt(counts[istack]) ss[istack].charAt ss[istack] ss istack counts[istack] counts istack counts[istack]++ counts[istack] counts istack istack = pMap1.get(cstack) istack pMap1.get(cstack) pMap1.get pMap1 cstack String[] args args public class Main{
 
	public static void main(String[] args){
 
		Scanner sc = new Scanner(System.in);
        String ss[] = {sc.next(),sc.next(),sc.next()};
      	int counts[] = {0,0,0};
      	boolean game = true;
      	int istack;
      	char cstack;
      	Map<Character, Integer> pMap1 = new HashMap<Character, Integer>();
		pMap1.put('a',0);
      	pMap1.put('b',1);
      	pMap1.put('c',2);
      	Map<Integer,Character> pMap2 = new HashMap<Integer,Character>();
		pMap2.put(0,'A');
      	pMap2.put(1,'B');
      	pMap2.put(2,'C');
      	
      	cstack = ss[0].charAt(0);
      	counts[0]++;
      	istack = istack = pMap1.get(cstack);
       	while(game){
          	if(counts[istack] == ss[istack].length()) {
              System.out.println(pMap2.get(istack));
              game = false;
            } else{            	              	
              	cstack = ss[istack].charAt(counts[istack]); 
                counts[istack]++;
              	istack = pMap1.get(cstack);         }
        }
   }
} public class Main{
 
	public static void main(String[] args){
 
		Scanner sc = new Scanner(System.in);
        String ss[] = {sc.next(),sc.next(),sc.next()};
      	int counts[] = {0,0,0};
      	boolean game = true;
      	int istack;
      	char cstack;
      	Map<Character, Integer> pMap1 = new HashMap<Character, Integer>();
		pMap1.put('a',0);
      	pMap1.put('b',1);
      	pMap1.put('c',2);
      	Map<Integer,Character> pMap2 = new HashMap<Integer,Character>();
		pMap2.put(0,'A');
      	pMap2.put(1,'B');
      	pMap2.put(2,'C');
      	
      	cstack = ss[0].charAt(0);
      	counts[0]++;
      	istack = istack = pMap1.get(cstack);
       	while(game){
          	if(counts[istack] == ss[istack].length()) {
              System.out.println(pMap2.get(istack));
              game = false;
            } else{            	              	
              	cstack = ss[istack].charAt(counts[istack]); 
                counts[istack]++;
              	istack = pMap1.get(cstack);         }
        }
   }
} Main
import java.util.*;
 
public class Main{
 
	public static void main(String[] args){
 
		Scanner sc = new Scanner(System.in);
        String ss[] = {sc.next(),sc.next(),sc.next()};
      	int counts[] = {0,0,0};
      	boolean game = true;
      	int istack;
      	char cstack;
      	Map<Character, Integer> pMap1 = new HashMap<Character, Integer>();
		pMap1.put('a',0);
      	pMap1.put('b',1);
      	pMap1.put('c',2);
      	Map<Integer,Character> pMap2 = new HashMap<Integer,Character>();
		pMap2.put(0,'A');
      	pMap2.put(1,'B');
      	pMap2.put(2,'C');
      	
      	cstack = ss[0].charAt(0);
      	counts[0]++;
      	istack = istack = pMap1.get(cstack);
       	while(game){
          	if(counts[istack] == ss[istack].length()) {
              System.out.println(pMap2.get(istack));
              game = false;
            } else{            	              	
              	cstack = ss[istack].charAt(counts[istack]); 
                counts[istack]++;
              	istack = pMap1.get(cstack);         }
        }
   }
}
