import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		String Sa = sc.next();
		String Sb = sc.next();
		String Sc = sc.next();

		int a = 0;
		int b = 0;
		int c = 0;
		int flag = -1;
		String A[] = Sa.split("");
		String B[] = Sb.split("");
		String C[] = Sc.split("");
		String str = "X";

		while(true){
			String X[];
			int x;
			if(flag == -1){
				X = A;
				if(A.length == a){
					str = "A";
				}
				x = a;
				a++;
				//System.out.println("a");
			}else if(flag == 0){
				X = B;
				if(B.length == b){
					str = "B";
				}
				x = b;
				b++;
				//System.out.println("b");
			}else{
				X = C;
				if(C.length == c){
					str = "C";
				}
				x = c;
				c++;
				//System.out.println("c");
			}//ここでlengthと同じになる

			if(!str.equals("X")){
				break;
			}

			if(X[x].equals("a")){
				flag = -1;
			}else if(X[x].equals("b")){
				flag = 0;
			}else{
				flag = 1;
			}

			//System.out.println(X + ":" + x);
		}

		System.out.println(str);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		String Sa = sc.next();
		String Sb = sc.next();
		String Sc = sc.next();

		int a = 0;
		int b = 0;
		int c = 0;
		int flag = -1;
		String A[] = Sa.split("");
		String B[] = Sb.split("");
		String C[] = Sc.split("");
		String str = "X";

		while(true){
			String X[];
			int x;
			if(flag == -1){
				X = A;
				if(A.length == a){
					str = "A";
				}
				x = a;
				a++;
				//System.out.println("a");
			}else if(flag == 0){
				X = B;
				if(B.length == b){
					str = "B";
				}
				x = b;
				b++;
				//System.out.println("b");
			}else{
				X = C;
				if(C.length == c){
					str = "C";
				}
				x = c;
				c++;
				//System.out.println("c");
			}//ここでlengthと同じになる

			if(!str.equals("X")){
				break;
			}

			if(X[x].equals("a")){
				flag = -1;
			}else if(X[x].equals("b")){
				flag = 0;
			}else{
				flag = 1;
			}

			//System.out.println(X + ":" + x);
		}

		System.out.println(str);
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		String Sa = sc.next();
		String Sb = sc.next();
		String Sc = sc.next();

		int a = 0;
		int b = 0;
		int c = 0;
		int flag = -1;
		String A[] = Sa.split("");
		String B[] = Sb.split("");
		String C[] = Sc.split("");
		String str = "X";

		while(true){
			String X[];
			int x;
			if(flag == -1){
				X = A;
				if(A.length == a){
					str = "A";
				}
				x = a;
				a++;
				//System.out.println("a");
			}else if(flag == 0){
				X = B;
				if(B.length == b){
					str = "B";
				}
				x = b;
				b++;
				//System.out.println("b");
			}else{
				X = C;
				if(C.length == c){
					str = "C";
				}
				x = c;
				c++;
				//System.out.println("c");
			}//ここでlengthと同じになる

			if(!str.equals("X")){
				break;
			}

			if(X[x].equals("a")){
				flag = -1;
			}else if(X[x].equals("b")){
				flag = 0;
			}else{
				flag = 1;
			}

			//System.out.println(X + ":" + x);
		}

		System.out.println(str);
	} main {
		Scanner sc = new Scanner(System.in);

		String Sa = sc.next();
		String Sb = sc.next();
		String Sc = sc.next();

		int a = 0;
		int b = 0;
		int c = 0;
		int flag = -1;
		String A[] = Sa.split("");
		String B[] = Sb.split("");
		String C[] = Sc.split("");
		String str = "X";

		while(true){
			String X[];
			int x;
			if(flag == -1){
				X = A;
				if(A.length == a){
					str = "A";
				}
				x = a;
				a++;
				//System.out.println("a");
			}else if(flag == 0){
				X = B;
				if(B.length == b){
					str = "B";
				}
				x = b;
				b++;
				//System.out.println("b");
			}else{
				X = C;
				if(C.length == c){
					str = "C";
				}
				x = c;
				c++;
				//System.out.println("c");
			}//ここでlengthと同じになる

			if(!str.equals("X")){
				break;
			}

			if(X[x].equals("a")){
				flag = -1;
			}else if(X[x].equals("b")){
				flag = 0;
			}else{
				flag = 1;
			}

			//System.out.println(X + ":" + x);
		}

		System.out.println(str);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String Sa = sc.next(); Sa sc.next() sc.next sc String Sb = sc.next(); Sb sc.next() sc.next sc String Sc = sc.next(); Sc sc.next() sc.next sc int a = 0; a 0 int b = 0; b 0 int c = 0; c 0 int flag = -1; flag -1 1 String A[] = Sa.split(""); A Sa.split("") Sa.split Sa "" String B[] = Sb.split(""); B Sb.split("") Sb.split Sb "" String C[] = Sc.split(""); C Sc.split("") Sc.split Sc "" String str = "X"; str "X" while(true){
			String X[];
			int x;
			if(flag == -1){
				X = A;
				if(A.length == a){
					str = "A";
				}
				x = a;
				a++;
				//System.out.println("a");
			}else if(flag == 0){
				X = B;
				if(B.length == b){
					str = "B";
				}
				x = b;
				b++;
				//System.out.println("b");
			}else{
				X = C;
				if(C.length == c){
					str = "C";
				}
				x = c;
				c++;
				//System.out.println("c");
			}//ここでlengthと同じになる

			if(!str.equals("X")){
				break;
			}

			if(X[x].equals("a")){
				flag = -1;
			}else if(X[x].equals("b")){
				flag = 0;
			}else{
				flag = 1;
			}

			//System.out.println(X + ":" + x);
		} true {
			String X[];
			int x;
			if(flag == -1){
				X = A;
				if(A.length == a){
					str = "A";
				}
				x = a;
				a++;
				//System.out.println("a");
			}else if(flag == 0){
				X = B;
				if(B.length == b){
					str = "B";
				}
				x = b;
				b++;
				//System.out.println("b");
			}else{
				X = C;
				if(C.length == c){
					str = "C";
				}
				x = c;
				c++;
				//System.out.println("c");
			}//ここでlengthと同じになる

			if(!str.equals("X")){
				break;
			}

			if(X[x].equals("a")){
				flag = -1;
			}else if(X[x].equals("b")){
				flag = 0;
			}else{
				flag = 1;
			}

			//System.out.println(X + ":" + x);
		} String X[]; X int x; x if(flag == -1){
				X = A;
				if(A.length == a){
					str = "A";
				}
				x = a;
				a++;
				//System.out.println("a");
			}else if(flag == 0){
				X = B;
				if(B.length == b){
					str = "B";
				}
				x = b;
				b++;
				//System.out.println("b");
			}else{
				X = C;
				if(C.length == c){
					str = "C";
				}
				x = c;
				c++;
				//System.out.println("c");
			}//ここでlengthと同じになる flag == -1 flag -1 1 {
				X = A;
				if(A.length == a){
					str = "A";
				}
				x = a;
				a++;
				//System.out.println("a");
			} X = A X A if(A.length == a){
					str = "A";
				} A.length == a A.length A A.length a {
					str = "A";
				} str = "A" str "A" x = a x a a++ a if(flag == 0){
				X = B;
				if(B.length == b){
					str = "B";
				}
				x = b;
				b++;
				//System.out.println("b");
			}else{
				X = C;
				if(C.length == c){
					str = "C";
				}
				x = c;
				c++;
				//System.out.println("c");
			}//ここでlengthと同じになる flag == 0 flag 0 {
				X = B;
				if(B.length == b){
					str = "B";
				}
				x = b;
				b++;
				//System.out.println("b");
			} X = B X B if(B.length == b){
					str = "B";
				} B.length == b B.length B B.length b {
					str = "B";
				} str = "B" str "B" x = b x b b++ b {
				X = C;
				if(C.length == c){
					str = "C";
				}
				x = c;
				c++;
				//System.out.println("c");
			} X = C X C if(C.length == c){
					str = "C";
				} C.length == c C.length C C.length c {
					str = "C";
				} str = "C" str "C" x = c x c c++ c if(!str.equals("X")){
				break;
			} !str.equals("X") str.equals("X") str.equals str "X" {
				break;
			} break; if(X[x].equals("a")){
				flag = -1;
			}else if(X[x].equals("b")){
				flag = 0;
			}else{
				flag = 1;
			} X[x].equals("a") X[x].equals X[x] X x "a" {
				flag = -1;
			} flag = -1 flag -1 1 if(X[x].equals("b")){
				flag = 0;
			}else{
				flag = 1;
			} X[x].equals("b") X[x].equals X[x] X x "b" {
				flag = 0;
			} flag = 0 flag 0 {
				flag = 1;
			} flag = 1 flag 1 System.out.println(str) System.out.println System.out System System.out str String[] args args public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		String Sa = sc.next();
		String Sb = sc.next();
		String Sc = sc.next();

		int a = 0;
		int b = 0;
		int c = 0;
		int flag = -1;
		String A[] = Sa.split("");
		String B[] = Sb.split("");
		String C[] = Sc.split("");
		String str = "X";

		while(true){
			String X[];
			int x;
			if(flag == -1){
				X = A;
				if(A.length == a){
					str = "A";
				}
				x = a;
				a++;
				//System.out.println("a");
			}else if(flag == 0){
				X = B;
				if(B.length == b){
					str = "B";
				}
				x = b;
				b++;
				//System.out.println("b");
			}else{
				X = C;
				if(C.length == c){
					str = "C";
				}
				x = c;
				c++;
				//System.out.println("c");
			}//ここでlengthと同じになる

			if(!str.equals("X")){
				break;
			}

			if(X[x].equals("a")){
				flag = -1;
			}else if(X[x].equals("b")){
				flag = 0;
			}else{
				flag = 1;
			}

			//System.out.println(X + ":" + x);
		}

		System.out.println(str);
	}
} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		String Sa = sc.next();
		String Sb = sc.next();
		String Sc = sc.next();

		int a = 0;
		int b = 0;
		int c = 0;
		int flag = -1;
		String A[] = Sa.split("");
		String B[] = Sb.split("");
		String C[] = Sc.split("");
		String str = "X";

		while(true){
			String X[];
			int x;
			if(flag == -1){
				X = A;
				if(A.length == a){
					str = "A";
				}
				x = a;
				a++;
				//System.out.println("a");
			}else if(flag == 0){
				X = B;
				if(B.length == b){
					str = "B";
				}
				x = b;
				b++;
				//System.out.println("b");
			}else{
				X = C;
				if(C.length == c){
					str = "C";
				}
				x = c;
				c++;
				//System.out.println("c");
			}//ここでlengthと同じになる

			if(!str.equals("X")){
				break;
			}

			if(X[x].equals("a")){
				flag = -1;
			}else if(X[x].equals("b")){
				flag = 0;
			}else{
				flag = 1;
			}

			//System.out.println(X + ":" + x);
		}

		System.out.println(str);
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		String Sa = sc.next();
		String Sb = sc.next();
		String Sc = sc.next();

		int a = 0;
		int b = 0;
		int c = 0;
		int flag = -1;
		String A[] = Sa.split("");
		String B[] = Sb.split("");
		String C[] = Sc.split("");
		String str = "X";

		while(true){
			String X[];
			int x;
			if(flag == -1){
				X = A;
				if(A.length == a){
					str = "A";
				}
				x = a;
				a++;
				//System.out.println("a");
			}else if(flag == 0){
				X = B;
				if(B.length == b){
					str = "B";
				}
				x = b;
				b++;
				//System.out.println("b");
			}else{
				X = C;
				if(C.length == c){
					str = "C";
				}
				x = c;
				c++;
				//System.out.println("c");
			}//ここでlengthと同じになる

			if(!str.equals("X")){
				break;
			}

			if(X[x].equals("a")){
				flag = -1;
			}else if(X[x].equals("b")){
				flag = 0;
			}else{
				flag = 1;
			}

			//System.out.println(X + ":" + x);
		}

		System.out.println(str);
	}
}