import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		boolean t1, t2= false, t3= false;
		String n1 = scn.next();
		String n2 = scn.next();
		String n3 = scn.next();
		t1 = true;
		while (true) {
			if(t1) {
				if(n1.isEmpty()) {
					System.out.println("A");
					break;
				}
				if(n1.charAt(0)=='b') {
					t1 = false;
					t2 = true;
				} else if(n1.charAt(0)=='c') {
					t1 = false;
					t3 = true;
				}
				n1 = n1.substring(1);
			}else if(t2) {
				if(n2.isEmpty()) {
					System.out.println("B");
					break;
				}
				if(n2.charAt(0)=='a') {
					t2 = false;
					t1 = true;
				} else if(n2.charAt(0)=='c') {
					t2 = false;
					t3 = true;
				}
				n2 = n2.substring(1);
			}else if(t3) {
				if(n3.isEmpty()) {
					System.out.println("C");
					break;
				}
				if(n3.charAt(0)=='b') {
					t3 = false;
					t2 = true;
				} else if(n3.charAt(0)=='a') {
					t3 = false;
					t1 = true;
				}
				n3 = n3.substring(1);
			}
		}
		scn.close();
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		boolean t1, t2= false, t3= false;
		String n1 = scn.next();
		String n2 = scn.next();
		String n3 = scn.next();
		t1 = true;
		while (true) {
			if(t1) {
				if(n1.isEmpty()) {
					System.out.println("A");
					break;
				}
				if(n1.charAt(0)=='b') {
					t1 = false;
					t2 = true;
				} else if(n1.charAt(0)=='c') {
					t1 = false;
					t3 = true;
				}
				n1 = n1.substring(1);
			}else if(t2) {
				if(n2.isEmpty()) {
					System.out.println("B");
					break;
				}
				if(n2.charAt(0)=='a') {
					t2 = false;
					t1 = true;
				} else if(n2.charAt(0)=='c') {
					t2 = false;
					t3 = true;
				}
				n2 = n2.substring(1);
			}else if(t3) {
				if(n3.isEmpty()) {
					System.out.println("C");
					break;
				}
				if(n3.charAt(0)=='b') {
					t3 = false;
					t2 = true;
				} else if(n3.charAt(0)=='a') {
					t3 = false;
					t1 = true;
				}
				n3 = n3.substring(1);
			}
		}
		scn.close();
	}
} Main public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		boolean t1, t2= false, t3= false;
		String n1 = scn.next();
		String n2 = scn.next();
		String n3 = scn.next();
		t1 = true;
		while (true) {
			if(t1) {
				if(n1.isEmpty()) {
					System.out.println("A");
					break;
				}
				if(n1.charAt(0)=='b') {
					t1 = false;
					t2 = true;
				} else if(n1.charAt(0)=='c') {
					t1 = false;
					t3 = true;
				}
				n1 = n1.substring(1);
			}else if(t2) {
				if(n2.isEmpty()) {
					System.out.println("B");
					break;
				}
				if(n2.charAt(0)=='a') {
					t2 = false;
					t1 = true;
				} else if(n2.charAt(0)=='c') {
					t2 = false;
					t3 = true;
				}
				n2 = n2.substring(1);
			}else if(t3) {
				if(n3.isEmpty()) {
					System.out.println("C");
					break;
				}
				if(n3.charAt(0)=='b') {
					t3 = false;
					t2 = true;
				} else if(n3.charAt(0)=='a') {
					t3 = false;
					t1 = true;
				}
				n3 = n3.substring(1);
			}
		}
		scn.close();
	} main {
		Scanner scn = new Scanner(System.in);
		boolean t1, t2= false, t3= false;
		String n1 = scn.next();
		String n2 = scn.next();
		String n3 = scn.next();
		t1 = true;
		while (true) {
			if(t1) {
				if(n1.isEmpty()) {
					System.out.println("A");
					break;
				}
				if(n1.charAt(0)=='b') {
					t1 = false;
					t2 = true;
				} else if(n1.charAt(0)=='c') {
					t1 = false;
					t3 = true;
				}
				n1 = n1.substring(1);
			}else if(t2) {
				if(n2.isEmpty()) {
					System.out.println("B");
					break;
				}
				if(n2.charAt(0)=='a') {
					t2 = false;
					t1 = true;
				} else if(n2.charAt(0)=='c') {
					t2 = false;
					t3 = true;
				}
				n2 = n2.substring(1);
			}else if(t3) {
				if(n3.isEmpty()) {
					System.out.println("C");
					break;
				}
				if(n3.charAt(0)=='b') {
					t3 = false;
					t2 = true;
				} else if(n3.charAt(0)=='a') {
					t3 = false;
					t1 = true;
				}
				n3 = n3.substring(1);
			}
		}
		scn.close();
	} Scanner scn = new Scanner(System.in); scn new Scanner(System.in) boolean t1 t1 t2= false t2 false t3= false; t3 false String n1 = scn.next(); n1 scn.next() scn.next scn String n2 = scn.next(); n2 scn.next() scn.next scn String n3 = scn.next(); n3 scn.next() scn.next scn t1 = true t1 true while (true) {
			if(t1) {
				if(n1.isEmpty()) {
					System.out.println("A");
					break;
				}
				if(n1.charAt(0)=='b') {
					t1 = false;
					t2 = true;
				} else if(n1.charAt(0)=='c') {
					t1 = false;
					t3 = true;
				}
				n1 = n1.substring(1);
			}else if(t2) {
				if(n2.isEmpty()) {
					System.out.println("B");
					break;
				}
				if(n2.charAt(0)=='a') {
					t2 = false;
					t1 = true;
				} else if(n2.charAt(0)=='c') {
					t2 = false;
					t3 = true;
				}
				n2 = n2.substring(1);
			}else if(t3) {
				if(n3.isEmpty()) {
					System.out.println("C");
					break;
				}
				if(n3.charAt(0)=='b') {
					t3 = false;
					t2 = true;
				} else if(n3.charAt(0)=='a') {
					t3 = false;
					t1 = true;
				}
				n3 = n3.substring(1);
			}
		} true {
			if(t1) {
				if(n1.isEmpty()) {
					System.out.println("A");
					break;
				}
				if(n1.charAt(0)=='b') {
					t1 = false;
					t2 = true;
				} else if(n1.charAt(0)=='c') {
					t1 = false;
					t3 = true;
				}
				n1 = n1.substring(1);
			}else if(t2) {
				if(n2.isEmpty()) {
					System.out.println("B");
					break;
				}
				if(n2.charAt(0)=='a') {
					t2 = false;
					t1 = true;
				} else if(n2.charAt(0)=='c') {
					t2 = false;
					t3 = true;
				}
				n2 = n2.substring(1);
			}else if(t3) {
				if(n3.isEmpty()) {
					System.out.println("C");
					break;
				}
				if(n3.charAt(0)=='b') {
					t3 = false;
					t2 = true;
				} else if(n3.charAt(0)=='a') {
					t3 = false;
					t1 = true;
				}
				n3 = n3.substring(1);
			}
		} if(t1) {
				if(n1.isEmpty()) {
					System.out.println("A");
					break;
				}
				if(n1.charAt(0)=='b') {
					t1 = false;
					t2 = true;
				} else if(n1.charAt(0)=='c') {
					t1 = false;
					t3 = true;
				}
				n1 = n1.substring(1);
			}else if(t2) {
				if(n2.isEmpty()) {
					System.out.println("B");
					break;
				}
				if(n2.charAt(0)=='a') {
					t2 = false;
					t1 = true;
				} else if(n2.charAt(0)=='c') {
					t2 = false;
					t3 = true;
				}
				n2 = n2.substring(1);
			}else if(t3) {
				if(n3.isEmpty()) {
					System.out.println("C");
					break;
				}
				if(n3.charAt(0)=='b') {
					t3 = false;
					t2 = true;
				} else if(n3.charAt(0)=='a') {
					t3 = false;
					t1 = true;
				}
				n3 = n3.substring(1);
			} t1 {
				if(n1.isEmpty()) {
					System.out.println("A");
					break;
				}
				if(n1.charAt(0)=='b') {
					t1 = false;
					t2 = true;
				} else if(n1.charAt(0)=='c') {
					t1 = false;
					t3 = true;
				}
				n1 = n1.substring(1);
			} if(n1.isEmpty()) {
					System.out.println("A");
					break;
				} n1.isEmpty() n1.isEmpty n1 {
					System.out.println("A");
					break;
				} System.out.println("A") System.out.println System.out System System.out "A" break; if(n1.charAt(0)=='b') {
					t1 = false;
					t2 = true;
				} else if(n1.charAt(0)=='c') {
					t1 = false;
					t3 = true;
				} n1.charAt(0)=='b' n1.charAt(0) n1.charAt n1 0 'b' {
					t1 = false;
					t2 = true;
				} t1 = false t1 false t2 = true t2 true if(n1.charAt(0)=='c') {
					t1 = false;
					t3 = true;
				} n1.charAt(0)=='c' n1.charAt(0) n1.charAt n1 0 'c' {
					t1 = false;
					t3 = true;
				} t1 = false t1 false t3 = true t3 true n1 = n1.substring(1) n1 n1.substring(1) n1.substring n1 1 if(t2) {
				if(n2.isEmpty()) {
					System.out.println("B");
					break;
				}
				if(n2.charAt(0)=='a') {
					t2 = false;
					t1 = true;
				} else if(n2.charAt(0)=='c') {
					t2 = false;
					t3 = true;
				}
				n2 = n2.substring(1);
			}else if(t3) {
				if(n3.isEmpty()) {
					System.out.println("C");
					break;
				}
				if(n3.charAt(0)=='b') {
					t3 = false;
					t2 = true;
				} else if(n3.charAt(0)=='a') {
					t3 = false;
					t1 = true;
				}
				n3 = n3.substring(1);
			} t2 {
				if(n2.isEmpty()) {
					System.out.println("B");
					break;
				}
				if(n2.charAt(0)=='a') {
					t2 = false;
					t1 = true;
				} else if(n2.charAt(0)=='c') {
					t2 = false;
					t3 = true;
				}
				n2 = n2.substring(1);
			} if(n2.isEmpty()) {
					System.out.println("B");
					break;
				} n2.isEmpty() n2.isEmpty n2 {
					System.out.println("B");
					break;
				} System.out.println("B") System.out.println System.out System System.out "B" break; if(n2.charAt(0)=='a') {
					t2 = false;
					t1 = true;
				} else if(n2.charAt(0)=='c') {
					t2 = false;
					t3 = true;
				} n2.charAt(0)=='a' n2.charAt(0) n2.charAt n2 0 'a' {
					t2 = false;
					t1 = true;
				} t2 = false t2 false t1 = true t1 true if(n2.charAt(0)=='c') {
					t2 = false;
					t3 = true;
				} n2.charAt(0)=='c' n2.charAt(0) n2.charAt n2 0 'c' {
					t2 = false;
					t3 = true;
				} t2 = false t2 false t3 = true t3 true n2 = n2.substring(1) n2 n2.substring(1) n2.substring n2 1 if(t3) {
				if(n3.isEmpty()) {
					System.out.println("C");
					break;
				}
				if(n3.charAt(0)=='b') {
					t3 = false;
					t2 = true;
				} else if(n3.charAt(0)=='a') {
					t3 = false;
					t1 = true;
				}
				n3 = n3.substring(1);
			} t3 {
				if(n3.isEmpty()) {
					System.out.println("C");
					break;
				}
				if(n3.charAt(0)=='b') {
					t3 = false;
					t2 = true;
				} else if(n3.charAt(0)=='a') {
					t3 = false;
					t1 = true;
				}
				n3 = n3.substring(1);
			} if(n3.isEmpty()) {
					System.out.println("C");
					break;
				} n3.isEmpty() n3.isEmpty n3 {
					System.out.println("C");
					break;
				} System.out.println("C") System.out.println System.out System System.out "C" break; if(n3.charAt(0)=='b') {
					t3 = false;
					t2 = true;
				} else if(n3.charAt(0)=='a') {
					t3 = false;
					t1 = true;
				} n3.charAt(0)=='b' n3.charAt(0) n3.charAt n3 0 'b' {
					t3 = false;
					t2 = true;
				} t3 = false t3 false t2 = true t2 true if(n3.charAt(0)=='a') {
					t3 = false;
					t1 = true;
				} n3.charAt(0)=='a' n3.charAt(0) n3.charAt n3 0 'a' {
					t3 = false;
					t1 = true;
				} t3 = false t3 false t1 = true t1 true n3 = n3.substring(1) n3 n3.substring(1) n3.substring n3 1 scn.close() scn.close scn String[] args args public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		boolean t1, t2= false, t3= false;
		String n1 = scn.next();
		String n2 = scn.next();
		String n3 = scn.next();
		t1 = true;
		while (true) {
			if(t1) {
				if(n1.isEmpty()) {
					System.out.println("A");
					break;
				}
				if(n1.charAt(0)=='b') {
					t1 = false;
					t2 = true;
				} else if(n1.charAt(0)=='c') {
					t1 = false;
					t3 = true;
				}
				n1 = n1.substring(1);
			}else if(t2) {
				if(n2.isEmpty()) {
					System.out.println("B");
					break;
				}
				if(n2.charAt(0)=='a') {
					t2 = false;
					t1 = true;
				} else if(n2.charAt(0)=='c') {
					t2 = false;
					t3 = true;
				}
				n2 = n2.substring(1);
			}else if(t3) {
				if(n3.isEmpty()) {
					System.out.println("C");
					break;
				}
				if(n3.charAt(0)=='b') {
					t3 = false;
					t2 = true;
				} else if(n3.charAt(0)=='a') {
					t3 = false;
					t1 = true;
				}
				n3 = n3.substring(1);
			}
		}
		scn.close();
	}
} public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		boolean t1, t2= false, t3= false;
		String n1 = scn.next();
		String n2 = scn.next();
		String n3 = scn.next();
		t1 = true;
		while (true) {
			if(t1) {
				if(n1.isEmpty()) {
					System.out.println("A");
					break;
				}
				if(n1.charAt(0)=='b') {
					t1 = false;
					t2 = true;
				} else if(n1.charAt(0)=='c') {
					t1 = false;
					t3 = true;
				}
				n1 = n1.substring(1);
			}else if(t2) {
				if(n2.isEmpty()) {
					System.out.println("B");
					break;
				}
				if(n2.charAt(0)=='a') {
					t2 = false;
					t1 = true;
				} else if(n2.charAt(0)=='c') {
					t2 = false;
					t3 = true;
				}
				n2 = n2.substring(1);
			}else if(t3) {
				if(n3.isEmpty()) {
					System.out.println("C");
					break;
				}
				if(n3.charAt(0)=='b') {
					t3 = false;
					t2 = true;
				} else if(n3.charAt(0)=='a') {
					t3 = false;
					t1 = true;
				}
				n3 = n3.substring(1);
			}
		}
		scn.close();
	}
} Main
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		boolean t1, t2= false, t3= false;
		String n1 = scn.next();
		String n2 = scn.next();
		String n3 = scn.next();
		t1 = true;
		while (true) {
			if(t1) {
				if(n1.isEmpty()) {
					System.out.println("A");
					break;
				}
				if(n1.charAt(0)=='b') {
					t1 = false;
					t2 = true;
				} else if(n1.charAt(0)=='c') {
					t1 = false;
					t3 = true;
				}
				n1 = n1.substring(1);
			}else if(t2) {
				if(n2.isEmpty()) {
					System.out.println("B");
					break;
				}
				if(n2.charAt(0)=='a') {
					t2 = false;
					t1 = true;
				} else if(n2.charAt(0)=='c') {
					t2 = false;
					t3 = true;
				}
				n2 = n2.substring(1);
			}else if(t3) {
				if(n3.isEmpty()) {
					System.out.println("C");
					break;
				}
				if(n3.charAt(0)=='b') {
					t3 = false;
					t2 = true;
				} else if(n3.charAt(0)=='a') {
					t3 = false;
					t1 = true;
				}
				n3 = n3.substring(1);
			}
		}
		scn.close();
	}
}