import java.util.*;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	String SA = sc.next();
	String SB = sc.next();
	String SC = sc.next();
	int i = 0,j = 0,k = 0;
	String ans = "";
	char tmp = SA.charAt(i);
	i++;
	boolean f = true;
	while(f){
	    // System.out.println(tmp);
	    if ( tmp == 'a' ) {
		if ( i == SA.length() ) {
		    ans = "A";
		    break;
		}				
		tmp = SA.charAt(i);
		i++;

		//	System.out.println("111111");
	    } else if (tmp == 'b') {
		if ( j == SB.length() ) {
		    ans = "B";
		    break;
		}						
		tmp = SB.charAt(j);
		j++;
		//		System.out.println("222222");		
	    } else if (tmp == 'c') {
		if ( k == SC.length() ) {
		    ans = "C";
		    break;
		}						
		tmp = SC.charAt(k);
		k++;
		//		System.out.println("333333");		
	    }
	    
	}
	System.out.println(ans);
    }
} import java.util.*; util.* java public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	String SA = sc.next();
	String SB = sc.next();
	String SC = sc.next();
	int i = 0,j = 0,k = 0;
	String ans = "";
	char tmp = SA.charAt(i);
	i++;
	boolean f = true;
	while(f){
	    // System.out.println(tmp);
	    if ( tmp == 'a' ) {
		if ( i == SA.length() ) {
		    ans = "A";
		    break;
		}				
		tmp = SA.charAt(i);
		i++;

		//	System.out.println("111111");
	    } else if (tmp == 'b') {
		if ( j == SB.length() ) {
		    ans = "B";
		    break;
		}						
		tmp = SB.charAt(j);
		j++;
		//		System.out.println("222222");		
	    } else if (tmp == 'c') {
		if ( k == SC.length() ) {
		    ans = "C";
		    break;
		}						
		tmp = SC.charAt(k);
		k++;
		//		System.out.println("333333");		
	    }
	    
	}
	System.out.println(ans);
    }
} Main public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	String SA = sc.next();
	String SB = sc.next();
	String SC = sc.next();
	int i = 0,j = 0,k = 0;
	String ans = "";
	char tmp = SA.charAt(i);
	i++;
	boolean f = true;
	while(f){
	    // System.out.println(tmp);
	    if ( tmp == 'a' ) {
		if ( i == SA.length() ) {
		    ans = "A";
		    break;
		}				
		tmp = SA.charAt(i);
		i++;

		//	System.out.println("111111");
	    } else if (tmp == 'b') {
		if ( j == SB.length() ) {
		    ans = "B";
		    break;
		}						
		tmp = SB.charAt(j);
		j++;
		//		System.out.println("222222");		
	    } else if (tmp == 'c') {
		if ( k == SC.length() ) {
		    ans = "C";
		    break;
		}						
		tmp = SC.charAt(k);
		k++;
		//		System.out.println("333333");		
	    }
	    
	}
	System.out.println(ans);
    } main {
	Scanner sc = new Scanner(System.in);
	String SA = sc.next();
	String SB = sc.next();
	String SC = sc.next();
	int i = 0,j = 0,k = 0;
	String ans = "";
	char tmp = SA.charAt(i);
	i++;
	boolean f = true;
	while(f){
	    // System.out.println(tmp);
	    if ( tmp == 'a' ) {
		if ( i == SA.length() ) {
		    ans = "A";
		    break;
		}				
		tmp = SA.charAt(i);
		i++;

		//	System.out.println("111111");
	    } else if (tmp == 'b') {
		if ( j == SB.length() ) {
		    ans = "B";
		    break;
		}						
		tmp = SB.charAt(j);
		j++;
		//		System.out.println("222222");		
	    } else if (tmp == 'c') {
		if ( k == SC.length() ) {
		    ans = "C";
		    break;
		}						
		tmp = SC.charAt(k);
		k++;
		//		System.out.println("333333");		
	    }
	    
	}
	System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String SA = sc.next(); SA sc.next() sc.next sc String SB = sc.next(); SB sc.next() sc.next sc String SC = sc.next(); SC sc.next() sc.next sc int i = 0 i 0 j = 0 j 0 k = 0; k 0 String ans = ""; ans "" char tmp = SA.charAt(i); tmp SA.charAt(i) SA.charAt SA i i++ i boolean f = true; f true while(f){
	    // System.out.println(tmp);
	    if ( tmp == 'a' ) {
		if ( i == SA.length() ) {
		    ans = "A";
		    break;
		}				
		tmp = SA.charAt(i);
		i++;

		//	System.out.println("111111");
	    } else if (tmp == 'b') {
		if ( j == SB.length() ) {
		    ans = "B";
		    break;
		}						
		tmp = SB.charAt(j);
		j++;
		//		System.out.println("222222");		
	    } else if (tmp == 'c') {
		if ( k == SC.length() ) {
		    ans = "C";
		    break;
		}						
		tmp = SC.charAt(k);
		k++;
		//		System.out.println("333333");		
	    }
	    
	} f {
	    // System.out.println(tmp);
	    if ( tmp == 'a' ) {
		if ( i == SA.length() ) {
		    ans = "A";
		    break;
		}				
		tmp = SA.charAt(i);
		i++;

		//	System.out.println("111111");
	    } else if (tmp == 'b') {
		if ( j == SB.length() ) {
		    ans = "B";
		    break;
		}						
		tmp = SB.charAt(j);
		j++;
		//		System.out.println("222222");		
	    } else if (tmp == 'c') {
		if ( k == SC.length() ) {
		    ans = "C";
		    break;
		}						
		tmp = SC.charAt(k);
		k++;
		//		System.out.println("333333");		
	    }
	    
	} if ( tmp == 'a' ) {
		if ( i == SA.length() ) {
		    ans = "A";
		    break;
		}				
		tmp = SA.charAt(i);
		i++;

		//	System.out.println("111111");
	    } else if (tmp == 'b') {
		if ( j == SB.length() ) {
		    ans = "B";
		    break;
		}						
		tmp = SB.charAt(j);
		j++;
		//		System.out.println("222222");		
	    } else if (tmp == 'c') {
		if ( k == SC.length() ) {
		    ans = "C";
		    break;
		}						
		tmp = SC.charAt(k);
		k++;
		//		System.out.println("333333");		
	    } tmp == 'a' tmp 'a' {
		if ( i == SA.length() ) {
		    ans = "A";
		    break;
		}				
		tmp = SA.charAt(i);
		i++;

		//	System.out.println("111111");
	    } if ( i == SA.length() ) {
		    ans = "A";
		    break;
		} i == SA.length() i SA.length() SA.length SA {
		    ans = "A";
		    break;
		} ans = "A" ans "A" break; tmp = SA.charAt(i) tmp SA.charAt(i) SA.charAt SA i i++ i if (tmp == 'b') {
		if ( j == SB.length() ) {
		    ans = "B";
		    break;
		}						
		tmp = SB.charAt(j);
		j++;
		//		System.out.println("222222");		
	    } else if (tmp == 'c') {
		if ( k == SC.length() ) {
		    ans = "C";
		    break;
		}						
		tmp = SC.charAt(k);
		k++;
		//		System.out.println("333333");		
	    } tmp == 'b' tmp 'b' {
		if ( j == SB.length() ) {
		    ans = "B";
		    break;
		}						
		tmp = SB.charAt(j);
		j++;
		//		System.out.println("222222");		
	    } if ( j == SB.length() ) {
		    ans = "B";
		    break;
		} j == SB.length() j SB.length() SB.length SB {
		    ans = "B";
		    break;
		} ans = "B" ans "B" break; tmp = SB.charAt(j) tmp SB.charAt(j) SB.charAt SB j j++ j if (tmp == 'c') {
		if ( k == SC.length() ) {
		    ans = "C";
		    break;
		}						
		tmp = SC.charAt(k);
		k++;
		//		System.out.println("333333");		
	    } tmp == 'c' tmp 'c' {
		if ( k == SC.length() ) {
		    ans = "C";
		    break;
		}						
		tmp = SC.charAt(k);
		k++;
		//		System.out.println("333333");		
	    } if ( k == SC.length() ) {
		    ans = "C";
		    break;
		} k == SC.length() k SC.length() SC.length SC {
		    ans = "C";
		    break;
		} ans = "C" ans "C" break; tmp = SC.charAt(k) tmp SC.charAt(k) SC.charAt SC k k++ k System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	String SA = sc.next();
	String SB = sc.next();
	String SC = sc.next();
	int i = 0,j = 0,k = 0;
	String ans = "";
	char tmp = SA.charAt(i);
	i++;
	boolean f = true;
	while(f){
	    // System.out.println(tmp);
	    if ( tmp == 'a' ) {
		if ( i == SA.length() ) {
		    ans = "A";
		    break;
		}				
		tmp = SA.charAt(i);
		i++;

		//	System.out.println("111111");
	    } else if (tmp == 'b') {
		if ( j == SB.length() ) {
		    ans = "B";
		    break;
		}						
		tmp = SB.charAt(j);
		j++;
		//		System.out.println("222222");		
	    } else if (tmp == 'c') {
		if ( k == SC.length() ) {
		    ans = "C";
		    break;
		}						
		tmp = SC.charAt(k);
		k++;
		//		System.out.println("333333");		
	    }
	    
	}
	System.out.println(ans);
    }
} public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	String SA = sc.next();
	String SB = sc.next();
	String SC = sc.next();
	int i = 0,j = 0,k = 0;
	String ans = "";
	char tmp = SA.charAt(i);
	i++;
	boolean f = true;
	while(f){
	    // System.out.println(tmp);
	    if ( tmp == 'a' ) {
		if ( i == SA.length() ) {
		    ans = "A";
		    break;
		}				
		tmp = SA.charAt(i);
		i++;

		//	System.out.println("111111");
	    } else if (tmp == 'b') {
		if ( j == SB.length() ) {
		    ans = "B";
		    break;
		}						
		tmp = SB.charAt(j);
		j++;
		//		System.out.println("222222");		
	    } else if (tmp == 'c') {
		if ( k == SC.length() ) {
		    ans = "C";
		    break;
		}						
		tmp = SC.charAt(k);
		k++;
		//		System.out.println("333333");		
	    }
	    
	}
	System.out.println(ans);
    }
} Main
import java.util.*;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	String SA = sc.next();
	String SB = sc.next();
	String SC = sc.next();
	int i = 0,j = 0,k = 0;
	String ans = "";
	char tmp = SA.charAt(i);
	i++;
	boolean f = true;
	while(f){
	    // System.out.println(tmp);
	    if ( tmp == 'a' ) {
		if ( i == SA.length() ) {
		    ans = "A";
		    break;
		}				
		tmp = SA.charAt(i);
		i++;

		//	System.out.println("111111");
	    } else if (tmp == 'b') {
		if ( j == SB.length() ) {
		    ans = "B";
		    break;
		}						
		tmp = SB.charAt(j);
		j++;
		//		System.out.println("222222");		
	    } else if (tmp == 'c') {
		if ( k == SC.length() ) {
		    ans = "C";
		    break;
		}						
		tmp = SC.charAt(k);
		k++;
		//		System.out.println("333333");		
	    }
	    
	}
	System.out.println(ans);
    }
}
