import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S1 = sc.next(), S2 = sc.next(), S3 = sc.next();
		int cnt1 = 0, cnt2 = 0, cnt3 = 0;
		char turn = 'a';
		for(;;) {
			if(turn == 'a') {
				if(cnt1 == S1.length()) {
					System.out.println("A");
					return;
				}
				turn = S1.charAt(cnt1);
				cnt1++;
			} else if(turn == 'b') {
				if(cnt2 == S2.length()) {
					System.out.println("B");
					return;
				}
				turn = S2.charAt(cnt2);
				cnt2++;
			} else {
				if(cnt3 == S3.length()) {
					System.out.println("C");
					return;
				}
				turn = S3.charAt(cnt3);
				cnt3++;
			}
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S1 = sc.next(), S2 = sc.next(), S3 = sc.next();
		int cnt1 = 0, cnt2 = 0, cnt3 = 0;
		char turn = 'a';
		for(;;) {
			if(turn == 'a') {
				if(cnt1 == S1.length()) {
					System.out.println("A");
					return;
				}
				turn = S1.charAt(cnt1);
				cnt1++;
			} else if(turn == 'b') {
				if(cnt2 == S2.length()) {
					System.out.println("B");
					return;
				}
				turn = S2.charAt(cnt2);
				cnt2++;
			} else {
				if(cnt3 == S3.length()) {
					System.out.println("C");
					return;
				}
				turn = S3.charAt(cnt3);
				cnt3++;
			}
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S1 = sc.next(), S2 = sc.next(), S3 = sc.next();
		int cnt1 = 0, cnt2 = 0, cnt3 = 0;
		char turn = 'a';
		for(;;) {
			if(turn == 'a') {
				if(cnt1 == S1.length()) {
					System.out.println("A");
					return;
				}
				turn = S1.charAt(cnt1);
				cnt1++;
			} else if(turn == 'b') {
				if(cnt2 == S2.length()) {
					System.out.println("B");
					return;
				}
				turn = S2.charAt(cnt2);
				cnt2++;
			} else {
				if(cnt3 == S3.length()) {
					System.out.println("C");
					return;
				}
				turn = S3.charAt(cnt3);
				cnt3++;
			}
		}
	} main {
		Scanner sc = new Scanner(System.in);
		String S1 = sc.next(), S2 = sc.next(), S3 = sc.next();
		int cnt1 = 0, cnt2 = 0, cnt3 = 0;
		char turn = 'a';
		for(;;) {
			if(turn == 'a') {
				if(cnt1 == S1.length()) {
					System.out.println("A");
					return;
				}
				turn = S1.charAt(cnt1);
				cnt1++;
			} else if(turn == 'b') {
				if(cnt2 == S2.length()) {
					System.out.println("B");
					return;
				}
				turn = S2.charAt(cnt2);
				cnt2++;
			} else {
				if(cnt3 == S3.length()) {
					System.out.println("C");
					return;
				}
				turn = S3.charAt(cnt3);
				cnt3++;
			}
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String S1 = sc.next() S1 sc.next() sc.next sc S2 = sc.next() S2 sc.next() sc.next sc S3 = sc.next(); S3 sc.next() sc.next sc int cnt1 = 0 cnt1 0 cnt2 = 0 cnt2 0 cnt3 = 0; cnt3 0 char turn = 'a'; turn 'a' for(;;) {
			if(turn == 'a') {
				if(cnt1 == S1.length()) {
					System.out.println("A");
					return;
				}
				turn = S1.charAt(cnt1);
				cnt1++;
			} else if(turn == 'b') {
				if(cnt2 == S2.length()) {
					System.out.println("B");
					return;
				}
				turn = S2.charAt(cnt2);
				cnt2++;
			} else {
				if(cnt3 == S3.length()) {
					System.out.println("C");
					return;
				}
				turn = S3.charAt(cnt3);
				cnt3++;
			}
		} ; {
			if(turn == 'a') {
				if(cnt1 == S1.length()) {
					System.out.println("A");
					return;
				}
				turn = S1.charAt(cnt1);
				cnt1++;
			} else if(turn == 'b') {
				if(cnt2 == S2.length()) {
					System.out.println("B");
					return;
				}
				turn = S2.charAt(cnt2);
				cnt2++;
			} else {
				if(cnt3 == S3.length()) {
					System.out.println("C");
					return;
				}
				turn = S3.charAt(cnt3);
				cnt3++;
			}
		} {
			if(turn == 'a') {
				if(cnt1 == S1.length()) {
					System.out.println("A");
					return;
				}
				turn = S1.charAt(cnt1);
				cnt1++;
			} else if(turn == 'b') {
				if(cnt2 == S2.length()) {
					System.out.println("B");
					return;
				}
				turn = S2.charAt(cnt2);
				cnt2++;
			} else {
				if(cnt3 == S3.length()) {
					System.out.println("C");
					return;
				}
				turn = S3.charAt(cnt3);
				cnt3++;
			}
		} if(turn == 'a') {
				if(cnt1 == S1.length()) {
					System.out.println("A");
					return;
				}
				turn = S1.charAt(cnt1);
				cnt1++;
			} else if(turn == 'b') {
				if(cnt2 == S2.length()) {
					System.out.println("B");
					return;
				}
				turn = S2.charAt(cnt2);
				cnt2++;
			} else {
				if(cnt3 == S3.length()) {
					System.out.println("C");
					return;
				}
				turn = S3.charAt(cnt3);
				cnt3++;
			} turn == 'a' turn 'a' {
				if(cnt1 == S1.length()) {
					System.out.println("A");
					return;
				}
				turn = S1.charAt(cnt1);
				cnt1++;
			} if(cnt1 == S1.length()) {
					System.out.println("A");
					return;
				} cnt1 == S1.length() cnt1 S1.length() S1.length S1 {
					System.out.println("A");
					return;
				} System.out.println("A") System.out.println System.out System System.out "A" return; turn = S1.charAt(cnt1) turn S1.charAt(cnt1) S1.charAt S1 cnt1 cnt1++ cnt1 if(turn == 'b') {
				if(cnt2 == S2.length()) {
					System.out.println("B");
					return;
				}
				turn = S2.charAt(cnt2);
				cnt2++;
			} else {
				if(cnt3 == S3.length()) {
					System.out.println("C");
					return;
				}
				turn = S3.charAt(cnt3);
				cnt3++;
			} turn == 'b' turn 'b' {
				if(cnt2 == S2.length()) {
					System.out.println("B");
					return;
				}
				turn = S2.charAt(cnt2);
				cnt2++;
			} if(cnt2 == S2.length()) {
					System.out.println("B");
					return;
				} cnt2 == S2.length() cnt2 S2.length() S2.length S2 {
					System.out.println("B");
					return;
				} System.out.println("B") System.out.println System.out System System.out "B" return; turn = S2.charAt(cnt2) turn S2.charAt(cnt2) S2.charAt S2 cnt2 cnt2++ cnt2 {
				if(cnt3 == S3.length()) {
					System.out.println("C");
					return;
				}
				turn = S3.charAt(cnt3);
				cnt3++;
			} if(cnt3 == S3.length()) {
					System.out.println("C");
					return;
				} cnt3 == S3.length() cnt3 S3.length() S3.length S3 {
					System.out.println("C");
					return;
				} System.out.println("C") System.out.println System.out System System.out "C" return; turn = S3.charAt(cnt3) turn S3.charAt(cnt3) S3.charAt S3 cnt3 cnt3++ cnt3 String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S1 = sc.next(), S2 = sc.next(), S3 = sc.next();
		int cnt1 = 0, cnt2 = 0, cnt3 = 0;
		char turn = 'a';
		for(;;) {
			if(turn == 'a') {
				if(cnt1 == S1.length()) {
					System.out.println("A");
					return;
				}
				turn = S1.charAt(cnt1);
				cnt1++;
			} else if(turn == 'b') {
				if(cnt2 == S2.length()) {
					System.out.println("B");
					return;
				}
				turn = S2.charAt(cnt2);
				cnt2++;
			} else {
				if(cnt3 == S3.length()) {
					System.out.println("C");
					return;
				}
				turn = S3.charAt(cnt3);
				cnt3++;
			}
		}
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S1 = sc.next(), S2 = sc.next(), S3 = sc.next();
		int cnt1 = 0, cnt2 = 0, cnt3 = 0;
		char turn = 'a';
		for(;;) {
			if(turn == 'a') {
				if(cnt1 == S1.length()) {
					System.out.println("A");
					return;
				}
				turn = S1.charAt(cnt1);
				cnt1++;
			} else if(turn == 'b') {
				if(cnt2 == S2.length()) {
					System.out.println("B");
					return;
				}
				turn = S2.charAt(cnt2);
				cnt2++;
			} else {
				if(cnt3 == S3.length()) {
					System.out.println("C");
					return;
				}
				turn = S3.charAt(cnt3);
				cnt3++;
			}
		}
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S1 = sc.next(), S2 = sc.next(), S3 = sc.next();
		int cnt1 = 0, cnt2 = 0, cnt3 = 0;
		char turn = 'a';
		for(;;) {
			if(turn == 'a') {
				if(cnt1 == S1.length()) {
					System.out.println("A");
					return;
				}
				turn = S1.charAt(cnt1);
				cnt1++;
			} else if(turn == 'b') {
				if(cnt2 == S2.length()) {
					System.out.println("B");
					return;
				}
				turn = S2.charAt(cnt2);
				cnt2++;
			} else {
				if(cnt3 == S3.length()) {
					System.out.println("C");
					return;
				}
				turn = S3.charAt(cnt3);
				cnt3++;
			}
		}
	}
}
