import java.util.Scanner;

public class Main {
	static int ans;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S1 = sc.next();
		String S2 = sc.next();
		String S3 = sc.next();
		sc.close();
		char c = S1.charAt(0);
		solve(S1.substring(1, S1.length()), S2, S3, c);
		if(ans == 1) System.out.println("A");
		else if(ans == 2) System.out.println("B");
		else System.out.println("C");
	}
	static void solve(String S1, String S2, String S3, char n) {
		//System.out.println(S1 + " " + S2 + " " + S3 + " " + n);
		if(n == 'a') {
			if(S1.length() == 0) {ans = 1; return;}
			char c = S1.charAt(0);
			solve(S1.substring(1, S1.length()), S2, S3, c);
		}else if(n == 'b') {
			if(S2.length() == 0) {ans = 2; return;}
			char c = S2.charAt(0);
			solve(S1, S2.substring(1, S2.length()), S3, c);
		}else if(n == 'c') {
			if(S3.length() == 0) {ans = 3; return;}
			char c = S3.charAt(0);
			solve(S1, S2, S3.substring(1, S3.length()), c);
		}

	}
} import java.util.Scanner; Scanner java.util public class Main {
	static int ans;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S1 = sc.next();
		String S2 = sc.next();
		String S3 = sc.next();
		sc.close();
		char c = S1.charAt(0);
		solve(S1.substring(1, S1.length()), S2, S3, c);
		if(ans == 1) System.out.println("A");
		else if(ans == 2) System.out.println("B");
		else System.out.println("C");
	}
	static void solve(String S1, String S2, String S3, char n) {
		//System.out.println(S1 + " " + S2 + " " + S3 + " " + n);
		if(n == 'a') {
			if(S1.length() == 0) {ans = 1; return;}
			char c = S1.charAt(0);
			solve(S1.substring(1, S1.length()), S2, S3, c);
		}else if(n == 'b') {
			if(S2.length() == 0) {ans = 2; return;}
			char c = S2.charAt(0);
			solve(S1, S2.substring(1, S2.length()), S3, c);
		}else if(n == 'c') {
			if(S3.length() == 0) {ans = 3; return;}
			char c = S3.charAt(0);
			solve(S1, S2, S3.substring(1, S3.length()), c);
		}

	}
} Main static int ans; ans public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S1 = sc.next();
		String S2 = sc.next();
		String S3 = sc.next();
		sc.close();
		char c = S1.charAt(0);
		solve(S1.substring(1, S1.length()), S2, S3, c);
		if(ans == 1) System.out.println("A");
		else if(ans == 2) System.out.println("B");
		else System.out.println("C");
	} main {
		Scanner sc = new Scanner(System.in);
		String S1 = sc.next();
		String S2 = sc.next();
		String S3 = sc.next();
		sc.close();
		char c = S1.charAt(0);
		solve(S1.substring(1, S1.length()), S2, S3, c);
		if(ans == 1) System.out.println("A");
		else if(ans == 2) System.out.println("B");
		else System.out.println("C");
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String S1 = sc.next(); S1 sc.next() sc.next sc String S2 = sc.next(); S2 sc.next() sc.next sc String S3 = sc.next(); S3 sc.next() sc.next sc sc.close() sc.close sc char c = S1.charAt(0); c S1.charAt(0) S1.charAt S1 0 solve(S1.substring(1, S1.length()), S2, S3, c) solve S1.substring(1, S1.length()) S1.substring S1 1 S1.length() S1.length S1 S2 S3 c if(ans == 1) System.out.println("A");
		else if(ans == 2) System.out.println("B");
		else System.out.println("C"); ans == 1 ans 1 System.out.println("A") System.out.println System.out System System.out "A" if(ans == 2) System.out.println("B");
		else System.out.println("C"); ans == 2 ans 2 System.out.println("B") System.out.println System.out System System.out "B" System.out.println("C") System.out.println System.out System System.out "C" String[] args args static void solve(String S1, String S2, String S3, char n) {
		//System.out.println(S1 + " " + S2 + " " + S3 + " " + n);
		if(n == 'a') {
			if(S1.length() == 0) {ans = 1; return;}
			char c = S1.charAt(0);
			solve(S1.substring(1, S1.length()), S2, S3, c);
		}else if(n == 'b') {
			if(S2.length() == 0) {ans = 2; return;}
			char c = S2.charAt(0);
			solve(S1, S2.substring(1, S2.length()), S3, c);
		}else if(n == 'c') {
			if(S3.length() == 0) {ans = 3; return;}
			char c = S3.charAt(0);
			solve(S1, S2, S3.substring(1, S3.length()), c);
		}

	} solve {
		//System.out.println(S1 + " " + S2 + " " + S3 + " " + n);
		if(n == 'a') {
			if(S1.length() == 0) {ans = 1; return;}
			char c = S1.charAt(0);
			solve(S1.substring(1, S1.length()), S2, S3, c);
		}else if(n == 'b') {
			if(S2.length() == 0) {ans = 2; return;}
			char c = S2.charAt(0);
			solve(S1, S2.substring(1, S2.length()), S3, c);
		}else if(n == 'c') {
			if(S3.length() == 0) {ans = 3; return;}
			char c = S3.charAt(0);
			solve(S1, S2, S3.substring(1, S3.length()), c);
		}

	} if(n == 'a') {
			if(S1.length() == 0) {ans = 1; return;}
			char c = S1.charAt(0);
			solve(S1.substring(1, S1.length()), S2, S3, c);
		}else if(n == 'b') {
			if(S2.length() == 0) {ans = 2; return;}
			char c = S2.charAt(0);
			solve(S1, S2.substring(1, S2.length()), S3, c);
		}else if(n == 'c') {
			if(S3.length() == 0) {ans = 3; return;}
			char c = S3.charAt(0);
			solve(S1, S2, S3.substring(1, S3.length()), c);
		} n == 'a' n 'a' {
			if(S1.length() == 0) {ans = 1; return;}
			char c = S1.charAt(0);
			solve(S1.substring(1, S1.length()), S2, S3, c);
		} if(S1.length() == 0) {ans = 1; return;} S1.length() == 0 S1.length() S1.length S1 0 {ans = 1; return;} ans = 1 ans 1 return; char c = S1.charAt(0); c S1.charAt(0) S1.charAt S1 0 solve(S1.substring(1, S1.length()), S2, S3, c) solve S1.substring(1, S1.length()) S1.substring S1 1 S1.length() S1.length S1 S2 S3 c if(n == 'b') {
			if(S2.length() == 0) {ans = 2; return;}
			char c = S2.charAt(0);
			solve(S1, S2.substring(1, S2.length()), S3, c);
		}else if(n == 'c') {
			if(S3.length() == 0) {ans = 3; return;}
			char c = S3.charAt(0);
			solve(S1, S2, S3.substring(1, S3.length()), c);
		} n == 'b' n 'b' {
			if(S2.length() == 0) {ans = 2; return;}
			char c = S2.charAt(0);
			solve(S1, S2.substring(1, S2.length()), S3, c);
		} if(S2.length() == 0) {ans = 2; return;} S2.length() == 0 S2.length() S2.length S2 0 {ans = 2; return;} ans = 2 ans 2 return; char c = S2.charAt(0); c S2.charAt(0) S2.charAt S2 0 solve(S1, S2.substring(1, S2.length()), S3, c) solve S1 S2.substring(1, S2.length()) S2.substring S2 1 S2.length() S2.length S2 S3 c if(n == 'c') {
			if(S3.length() == 0) {ans = 3; return;}
			char c = S3.charAt(0);
			solve(S1, S2, S3.substring(1, S3.length()), c);
		} n == 'c' n 'c' {
			if(S3.length() == 0) {ans = 3; return;}
			char c = S3.charAt(0);
			solve(S1, S2, S3.substring(1, S3.length()), c);
		} if(S3.length() == 0) {ans = 3; return;} S3.length() == 0 S3.length() S3.length S3 0 {ans = 3; return;} ans = 3 ans 3 return; char c = S3.charAt(0); c S3.charAt(0) S3.charAt S3 0 solve(S1, S2, S3.substring(1, S3.length()), c) solve S1 S2 S3.substring(1, S3.length()) S3.substring S3 1 S3.length() S3.length S3 c String S1 S1 String S2 S2 String S3 S3 char n n public class Main {
	static int ans;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S1 = sc.next();
		String S2 = sc.next();
		String S3 = sc.next();
		sc.close();
		char c = S1.charAt(0);
		solve(S1.substring(1, S1.length()), S2, S3, c);
		if(ans == 1) System.out.println("A");
		else if(ans == 2) System.out.println("B");
		else System.out.println("C");
	}
	static void solve(String S1, String S2, String S3, char n) {
		//System.out.println(S1 + " " + S2 + " " + S3 + " " + n);
		if(n == 'a') {
			if(S1.length() == 0) {ans = 1; return;}
			char c = S1.charAt(0);
			solve(S1.substring(1, S1.length()), S2, S3, c);
		}else if(n == 'b') {
			if(S2.length() == 0) {ans = 2; return;}
			char c = S2.charAt(0);
			solve(S1, S2.substring(1, S2.length()), S3, c);
		}else if(n == 'c') {
			if(S3.length() == 0) {ans = 3; return;}
			char c = S3.charAt(0);
			solve(S1, S2, S3.substring(1, S3.length()), c);
		}

	}
} public class Main {
	static int ans;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S1 = sc.next();
		String S2 = sc.next();
		String S3 = sc.next();
		sc.close();
		char c = S1.charAt(0);
		solve(S1.substring(1, S1.length()), S2, S3, c);
		if(ans == 1) System.out.println("A");
		else if(ans == 2) System.out.println("B");
		else System.out.println("C");
	}
	static void solve(String S1, String S2, String S3, char n) {
		//System.out.println(S1 + " " + S2 + " " + S3 + " " + n);
		if(n == 'a') {
			if(S1.length() == 0) {ans = 1; return;}
			char c = S1.charAt(0);
			solve(S1.substring(1, S1.length()), S2, S3, c);
		}else if(n == 'b') {
			if(S2.length() == 0) {ans = 2; return;}
			char c = S2.charAt(0);
			solve(S1, S2.substring(1, S2.length()), S3, c);
		}else if(n == 'c') {
			if(S3.length() == 0) {ans = 3; return;}
			char c = S3.charAt(0);
			solve(S1, S2, S3.substring(1, S3.length()), c);
		}

	}
} Main
import java.util.Scanner;

public class Main {
	static int ans;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S1 = sc.next();
		String S2 = sc.next();
		String S3 = sc.next();
		sc.close();
		char c = S1.charAt(0);
		solve(S1.substring(1, S1.length()), S2, S3, c);
		if(ans == 1) System.out.println("A");
		else if(ans == 2) System.out.println("B");
		else System.out.println("C");
	}
	static void solve(String S1, String S2, String S3, char n) {
		//System.out.println(S1 + " " + S2 + " " + S3 + " " + n);
		if(n == 'a') {
			if(S1.length() == 0) {ans = 1; return;}
			char c = S1.charAt(0);
			solve(S1.substring(1, S1.length()), S2, S3, c);
		}else if(n == 'b') {
			if(S2.length() == 0) {ans = 2; return;}
			char c = S2.charAt(0);
			solve(S1, S2.substring(1, S2.length()), S3, c);
		}else if(n == 'c') {
			if(S3.length() == 0) {ans = 3; return;}
			char c = S3.charAt(0);
			solve(S1, S2, S3.substring(1, S3.length()), c);
		}

	}
}