import java.util.*;

class Main{
public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();
    char x = 'a';
    for(int i = 0; i < 300; i++) {
    	if(x == 'a') {
    		if(a.length() == 0) {
    			System.out.println("A");
    			break;
    		} else {
    			x = a.charAt(0);
    			a = a.substring(1);
    		}
    	}
    	if(x == 'b') {
    		if(b.length() == 0) {
    			System.out.println("B");
    			break;
    		} else {
    			x = b.charAt(0);
    			b = b.substring(1);
    		}
    	}
    	if(x == 'c') {
    		if(c.length() == 0) {
    			System.out.println("C");
    			break;
    		} else {
    			x = c.charAt(0);
    			c = c.substring(1);
    		}		
    	}        					
    }
}
} import java.util.*; util.* java class Main{
public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();
    char x = 'a';
    for(int i = 0; i < 300; i++) {
    	if(x == 'a') {
    		if(a.length() == 0) {
    			System.out.println("A");
    			break;
    		} else {
    			x = a.charAt(0);
    			a = a.substring(1);
    		}
    	}
    	if(x == 'b') {
    		if(b.length() == 0) {
    			System.out.println("B");
    			break;
    		} else {
    			x = b.charAt(0);
    			b = b.substring(1);
    		}
    	}
    	if(x == 'c') {
    		if(c.length() == 0) {
    			System.out.println("C");
    			break;
    		} else {
    			x = c.charAt(0);
    			c = c.substring(1);
    		}		
    	}        					
    }
}
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();
    char x = 'a';
    for(int i = 0; i < 300; i++) {
    	if(x == 'a') {
    		if(a.length() == 0) {
    			System.out.println("A");
    			break;
    		} else {
    			x = a.charAt(0);
    			a = a.substring(1);
    		}
    	}
    	if(x == 'b') {
    		if(b.length() == 0) {
    			System.out.println("B");
    			break;
    		} else {
    			x = b.charAt(0);
    			b = b.substring(1);
    		}
    	}
    	if(x == 'c') {
    		if(c.length() == 0) {
    			System.out.println("C");
    			break;
    		} else {
    			x = c.charAt(0);
    			c = c.substring(1);
    		}		
    	}        					
    }
} main {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();
    char x = 'a';
    for(int i = 0; i < 300; i++) {
    	if(x == 'a') {
    		if(a.length() == 0) {
    			System.out.println("A");
    			break;
    		} else {
    			x = a.charAt(0);
    			a = a.substring(1);
    		}
    	}
    	if(x == 'b') {
    		if(b.length() == 0) {
    			System.out.println("B");
    			break;
    		} else {
    			x = b.charAt(0);
    			b = b.substring(1);
    		}
    	}
    	if(x == 'c') {
    		if(c.length() == 0) {
    			System.out.println("C");
    			break;
    		} else {
    			x = c.charAt(0);
    			c = c.substring(1);
    		}		
    	}        					
    }
} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String a = sc.next(); a sc.next() sc.next sc String b = sc.next(); b sc.next() sc.next sc String c = sc.next(); c sc.next() sc.next sc char x = 'a'; x 'a' for(int i = 0; i < 300; i++) {
    	if(x == 'a') {
    		if(a.length() == 0) {
    			System.out.println("A");
    			break;
    		} else {
    			x = a.charAt(0);
    			a = a.substring(1);
    		}
    	}
    	if(x == 'b') {
    		if(b.length() == 0) {
    			System.out.println("B");
    			break;
    		} else {
    			x = b.charAt(0);
    			b = b.substring(1);
    		}
    	}
    	if(x == 'c') {
    		if(c.length() == 0) {
    			System.out.println("C");
    			break;
    		} else {
    			x = c.charAt(0);
    			c = c.substring(1);
    		}		
    	}        					
    } int i = 0; int i = 0; i 0 i < 300 i 300 i++ i++ i {
    	if(x == 'a') {
    		if(a.length() == 0) {
    			System.out.println("A");
    			break;
    		} else {
    			x = a.charAt(0);
    			a = a.substring(1);
    		}
    	}
    	if(x == 'b') {
    		if(b.length() == 0) {
    			System.out.println("B");
    			break;
    		} else {
    			x = b.charAt(0);
    			b = b.substring(1);
    		}
    	}
    	if(x == 'c') {
    		if(c.length() == 0) {
    			System.out.println("C");
    			break;
    		} else {
    			x = c.charAt(0);
    			c = c.substring(1);
    		}		
    	}        					
    } {
    	if(x == 'a') {
    		if(a.length() == 0) {
    			System.out.println("A");
    			break;
    		} else {
    			x = a.charAt(0);
    			a = a.substring(1);
    		}
    	}
    	if(x == 'b') {
    		if(b.length() == 0) {
    			System.out.println("B");
    			break;
    		} else {
    			x = b.charAt(0);
    			b = b.substring(1);
    		}
    	}
    	if(x == 'c') {
    		if(c.length() == 0) {
    			System.out.println("C");
    			break;
    		} else {
    			x = c.charAt(0);
    			c = c.substring(1);
    		}		
    	}        					
    } if(x == 'a') {
    		if(a.length() == 0) {
    			System.out.println("A");
    			break;
    		} else {
    			x = a.charAt(0);
    			a = a.substring(1);
    		}
    	} x == 'a' x 'a' {
    		if(a.length() == 0) {
    			System.out.println("A");
    			break;
    		} else {
    			x = a.charAt(0);
    			a = a.substring(1);
    		}
    	} if(a.length() == 0) {
    			System.out.println("A");
    			break;
    		} else {
    			x = a.charAt(0);
    			a = a.substring(1);
    		} a.length() == 0 a.length() a.length a 0 {
    			System.out.println("A");
    			break;
    		} System.out.println("A") System.out.println System.out System System.out "A" break; {
    			x = a.charAt(0);
    			a = a.substring(1);
    		} x = a.charAt(0) x a.charAt(0) a.charAt a 0 a = a.substring(1) a a.substring(1) a.substring a 1 if(x == 'b') {
    		if(b.length() == 0) {
    			System.out.println("B");
    			break;
    		} else {
    			x = b.charAt(0);
    			b = b.substring(1);
    		}
    	} x == 'b' x 'b' {
    		if(b.length() == 0) {
    			System.out.println("B");
    			break;
    		} else {
    			x = b.charAt(0);
    			b = b.substring(1);
    		}
    	} if(b.length() == 0) {
    			System.out.println("B");
    			break;
    		} else {
    			x = b.charAt(0);
    			b = b.substring(1);
    		} b.length() == 0 b.length() b.length b 0 {
    			System.out.println("B");
    			break;
    		} System.out.println("B") System.out.println System.out System System.out "B" break; {
    			x = b.charAt(0);
    			b = b.substring(1);
    		} x = b.charAt(0) x b.charAt(0) b.charAt b 0 b = b.substring(1) b b.substring(1) b.substring b 1 if(x == 'c') {
    		if(c.length() == 0) {
    			System.out.println("C");
    			break;
    		} else {
    			x = c.charAt(0);
    			c = c.substring(1);
    		}		
    	} x == 'c' x 'c' {
    		if(c.length() == 0) {
    			System.out.println("C");
    			break;
    		} else {
    			x = c.charAt(0);
    			c = c.substring(1);
    		}		
    	} if(c.length() == 0) {
    			System.out.println("C");
    			break;
    		} else {
    			x = c.charAt(0);
    			c = c.substring(1);
    		} c.length() == 0 c.length() c.length c 0 {
    			System.out.println("C");
    			break;
    		} System.out.println("C") System.out.println System.out System System.out "C" break; {
    			x = c.charAt(0);
    			c = c.substring(1);
    		} x = c.charAt(0) x c.charAt(0) c.charAt c 0 c = c.substring(1) c c.substring(1) c.substring c 1 String[] args args
import java.util.*;

class Main{
public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();
    char x = 'a';
    for(int i = 0; i < 300; i++) {
    	if(x == 'a') {
    		if(a.length() == 0) {
    			System.out.println("A");
    			break;
    		} else {
    			x = a.charAt(0);
    			a = a.substring(1);
    		}
    	}
    	if(x == 'b') {
    		if(b.length() == 0) {
    			System.out.println("B");
    			break;
    		} else {
    			x = b.charAt(0);
    			b = b.substring(1);
    		}
    	}
    	if(x == 'c') {
    		if(c.length() == 0) {
    			System.out.println("C");
    			break;
    		} else {
    			x = c.charAt(0);
    			c = c.substring(1);
    		}		
    	}        					
    }
}
}
