import java.util.Scanner;

public class Main {
	public static void main(String[] args)  {
		Scanner sc = new Scanner(System.in);
		String[] str = new String[3];
		str[0] = sc.nextLine();
		str[1] = sc.nextLine();
		str[2] = sc.nextLine();
		boolean f = true;
		int i = 0;
		while(f) {
			if(str[i].substring(0,1).equals("a")){
				str[i] = str[i].substring(1,str[i].length());
				i = 0;
			}else if(str[i].substring(0,1).equals("b")){
				str[i] = str[i].substring(1,str[i].length());
				i = 1;
			}else if(str[i].substring(0,1).equals("c")){
				str[i] = str[i].substring(1,str[i].length());
				i = 2;
			}
			if(str[i].equals("")){
				if(i == 0) {
					System.out.println("A");
					return;
				}else if(i == 1) {
					System.out.println("B");
					return;
				}else if(i == 2) {
					System.out.println("C");
					return;
				}
			}
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args)  {
		Scanner sc = new Scanner(System.in);
		String[] str = new String[3];
		str[0] = sc.nextLine();
		str[1] = sc.nextLine();
		str[2] = sc.nextLine();
		boolean f = true;
		int i = 0;
		while(f) {
			if(str[i].substring(0,1).equals("a")){
				str[i] = str[i].substring(1,str[i].length());
				i = 0;
			}else if(str[i].substring(0,1).equals("b")){
				str[i] = str[i].substring(1,str[i].length());
				i = 1;
			}else if(str[i].substring(0,1).equals("c")){
				str[i] = str[i].substring(1,str[i].length());
				i = 2;
			}
			if(str[i].equals("")){
				if(i == 0) {
					System.out.println("A");
					return;
				}else if(i == 1) {
					System.out.println("B");
					return;
				}else if(i == 2) {
					System.out.println("C");
					return;
				}
			}
		}
	}
} Main public static void main(String[] args)  {
		Scanner sc = new Scanner(System.in);
		String[] str = new String[3];
		str[0] = sc.nextLine();
		str[1] = sc.nextLine();
		str[2] = sc.nextLine();
		boolean f = true;
		int i = 0;
		while(f) {
			if(str[i].substring(0,1).equals("a")){
				str[i] = str[i].substring(1,str[i].length());
				i = 0;
			}else if(str[i].substring(0,1).equals("b")){
				str[i] = str[i].substring(1,str[i].length());
				i = 1;
			}else if(str[i].substring(0,1).equals("c")){
				str[i] = str[i].substring(1,str[i].length());
				i = 2;
			}
			if(str[i].equals("")){
				if(i == 0) {
					System.out.println("A");
					return;
				}else if(i == 1) {
					System.out.println("B");
					return;
				}else if(i == 2) {
					System.out.println("C");
					return;
				}
			}
		}
	} main {
		Scanner sc = new Scanner(System.in);
		String[] str = new String[3];
		str[0] = sc.nextLine();
		str[1] = sc.nextLine();
		str[2] = sc.nextLine();
		boolean f = true;
		int i = 0;
		while(f) {
			if(str[i].substring(0,1).equals("a")){
				str[i] = str[i].substring(1,str[i].length());
				i = 0;
			}else if(str[i].substring(0,1).equals("b")){
				str[i] = str[i].substring(1,str[i].length());
				i = 1;
			}else if(str[i].substring(0,1).equals("c")){
				str[i] = str[i].substring(1,str[i].length());
				i = 2;
			}
			if(str[i].equals("")){
				if(i == 0) {
					System.out.println("A");
					return;
				}else if(i == 1) {
					System.out.println("B");
					return;
				}else if(i == 2) {
					System.out.println("C");
					return;
				}
			}
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String[] str = new String[3]; str new String[3] 3 str[0] = sc.nextLine() str[0] str 0 sc.nextLine() sc.nextLine sc str[1] = sc.nextLine() str[1] str 1 sc.nextLine() sc.nextLine sc str[2] = sc.nextLine() str[2] str 2 sc.nextLine() sc.nextLine sc boolean f = true; f true int i = 0; i 0 while(f) {
			if(str[i].substring(0,1).equals("a")){
				str[i] = str[i].substring(1,str[i].length());
				i = 0;
			}else if(str[i].substring(0,1).equals("b")){
				str[i] = str[i].substring(1,str[i].length());
				i = 1;
			}else if(str[i].substring(0,1).equals("c")){
				str[i] = str[i].substring(1,str[i].length());
				i = 2;
			}
			if(str[i].equals("")){
				if(i == 0) {
					System.out.println("A");
					return;
				}else if(i == 1) {
					System.out.println("B");
					return;
				}else if(i == 2) {
					System.out.println("C");
					return;
				}
			}
		} f {
			if(str[i].substring(0,1).equals("a")){
				str[i] = str[i].substring(1,str[i].length());
				i = 0;
			}else if(str[i].substring(0,1).equals("b")){
				str[i] = str[i].substring(1,str[i].length());
				i = 1;
			}else if(str[i].substring(0,1).equals("c")){
				str[i] = str[i].substring(1,str[i].length());
				i = 2;
			}
			if(str[i].equals("")){
				if(i == 0) {
					System.out.println("A");
					return;
				}else if(i == 1) {
					System.out.println("B");
					return;
				}else if(i == 2) {
					System.out.println("C");
					return;
				}
			}
		} if(str[i].substring(0,1).equals("a")){
				str[i] = str[i].substring(1,str[i].length());
				i = 0;
			}else if(str[i].substring(0,1).equals("b")){
				str[i] = str[i].substring(1,str[i].length());
				i = 1;
			}else if(str[i].substring(0,1).equals("c")){
				str[i] = str[i].substring(1,str[i].length());
				i = 2;
			} str[i].substring(0,1).equals("a") str[i].substring(0,1).equals str[i].substring(0,1) str[i].substring str[i] str i 0 1 "a" {
				str[i] = str[i].substring(1,str[i].length());
				i = 0;
			} str[i] = str[i].substring(1,str[i].length()) str[i] str i str[i].substring(1,str[i].length()) str[i].substring str[i] str i 1 str[i].length() str[i].length str[i] str i i = 0 i 0 if(str[i].substring(0,1).equals("b")){
				str[i] = str[i].substring(1,str[i].length());
				i = 1;
			}else if(str[i].substring(0,1).equals("c")){
				str[i] = str[i].substring(1,str[i].length());
				i = 2;
			} str[i].substring(0,1).equals("b") str[i].substring(0,1).equals str[i].substring(0,1) str[i].substring str[i] str i 0 1 "b" {
				str[i] = str[i].substring(1,str[i].length());
				i = 1;
			} str[i] = str[i].substring(1,str[i].length()) str[i] str i str[i].substring(1,str[i].length()) str[i].substring str[i] str i 1 str[i].length() str[i].length str[i] str i i = 1 i 1 if(str[i].substring(0,1).equals("c")){
				str[i] = str[i].substring(1,str[i].length());
				i = 2;
			} str[i].substring(0,1).equals("c") str[i].substring(0,1).equals str[i].substring(0,1) str[i].substring str[i] str i 0 1 "c" {
				str[i] = str[i].substring(1,str[i].length());
				i = 2;
			} str[i] = str[i].substring(1,str[i].length()) str[i] str i str[i].substring(1,str[i].length()) str[i].substring str[i] str i 1 str[i].length() str[i].length str[i] str i i = 2 i 2 if(str[i].equals("")){
				if(i == 0) {
					System.out.println("A");
					return;
				}else if(i == 1) {
					System.out.println("B");
					return;
				}else if(i == 2) {
					System.out.println("C");
					return;
				}
			} str[i].equals("") str[i].equals str[i] str i "" {
				if(i == 0) {
					System.out.println("A");
					return;
				}else if(i == 1) {
					System.out.println("B");
					return;
				}else if(i == 2) {
					System.out.println("C");
					return;
				}
			} if(i == 0) {
					System.out.println("A");
					return;
				}else if(i == 1) {
					System.out.println("B");
					return;
				}else if(i == 2) {
					System.out.println("C");
					return;
				} i == 0 i 0 {
					System.out.println("A");
					return;
				} System.out.println("A") System.out.println System.out System System.out "A" return; if(i == 1) {
					System.out.println("B");
					return;
				}else if(i == 2) {
					System.out.println("C");
					return;
				} i == 1 i 1 {
					System.out.println("B");
					return;
				} System.out.println("B") System.out.println System.out System System.out "B" return; if(i == 2) {
					System.out.println("C");
					return;
				} i == 2 i 2 {
					System.out.println("C");
					return;
				} System.out.println("C") System.out.println System.out System System.out "C" return; String[] args args public class Main {
	public static void main(String[] args)  {
		Scanner sc = new Scanner(System.in);
		String[] str = new String[3];
		str[0] = sc.nextLine();
		str[1] = sc.nextLine();
		str[2] = sc.nextLine();
		boolean f = true;
		int i = 0;
		while(f) {
			if(str[i].substring(0,1).equals("a")){
				str[i] = str[i].substring(1,str[i].length());
				i = 0;
			}else if(str[i].substring(0,1).equals("b")){
				str[i] = str[i].substring(1,str[i].length());
				i = 1;
			}else if(str[i].substring(0,1).equals("c")){
				str[i] = str[i].substring(1,str[i].length());
				i = 2;
			}
			if(str[i].equals("")){
				if(i == 0) {
					System.out.println("A");
					return;
				}else if(i == 1) {
					System.out.println("B");
					return;
				}else if(i == 2) {
					System.out.println("C");
					return;
				}
			}
		}
	}
} public class Main {
	public static void main(String[] args)  {
		Scanner sc = new Scanner(System.in);
		String[] str = new String[3];
		str[0] = sc.nextLine();
		str[1] = sc.nextLine();
		str[2] = sc.nextLine();
		boolean f = true;
		int i = 0;
		while(f) {
			if(str[i].substring(0,1).equals("a")){
				str[i] = str[i].substring(1,str[i].length());
				i = 0;
			}else if(str[i].substring(0,1).equals("b")){
				str[i] = str[i].substring(1,str[i].length());
				i = 1;
			}else if(str[i].substring(0,1).equals("c")){
				str[i] = str[i].substring(1,str[i].length());
				i = 2;
			}
			if(str[i].equals("")){
				if(i == 0) {
					System.out.println("A");
					return;
				}else if(i == 1) {
					System.out.println("B");
					return;
				}else if(i == 2) {
					System.out.println("C");
					return;
				}
			}
		}
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args)  {
		Scanner sc = new Scanner(System.in);
		String[] str = new String[3];
		str[0] = sc.nextLine();
		str[1] = sc.nextLine();
		str[2] = sc.nextLine();
		boolean f = true;
		int i = 0;
		while(f) {
			if(str[i].substring(0,1).equals("a")){
				str[i] = str[i].substring(1,str[i].length());
				i = 0;
			}else if(str[i].substring(0,1).equals("b")){
				str[i] = str[i].substring(1,str[i].length());
				i = 1;
			}else if(str[i].substring(0,1).equals("c")){
				str[i] = str[i].substring(1,str[i].length());
				i = 2;
			}
			if(str[i].equals("")){
				if(i == 0) {
					System.out.println("A");
					return;
				}else if(i == 1) {
					System.out.println("B");
					return;
				}else if(i == 2) {
					System.out.println("C");
					return;
				}
			}
		}
	}
}