import java.util.*;
import java.math.*;
import java.lang.String;
import java.lang.System;
import java.lang.reflect.Array;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String A = sc.nextLine();
		String[] Aarr = A.split("");
		String B = sc.nextLine();
		String[] Barr = B.split("");
		String C = sc.nextLine();
		String[] Carr = C.split("");
		String[][] arr = new String[3][];
		arr[0] = Aarr;
		arr[1] = Barr;
		arr[2] = Carr;
		int Acount = 0;
		int Bcount = 0;
		int Ccount = 0;
		String answer = null;
		boolean fin = false;
		int i = 0;
		int j = 0;
		
		while (!fin) {
			if (i == 0) {
				j = Acount;
				Acount++;
				if (Acount > A.length()) {
					fin = true;
					answer = "A";
				}
			} else if (i == 1) {
				j = Bcount;
				Bcount++;
				if (Bcount > B.length()) {
					fin = true;
					answer = "B";
				}
			} else {
				j = Ccount;
				Ccount++;
				if (Ccount > C.length()) {
					fin = true;
					answer = "C";
				}
			}
			if (!fin) {
				if (arr[i][j].equals("a")) {
					i = 0;
				} else if (arr[i][j].equals("b")) {
					i = 1;
				} else {
					i = 2;
				}
			}
		}
		System.out.println(answer);
		
	}
} import java.util.*; util.* java import java.math.*; math.* java import java.lang.String; String java.lang import java.lang.System; System java.lang import java.lang.reflect.Array; Array java.lang.reflect public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String A = sc.nextLine();
		String[] Aarr = A.split("");
		String B = sc.nextLine();
		String[] Barr = B.split("");
		String C = sc.nextLine();
		String[] Carr = C.split("");
		String[][] arr = new String[3][];
		arr[0] = Aarr;
		arr[1] = Barr;
		arr[2] = Carr;
		int Acount = 0;
		int Bcount = 0;
		int Ccount = 0;
		String answer = null;
		boolean fin = false;
		int i = 0;
		int j = 0;
		
		while (!fin) {
			if (i == 0) {
				j = Acount;
				Acount++;
				if (Acount > A.length()) {
					fin = true;
					answer = "A";
				}
			} else if (i == 1) {
				j = Bcount;
				Bcount++;
				if (Bcount > B.length()) {
					fin = true;
					answer = "B";
				}
			} else {
				j = Ccount;
				Ccount++;
				if (Ccount > C.length()) {
					fin = true;
					answer = "C";
				}
			}
			if (!fin) {
				if (arr[i][j].equals("a")) {
					i = 0;
				} else if (arr[i][j].equals("b")) {
					i = 1;
				} else {
					i = 2;
				}
			}
		}
		System.out.println(answer);
		
	}
} Main public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String A = sc.nextLine();
		String[] Aarr = A.split("");
		String B = sc.nextLine();
		String[] Barr = B.split("");
		String C = sc.nextLine();
		String[] Carr = C.split("");
		String[][] arr = new String[3][];
		arr[0] = Aarr;
		arr[1] = Barr;
		arr[2] = Carr;
		int Acount = 0;
		int Bcount = 0;
		int Ccount = 0;
		String answer = null;
		boolean fin = false;
		int i = 0;
		int j = 0;
		
		while (!fin) {
			if (i == 0) {
				j = Acount;
				Acount++;
				if (Acount > A.length()) {
					fin = true;
					answer = "A";
				}
			} else if (i == 1) {
				j = Bcount;
				Bcount++;
				if (Bcount > B.length()) {
					fin = true;
					answer = "B";
				}
			} else {
				j = Ccount;
				Ccount++;
				if (Ccount > C.length()) {
					fin = true;
					answer = "C";
				}
			}
			if (!fin) {
				if (arr[i][j].equals("a")) {
					i = 0;
				} else if (arr[i][j].equals("b")) {
					i = 1;
				} else {
					i = 2;
				}
			}
		}
		System.out.println(answer);
		
	} main {
		Scanner sc = new Scanner(System.in);
		String A = sc.nextLine();
		String[] Aarr = A.split("");
		String B = sc.nextLine();
		String[] Barr = B.split("");
		String C = sc.nextLine();
		String[] Carr = C.split("");
		String[][] arr = new String[3][];
		arr[0] = Aarr;
		arr[1] = Barr;
		arr[2] = Carr;
		int Acount = 0;
		int Bcount = 0;
		int Ccount = 0;
		String answer = null;
		boolean fin = false;
		int i = 0;
		int j = 0;
		
		while (!fin) {
			if (i == 0) {
				j = Acount;
				Acount++;
				if (Acount > A.length()) {
					fin = true;
					answer = "A";
				}
			} else if (i == 1) {
				j = Bcount;
				Bcount++;
				if (Bcount > B.length()) {
					fin = true;
					answer = "B";
				}
			} else {
				j = Ccount;
				Ccount++;
				if (Ccount > C.length()) {
					fin = true;
					answer = "C";
				}
			}
			if (!fin) {
				if (arr[i][j].equals("a")) {
					i = 0;
				} else if (arr[i][j].equals("b")) {
					i = 1;
				} else {
					i = 2;
				}
			}
		}
		System.out.println(answer);
		
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String A = sc.nextLine(); A sc.nextLine() sc.nextLine sc String[] Aarr = A.split(""); Aarr A.split("") A.split A "" String B = sc.nextLine(); B sc.nextLine() sc.nextLine sc String[] Barr = B.split(""); Barr B.split("") B.split B "" String C = sc.nextLine(); C sc.nextLine() sc.nextLine sc String[] Carr = C.split(""); Carr C.split("") C.split C "" String[][] arr = new String[3][]; arr new String[3][] 3 arr[0] = Aarr arr[0] arr 0 Aarr arr[1] = Barr arr[1] arr 1 Barr arr[2] = Carr arr[2] arr 2 Carr int Acount = 0; Acount 0 int Bcount = 0; Bcount 0 int Ccount = 0; Ccount 0 String answer = null; answer null boolean fin = false; fin false int i = 0; i 0 int j = 0; j 0 while (!fin) {
			if (i == 0) {
				j = Acount;
				Acount++;
				if (Acount > A.length()) {
					fin = true;
					answer = "A";
				}
			} else if (i == 1) {
				j = Bcount;
				Bcount++;
				if (Bcount > B.length()) {
					fin = true;
					answer = "B";
				}
			} else {
				j = Ccount;
				Ccount++;
				if (Ccount > C.length()) {
					fin = true;
					answer = "C";
				}
			}
			if (!fin) {
				if (arr[i][j].equals("a")) {
					i = 0;
				} else if (arr[i][j].equals("b")) {
					i = 1;
				} else {
					i = 2;
				}
			}
		} !fin fin {
			if (i == 0) {
				j = Acount;
				Acount++;
				if (Acount > A.length()) {
					fin = true;
					answer = "A";
				}
			} else if (i == 1) {
				j = Bcount;
				Bcount++;
				if (Bcount > B.length()) {
					fin = true;
					answer = "B";
				}
			} else {
				j = Ccount;
				Ccount++;
				if (Ccount > C.length()) {
					fin = true;
					answer = "C";
				}
			}
			if (!fin) {
				if (arr[i][j].equals("a")) {
					i = 0;
				} else if (arr[i][j].equals("b")) {
					i = 1;
				} else {
					i = 2;
				}
			}
		} if (i == 0) {
				j = Acount;
				Acount++;
				if (Acount > A.length()) {
					fin = true;
					answer = "A";
				}
			} else if (i == 1) {
				j = Bcount;
				Bcount++;
				if (Bcount > B.length()) {
					fin = true;
					answer = "B";
				}
			} else {
				j = Ccount;
				Ccount++;
				if (Ccount > C.length()) {
					fin = true;
					answer = "C";
				}
			} i == 0 i 0 {
				j = Acount;
				Acount++;
				if (Acount > A.length()) {
					fin = true;
					answer = "A";
				}
			} j = Acount j Acount Acount++ Acount if (Acount > A.length()) {
					fin = true;
					answer = "A";
				} Acount > A.length() Acount A.length() A.length A {
					fin = true;
					answer = "A";
				} fin = true fin true answer = "A" answer "A" if (i == 1) {
				j = Bcount;
				Bcount++;
				if (Bcount > B.length()) {
					fin = true;
					answer = "B";
				}
			} else {
				j = Ccount;
				Ccount++;
				if (Ccount > C.length()) {
					fin = true;
					answer = "C";
				}
			} i == 1 i 1 {
				j = Bcount;
				Bcount++;
				if (Bcount > B.length()) {
					fin = true;
					answer = "B";
				}
			} j = Bcount j Bcount Bcount++ Bcount if (Bcount > B.length()) {
					fin = true;
					answer = "B";
				} Bcount > B.length() Bcount B.length() B.length B {
					fin = true;
					answer = "B";
				} fin = true fin true answer = "B" answer "B" {
				j = Ccount;
				Ccount++;
				if (Ccount > C.length()) {
					fin = true;
					answer = "C";
				}
			} j = Ccount j Ccount Ccount++ Ccount if (Ccount > C.length()) {
					fin = true;
					answer = "C";
				} Ccount > C.length() Ccount C.length() C.length C {
					fin = true;
					answer = "C";
				} fin = true fin true answer = "C" answer "C" if (!fin) {
				if (arr[i][j].equals("a")) {
					i = 0;
				} else if (arr[i][j].equals("b")) {
					i = 1;
				} else {
					i = 2;
				}
			} !fin fin {
				if (arr[i][j].equals("a")) {
					i = 0;
				} else if (arr[i][j].equals("b")) {
					i = 1;
				} else {
					i = 2;
				}
			} if (arr[i][j].equals("a")) {
					i = 0;
				} else if (arr[i][j].equals("b")) {
					i = 1;
				} else {
					i = 2;
				} arr[i][j].equals("a") arr[i][j].equals arr[i][j] arr[i] arr i j "a" {
					i = 0;
				} i = 0 i 0 if (arr[i][j].equals("b")) {
					i = 1;
				} else {
					i = 2;
				} arr[i][j].equals("b") arr[i][j].equals arr[i][j] arr[i] arr i j "b" {
					i = 1;
				} i = 1 i 1 {
					i = 2;
				} i = 2 i 2 System.out.println(answer) System.out.println System.out System System.out answer String args[] args public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String A = sc.nextLine();
		String[] Aarr = A.split("");
		String B = sc.nextLine();
		String[] Barr = B.split("");
		String C = sc.nextLine();
		String[] Carr = C.split("");
		String[][] arr = new String[3][];
		arr[0] = Aarr;
		arr[1] = Barr;
		arr[2] = Carr;
		int Acount = 0;
		int Bcount = 0;
		int Ccount = 0;
		String answer = null;
		boolean fin = false;
		int i = 0;
		int j = 0;
		
		while (!fin) {
			if (i == 0) {
				j = Acount;
				Acount++;
				if (Acount > A.length()) {
					fin = true;
					answer = "A";
				}
			} else if (i == 1) {
				j = Bcount;
				Bcount++;
				if (Bcount > B.length()) {
					fin = true;
					answer = "B";
				}
			} else {
				j = Ccount;
				Ccount++;
				if (Ccount > C.length()) {
					fin = true;
					answer = "C";
				}
			}
			if (!fin) {
				if (arr[i][j].equals("a")) {
					i = 0;
				} else if (arr[i][j].equals("b")) {
					i = 1;
				} else {
					i = 2;
				}
			}
		}
		System.out.println(answer);
		
	}
} public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String A = sc.nextLine();
		String[] Aarr = A.split("");
		String B = sc.nextLine();
		String[] Barr = B.split("");
		String C = sc.nextLine();
		String[] Carr = C.split("");
		String[][] arr = new String[3][];
		arr[0] = Aarr;
		arr[1] = Barr;
		arr[2] = Carr;
		int Acount = 0;
		int Bcount = 0;
		int Ccount = 0;
		String answer = null;
		boolean fin = false;
		int i = 0;
		int j = 0;
		
		while (!fin) {
			if (i == 0) {
				j = Acount;
				Acount++;
				if (Acount > A.length()) {
					fin = true;
					answer = "A";
				}
			} else if (i == 1) {
				j = Bcount;
				Bcount++;
				if (Bcount > B.length()) {
					fin = true;
					answer = "B";
				}
			} else {
				j = Ccount;
				Ccount++;
				if (Ccount > C.length()) {
					fin = true;
					answer = "C";
				}
			}
			if (!fin) {
				if (arr[i][j].equals("a")) {
					i = 0;
				} else if (arr[i][j].equals("b")) {
					i = 1;
				} else {
					i = 2;
				}
			}
		}
		System.out.println(answer);
		
	}
} Main
import java.util.*;
import java.math.*;
import java.lang.String;
import java.lang.System;
import java.lang.reflect.Array;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String A = sc.nextLine();
		String[] Aarr = A.split("");
		String B = sc.nextLine();
		String[] Barr = B.split("");
		String C = sc.nextLine();
		String[] Carr = C.split("");
		String[][] arr = new String[3][];
		arr[0] = Aarr;
		arr[1] = Barr;
		arr[2] = Carr;
		int Acount = 0;
		int Bcount = 0;
		int Ccount = 0;
		String answer = null;
		boolean fin = false;
		int i = 0;
		int j = 0;
		
		while (!fin) {
			if (i == 0) {
				j = Acount;
				Acount++;
				if (Acount > A.length()) {
					fin = true;
					answer = "A";
				}
			} else if (i == 1) {
				j = Bcount;
				Bcount++;
				if (Bcount > B.length()) {
					fin = true;
					answer = "B";
				}
			} else {
				j = Ccount;
				Ccount++;
				if (Ccount > C.length()) {
					fin = true;
					answer = "C";
				}
			}
			if (!fin) {
				if (arr[i][j].equals("a")) {
					i = 0;
				} else if (arr[i][j].equals("b")) {
					i = 1;
				} else {
					i = 2;
				}
			}
		}
		System.out.println(answer);
		
	}
}
