import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String[] a = sc.nextLine().split("",0);
		String[] b = sc.nextLine().split("",0);
		String[] c = sc.nextLine().split("",0);
		int countA = a.length;
		int countB = b.length;
		int countC = c.length;
		String out = null;
		String player = "a";

		while(true){
		    if (player.equals("a")) {
		        if (countA == 0) {
		            out = "A";
		            break;
		        } else {
		            player = a[a.length - countA];
		            countA--;
		        }
		    } else if (player.equals("b")) {
		        if (countB == 0) {
		            out = "B";
		            break;
		        } else {
		            player = b[b.length - countB];
		            countB--;
		        }
		    } else {
		        if (countC == 0) {
		            out = "C";
		            break;
		        } else {
		            player = c[c.length - countC];
		            countC--;
		        }
		    }

		}

		System.out.println(out);
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String[] a = sc.nextLine().split("",0);
		String[] b = sc.nextLine().split("",0);
		String[] c = sc.nextLine().split("",0);
		int countA = a.length;
		int countB = b.length;
		int countC = c.length;
		String out = null;
		String player = "a";

		while(true){
		    if (player.equals("a")) {
		        if (countA == 0) {
		            out = "A";
		            break;
		        } else {
		            player = a[a.length - countA];
		            countA--;
		        }
		    } else if (player.equals("b")) {
		        if (countB == 0) {
		            out = "B";
		            break;
		        } else {
		            player = b[b.length - countB];
		            countB--;
		        }
		    } else {
		        if (countC == 0) {
		            out = "C";
		            break;
		        } else {
		            player = c[c.length - countC];
		            countC--;
		        }
		    }

		}

		System.out.println(out);
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String[] a = sc.nextLine().split("",0);
		String[] b = sc.nextLine().split("",0);
		String[] c = sc.nextLine().split("",0);
		int countA = a.length;
		int countB = b.length;
		int countC = c.length;
		String out = null;
		String player = "a";

		while(true){
		    if (player.equals("a")) {
		        if (countA == 0) {
		            out = "A";
		            break;
		        } else {
		            player = a[a.length - countA];
		            countA--;
		        }
		    } else if (player.equals("b")) {
		        if (countB == 0) {
		            out = "B";
		            break;
		        } else {
		            player = b[b.length - countB];
		            countB--;
		        }
		    } else {
		        if (countC == 0) {
		            out = "C";
		            break;
		        } else {
		            player = c[c.length - countC];
		            countC--;
		        }
		    }

		}

		System.out.println(out);
	} main {
		Scanner sc = new Scanner(System.in);
		String[] a = sc.nextLine().split("",0);
		String[] b = sc.nextLine().split("",0);
		String[] c = sc.nextLine().split("",0);
		int countA = a.length;
		int countB = b.length;
		int countC = c.length;
		String out = null;
		String player = "a";

		while(true){
		    if (player.equals("a")) {
		        if (countA == 0) {
		            out = "A";
		            break;
		        } else {
		            player = a[a.length - countA];
		            countA--;
		        }
		    } else if (player.equals("b")) {
		        if (countB == 0) {
		            out = "B";
		            break;
		        } else {
		            player = b[b.length - countB];
		            countB--;
		        }
		    } else {
		        if (countC == 0) {
		            out = "C";
		            break;
		        } else {
		            player = c[c.length - countC];
		            countC--;
		        }
		    }

		}

		System.out.println(out);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String[] a = sc.nextLine().split("",0); a sc.nextLine().split("",0) sc.nextLine().split sc.nextLine() sc.nextLine sc "" 0 String[] b = sc.nextLine().split("",0); b sc.nextLine().split("",0) sc.nextLine().split sc.nextLine() sc.nextLine sc "" 0 String[] c = sc.nextLine().split("",0); c sc.nextLine().split("",0) sc.nextLine().split sc.nextLine() sc.nextLine sc "" 0 int countA = a.length; countA a.length a a.length int countB = b.length; countB b.length b b.length int countC = c.length; countC c.length c c.length String out = null; out null String player = "a"; player "a" while(true){
		    if (player.equals("a")) {
		        if (countA == 0) {
		            out = "A";
		            break;
		        } else {
		            player = a[a.length - countA];
		            countA--;
		        }
		    } else if (player.equals("b")) {
		        if (countB == 0) {
		            out = "B";
		            break;
		        } else {
		            player = b[b.length - countB];
		            countB--;
		        }
		    } else {
		        if (countC == 0) {
		            out = "C";
		            break;
		        } else {
		            player = c[c.length - countC];
		            countC--;
		        }
		    }

		} true {
		    if (player.equals("a")) {
		        if (countA == 0) {
		            out = "A";
		            break;
		        } else {
		            player = a[a.length - countA];
		            countA--;
		        }
		    } else if (player.equals("b")) {
		        if (countB == 0) {
		            out = "B";
		            break;
		        } else {
		            player = b[b.length - countB];
		            countB--;
		        }
		    } else {
		        if (countC == 0) {
		            out = "C";
		            break;
		        } else {
		            player = c[c.length - countC];
		            countC--;
		        }
		    }

		} if (player.equals("a")) {
		        if (countA == 0) {
		            out = "A";
		            break;
		        } else {
		            player = a[a.length - countA];
		            countA--;
		        }
		    } else if (player.equals("b")) {
		        if (countB == 0) {
		            out = "B";
		            break;
		        } else {
		            player = b[b.length - countB];
		            countB--;
		        }
		    } else {
		        if (countC == 0) {
		            out = "C";
		            break;
		        } else {
		            player = c[c.length - countC];
		            countC--;
		        }
		    } player.equals("a") player.equals player "a" {
		        if (countA == 0) {
		            out = "A";
		            break;
		        } else {
		            player = a[a.length - countA];
		            countA--;
		        }
		    } if (countA == 0) {
		            out = "A";
		            break;
		        } else {
		            player = a[a.length - countA];
		            countA--;
		        } countA == 0 countA 0 {
		            out = "A";
		            break;
		        } out = "A" out "A" break; {
		            player = a[a.length - countA];
		            countA--;
		        } player = a[a.length - countA] player a[a.length - countA] a a.length - countA a.length a a.length countA countA-- countA if (player.equals("b")) {
		        if (countB == 0) {
		            out = "B";
		            break;
		        } else {
		            player = b[b.length - countB];
		            countB--;
		        }
		    } else {
		        if (countC == 0) {
		            out = "C";
		            break;
		        } else {
		            player = c[c.length - countC];
		            countC--;
		        }
		    } player.equals("b") player.equals player "b" {
		        if (countB == 0) {
		            out = "B";
		            break;
		        } else {
		            player = b[b.length - countB];
		            countB--;
		        }
		    } if (countB == 0) {
		            out = "B";
		            break;
		        } else {
		            player = b[b.length - countB];
		            countB--;
		        } countB == 0 countB 0 {
		            out = "B";
		            break;
		        } out = "B" out "B" break; {
		            player = b[b.length - countB];
		            countB--;
		        } player = b[b.length - countB] player b[b.length - countB] b b.length - countB b.length b b.length countB countB-- countB {
		        if (countC == 0) {
		            out = "C";
		            break;
		        } else {
		            player = c[c.length - countC];
		            countC--;
		        }
		    } if (countC == 0) {
		            out = "C";
		            break;
		        } else {
		            player = c[c.length - countC];
		            countC--;
		        } countC == 0 countC 0 {
		            out = "C";
		            break;
		        } out = "C" out "C" break; {
		            player = c[c.length - countC];
		            countC--;
		        } player = c[c.length - countC] player c[c.length - countC] c c.length - countC c.length c c.length countC countC-- countC System.out.println(out) System.out.println System.out System System.out out String[] args args public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String[] a = sc.nextLine().split("",0);
		String[] b = sc.nextLine().split("",0);
		String[] c = sc.nextLine().split("",0);
		int countA = a.length;
		int countB = b.length;
		int countC = c.length;
		String out = null;
		String player = "a";

		while(true){
		    if (player.equals("a")) {
		        if (countA == 0) {
		            out = "A";
		            break;
		        } else {
		            player = a[a.length - countA];
		            countA--;
		        }
		    } else if (player.equals("b")) {
		        if (countB == 0) {
		            out = "B";
		            break;
		        } else {
		            player = b[b.length - countB];
		            countB--;
		        }
		    } else {
		        if (countC == 0) {
		            out = "C";
		            break;
		        } else {
		            player = c[c.length - countC];
		            countC--;
		        }
		    }

		}

		System.out.println(out);
	}
} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String[] a = sc.nextLine().split("",0);
		String[] b = sc.nextLine().split("",0);
		String[] c = sc.nextLine().split("",0);
		int countA = a.length;
		int countB = b.length;
		int countC = c.length;
		String out = null;
		String player = "a";

		while(true){
		    if (player.equals("a")) {
		        if (countA == 0) {
		            out = "A";
		            break;
		        } else {
		            player = a[a.length - countA];
		            countA--;
		        }
		    } else if (player.equals("b")) {
		        if (countB == 0) {
		            out = "B";
		            break;
		        } else {
		            player = b[b.length - countB];
		            countB--;
		        }
		    } else {
		        if (countC == 0) {
		            out = "C";
		            break;
		        } else {
		            player = c[c.length - countC];
		            countC--;
		        }
		    }

		}

		System.out.println(out);
	}
} Main
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String[] a = sc.nextLine().split("",0);
		String[] b = sc.nextLine().split("",0);
		String[] c = sc.nextLine().split("",0);
		int countA = a.length;
		int countB = b.length;
		int countC = c.length;
		String out = null;
		String player = "a";

		while(true){
		    if (player.equals("a")) {
		        if (countA == 0) {
		            out = "A";
		            break;
		        } else {
		            player = a[a.length - countA];
		            countA--;
		        }
		    } else if (player.equals("b")) {
		        if (countB == 0) {
		            out = "B";
		            break;
		        } else {
		            player = b[b.length - countB];
		            countB--;
		        }
		    } else {
		        if (countC == 0) {
		            out = "C";
		            break;
		        } else {
		            player = c[c.length - countC];
		            countC--;
		        }
		    }

		}

		System.out.println(out);
	}
}