import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S1 = sc.next();
		String S2 = sc.next();
		String S3 = sc.next();
		char turn = 'a';
		int a = S1.length();
		int b = S2.length();
		int c = S3.length();
		int cnt1 = 0;
		int cnt2 = 0;
		int cnt3 = 0;
		while(true) {
			if(turn == 'a') {
				if(a == cnt1) {
					System.out.println("A");
					return;
				}
				cnt1++;
				turn = S1.charAt(cnt1 - 1);
			} else if(turn == 'b') {
				if(b == cnt2) {
					System.out.println("B");
					return;
				}
				cnt2++;
				turn = S2.charAt(cnt2 - 1);
			} else {
				if(c == cnt3) {
					System.out.println("C");
					return;
				}
				cnt3++;
				turn = S3.charAt(cnt3 - 1);
			}
		}
	}
} 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();
		String S2 = sc.next();
		String S3 = sc.next();
		char turn = 'a';
		int a = S1.length();
		int b = S2.length();
		int c = S3.length();
		int cnt1 = 0;
		int cnt2 = 0;
		int cnt3 = 0;
		while(true) {
			if(turn == 'a') {
				if(a == cnt1) {
					System.out.println("A");
					return;
				}
				cnt1++;
				turn = S1.charAt(cnt1 - 1);
			} else if(turn == 'b') {
				if(b == cnt2) {
					System.out.println("B");
					return;
				}
				cnt2++;
				turn = S2.charAt(cnt2 - 1);
			} else {
				if(c == cnt3) {
					System.out.println("C");
					return;
				}
				cnt3++;
				turn = S3.charAt(cnt3 - 1);
			}
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S1 = sc.next();
		String S2 = sc.next();
		String S3 = sc.next();
		char turn = 'a';
		int a = S1.length();
		int b = S2.length();
		int c = S3.length();
		int cnt1 = 0;
		int cnt2 = 0;
		int cnt3 = 0;
		while(true) {
			if(turn == 'a') {
				if(a == cnt1) {
					System.out.println("A");
					return;
				}
				cnt1++;
				turn = S1.charAt(cnt1 - 1);
			} else if(turn == 'b') {
				if(b == cnt2) {
					System.out.println("B");
					return;
				}
				cnt2++;
				turn = S2.charAt(cnt2 - 1);
			} else {
				if(c == cnt3) {
					System.out.println("C");
					return;
				}
				cnt3++;
				turn = S3.charAt(cnt3 - 1);
			}
		}
	} main {
		Scanner sc = new Scanner(System.in);
		String S1 = sc.next();
		String S2 = sc.next();
		String S3 = sc.next();
		char turn = 'a';
		int a = S1.length();
		int b = S2.length();
		int c = S3.length();
		int cnt1 = 0;
		int cnt2 = 0;
		int cnt3 = 0;
		while(true) {
			if(turn == 'a') {
				if(a == cnt1) {
					System.out.println("A");
					return;
				}
				cnt1++;
				turn = S1.charAt(cnt1 - 1);
			} else if(turn == 'b') {
				if(b == cnt2) {
					System.out.println("B");
					return;
				}
				cnt2++;
				turn = S2.charAt(cnt2 - 1);
			} else {
				if(c == cnt3) {
					System.out.println("C");
					return;
				}
				cnt3++;
				turn = S3.charAt(cnt3 - 1);
			}
		}
	} 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 char turn = 'a'; turn 'a' int a = S1.length(); a S1.length() S1.length S1 int b = S2.length(); b S2.length() S2.length S2 int c = S3.length(); c S3.length() S3.length S3 int cnt1 = 0; cnt1 0 int cnt2 = 0; cnt2 0 int cnt3 = 0; cnt3 0 while(true) {
			if(turn == 'a') {
				if(a == cnt1) {
					System.out.println("A");
					return;
				}
				cnt1++;
				turn = S1.charAt(cnt1 - 1);
			} else if(turn == 'b') {
				if(b == cnt2) {
					System.out.println("B");
					return;
				}
				cnt2++;
				turn = S2.charAt(cnt2 - 1);
			} else {
				if(c == cnt3) {
					System.out.println("C");
					return;
				}
				cnt3++;
				turn = S3.charAt(cnt3 - 1);
			}
		} true {
			if(turn == 'a') {
				if(a == cnt1) {
					System.out.println("A");
					return;
				}
				cnt1++;
				turn = S1.charAt(cnt1 - 1);
			} else if(turn == 'b') {
				if(b == cnt2) {
					System.out.println("B");
					return;
				}
				cnt2++;
				turn = S2.charAt(cnt2 - 1);
			} else {
				if(c == cnt3) {
					System.out.println("C");
					return;
				}
				cnt3++;
				turn = S3.charAt(cnt3 - 1);
			}
		} if(turn == 'a') {
				if(a == cnt1) {
					System.out.println("A");
					return;
				}
				cnt1++;
				turn = S1.charAt(cnt1 - 1);
			} else if(turn == 'b') {
				if(b == cnt2) {
					System.out.println("B");
					return;
				}
				cnt2++;
				turn = S2.charAt(cnt2 - 1);
			} else {
				if(c == cnt3) {
					System.out.println("C");
					return;
				}
				cnt3++;
				turn = S3.charAt(cnt3 - 1);
			} turn == 'a' turn 'a' {
				if(a == cnt1) {
					System.out.println("A");
					return;
				}
				cnt1++;
				turn = S1.charAt(cnt1 - 1);
			} if(a == cnt1) {
					System.out.println("A");
					return;
				} a == cnt1 a cnt1 {
					System.out.println("A");
					return;
				} System.out.println("A") System.out.println System.out System System.out "A" return; cnt1++ cnt1 turn = S1.charAt(cnt1 - 1) turn S1.charAt(cnt1 - 1) S1.charAt S1 cnt1 - 1 cnt1 1 if(turn == 'b') {
				if(b == cnt2) {
					System.out.println("B");
					return;
				}
				cnt2++;
				turn = S2.charAt(cnt2 - 1);
			} else {
				if(c == cnt3) {
					System.out.println("C");
					return;
				}
				cnt3++;
				turn = S3.charAt(cnt3 - 1);
			} turn == 'b' turn 'b' {
				if(b == cnt2) {
					System.out.println("B");
					return;
				}
				cnt2++;
				turn = S2.charAt(cnt2 - 1);
			} if(b == cnt2) {
					System.out.println("B");
					return;
				} b == cnt2 b cnt2 {
					System.out.println("B");
					return;
				} System.out.println("B") System.out.println System.out System System.out "B" return; cnt2++ cnt2 turn = S2.charAt(cnt2 - 1) turn S2.charAt(cnt2 - 1) S2.charAt S2 cnt2 - 1 cnt2 1 {
				if(c == cnt3) {
					System.out.println("C");
					return;
				}
				cnt3++;
				turn = S3.charAt(cnt3 - 1);
			} if(c == cnt3) {
					System.out.println("C");
					return;
				} c == cnt3 c cnt3 {
					System.out.println("C");
					return;
				} System.out.println("C") System.out.println System.out System System.out "C" return; cnt3++ cnt3 turn = S3.charAt(cnt3 - 1) turn S3.charAt(cnt3 - 1) S3.charAt S3 cnt3 - 1 cnt3 1 String[] args args public class Main {

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

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

public class Main {

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